DigitalZebra
DigitalZebra

Reputation: 41533

Store a group of nodes as a variable in XSLT?

So here is my current code:

<xsl:variable name="address">
    <xsl:value-of select="concat(/node1/node2/address.node/street, /node1/node2/address.node/city, /node1/node2/address.node/zip)" />
</xsl:variable>

Now, I'm trying to shorten this down to:

<xsl:variable name="addressNode">
    <xsl:value-of select="/node1/node2/address.node" />
</xsl:variable>

<xsl:variable name="address">
    <xsl:value-of select="concat($addressNode/street, $addressNode/city, $addressNode/zip)" />
</xsl:variable>

However this is not working at all as expected... could anyone point me in the right direction? I tried using copy-to instead of value-of for addressNode, but it still isn't working :(

Upvotes: 0

Views: 1396

Answers (1)

J&#246;rn Horstmann
J&#246;rn Horstmann

Reputation: 34024

When you use xsl:value-of inside xsl:variable you get a variable of type string, not a node. You should use use the select attribute of xsl:variable:

<xsl:variable name="addressNode" select="/node1/node2/address.node" />

Upvotes: 4

Related Questions