I want to change the specifics Tags in following XML. The tags <linkSource>
should be convert to <fo:basic-link internal-destination="boothId">
and the tag <linkDestination>
should be convertet to <fo:block id="boothId">
.
<root>
<directCompNotes>
<paragraph>Go to:</paragraph>
<bullet-list>
<item>
<paragraph>
<linkSource>
Booth
</linkSource>
</paragraph>
</item>
<item>
<paragraph>
WithoutLinkSource
</paragraph>
</item>
</bullet-list>
</directCompNotes>
<directComp>
<paragraph>
<linkDestination>
Explainition
</linkDestination>
</paragraph>
</directComp>
</root>
That is what I tried to do:
<xsl:template match="root">
<xsl:for-each select="directCompNotes/bullet-list/item/paragraph/linkSource">
<fo:basic-link internal-destination="boothId">
<xsl:value-of select="."/>
</fo:basic-link>
</xsl:for-each>
</xsl:template>
The goal is that I should be able to create a link from "Booth" to "Explanition". All of the linkSource and linkDestinition are in the XML file already defined.
Can anyone help me please?
(Sorry, My English is not very well, but I hope I was able to explain the question well).
CodePudding user response:
Please try the following XSLT.
Input XML
<?xml version="1.0"?>
<root>
<directCompNotes>
<paragraph>Go to:</paragraph>
<bullet-list>
<item>
<paragraph>
<linkSource>Booth</linkSource>
</paragraph>
</item>
<item>
<paragraph>WithoutLinkSource</paragraph>
</item>
</bullet-list>
</directCompNotes>
<directComp>
<paragraph>
<linkDestination>Explainition</linkDestination>
</paragraph>
</directComp>
</root>
XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:apply-templates/>
</fo:root>
</xsl:template>
<xsl:template match="linkSource">
<fo:basic-link internal-destination="boothId">
<xsl:value-of select="."/>
</fo:basic-link>
</xsl:template>
<xsl:template match="linkDestination">
<fo:block id="boothId">
<xsl:value-of select="."/>
</fo:block>
</xsl:template>
</xsl:stylesheet>
Output XML
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<directCompNotes>
<paragraph>Go to:</paragraph>
<bullet-list>
<item>
<paragraph>
<fo:basic-link internal-destination="boothId">Booth</fo:basic-link>
</paragraph>
</item>
<item>
<paragraph>WithoutLinkSource</paragraph>
</item>
</bullet-list>
</directCompNotes>
<directComp>
<paragraph>
<fo:block id="boothId">Explainition</fo:block>
</paragraph>
</directComp>
</fo:root>