joeriks
joeriks

Reputation: 3462

How to set XSLT variable to contain exact xml data

I wonder how to store xml data from one variable in another.

This works ($oldvariable contains xml data):

<xsl:variable name="newvariable" select="$oldvariable"/>

But this does not work (probably because of some obvious reason for an experienced XSLT-coder):

<xsl:variable name="newvariable">
 <xsl:copy-of select="$oldvariable"/>
</xsl:variable>

How can I make the latter store the exact variable data?

I need that construct since I'm really using a :

<xsl:variable name="newvariable">
<xsl:choose>
 <xsl:when test="some-test">
  <xsl:copy-of select="$oldvariable"/>
...

Thanks alot!

Upvotes: 0

Views: 923

Answers (1)

user357812
user357812

Reputation:

This is FAQ: In XSLT 1.0, whenever you declare a variable/parameter with content template (without @select), the result type is Result Tree Fragment.

Then, you can't use RTF as left hand for / step operator.

So, how do you declare a variable to be one of two node-sets based on a condition?

<xsl:variable name="newvariable" select="$oldvariable[$condition]|
                                         $othernodeset[not($condition)]"/> 

Upvotes: 3

Related Questions