Jump to content

Recommended Posts

Posted

Very simple example... but don't understand why.

 <xsl:variable name="i" select="1" />      <xsl:variable name="a" select="35" />      <xsl:variable name="b" select="'fn'" />      <xsl:variable name="c">        <xsl:if test="$i < $a">          <xsl:value-of select="$b" />        </xsl:if>        <xsl:if test="$i = $a">'test'</xsl:if></xsl:variable>

At the end, value is a node instead of just the text 'fn'.

If I use

xsl:variable name="c" select="$b" />

Then the value is correct (just 'fn').

 

Any help?

Posted

I found the answer. Variables created that way (not using select) are considered Reference Tree Fragment (http://msdn.microsoft.com/en-us/library/4wwc9138.aspx).

It's still possible to use the variable content the normal way, although the object will be a RTF.

Now, If you have a list of nodes, you have to transform the variable to a NodeSet and then call the nodes() function like

msxsl:node-set($myvariable)/node()

Then it will be just like creating a variable with the select argument.

Posted

It is called a "result tree fragment". Also note that XSLT 2.0 exists since 2007 and that there you can have temporary trees instead of result tree fragments. Furthermore XSLT 2.0 has an "if (condition) then expression1 else expression2" expression.

So with an XSLT 2.0 processor like Saxon 9 you can avoid such problems.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...