Zyga
Zyga

Reputation: 2427

Insert NodeList into XSLT output

I am passing NodeList as a parameter to XSLT (Im using SaxonB 9.1/XSLT 2 if that makes any difference).

What I want to do is to insert all of the elements/values from the nodelist into the XSLT output (which is XML file).

When I do below, it only prints the text values of the nodes (ie. it doesnt generate XML elements at all)

<xsl:param name="NL" />
.    <xsl:template match="/">
.          <xsl:value-of select="$NL" />
.     </xsl:template>
<xsl:stylesheet>

I can access particular elements using XPath, ie. $NL/Node1. What do I need to do in order to include all of the NodeList's XML elements and values with the output?

I also tried to do loop like below, but it only prints "top-level" elements of the NOdeList - it doesnt include any children nodes of those elements.

<xsl:for-each select="$NL/*">
.   <xsl:element name="{./name()}">
.       <xsl:value-of select="./text()"/>
.   </xsl:element>
</xsl:for-each>

Upvotes: 1

Views: 552

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122394

<xsl:value-of> gives you the string value, you probably want to use <xsl:copy-of> instead.

Upvotes: 3

Related Questions