I'm converting xml to xsl-fo... In the below XML How to get the value of same xml element <cd>
.
XML
<?xml version="1.0" encoding="UTF-8"?>
<header>
<child-A>
<element>
<cd>100</cd>
<cd>message</cd>
<example>text</example>
</element>
</child-A>
<child-B>
<element>
<cd>10</cd>
<cd>test</cd>
<example>textB</example>
<cd>testvalue</cd>
</element>
<child-/B>
</header>
In this Xml I want to get the value of all <cd>
xml elements in child-A/element/(both cd elements value).
XSLT 1.0
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" indent="yes" />
<xsl:template match="/header">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="child-A/element">
<fo:block>
<xsl:value-of select="cd">
</fo:block>
</xsl:template>
</xsl:stylesheet>
Here I'm getting the first value of element but not the second..
Output I get
<fo:block>100<fo:block>
Output I want
<fo:block>100
message</fo:block>
CodePudding user response:
In XSLT 2 (or 3) with an XSLT 2 (or 3) processor you can use <xsl:value-of select="cd"/>
to get the string concatenation of all cd
elements. With XSLT 1 and an XSLT 1 processor push the cd
elements to another template e.g. <xsl:apply-templates select="cd"/>
or process them with xsl:for-each select="cd"
with an xsl:value-of select="."
inside.