Reputation: 83
Could anyone Please tell what is wrong with below code, I am not able to create nested variable, i.e. in the format $v1/v2. but i believe these format should work.
<xsl:variable name="n" select="100"/>
<xsl:variable name="v1">
<v2>
<xsl:value-of select="$n"></xsl:value-of>
</v2>
</xsl:variable>
<xsl:if test="$v1/v2">
<message:output>
<xsl:value-of select="$v1/v2"/>
</message:output>
</xsl:if>
Upvotes: 1
Views: 752
Reputation: 83
I am a bit confused here, when I checked the version using <xsl:value-of select="system-property('xsl:version')" />
it gave me 2 as output.
But in my stylesheet tag it was mentioned as 1.0, so below code was not working in that.
when i changed the version to 2.0: <xsl:stylesheet version="2.0"
the same code started working.
<xsl:template match="/">
<message:ExecuteSubProcessResponse>
<xsl:variable name="n" select="100"/>
<xsl:variable name="v1">
<v2>
<xsl:value-of select="$n"></xsl:value-of>
</v2>
</xsl:variable>
<xsl:choose>
<xsl:when test="count($v1/v2)> 0">
<message:BIMStatus>
<xsl:text disable-output-escaping="no">ELIGIBLE</xsl:text>
</message:BIMStatus>
</xsl:when>
<xsl:otherwise>
<message:BIMStatus>
<xsl:value-of select="$v1/v2"/>
</message:BIMStatus>
</xsl:otherwise>
</xsl:choose>
</message:ExecuteSubProcessResponse>
</xsl:template>
Upvotes: 0
Reputation: 163352
In XSLT 2.0 your code looks fine; in XSLT 1.0 it would fail saying that in a path expression such as $v1/v2
, the value of $v1 must be a node-set rather than a result-tree-fragment. Most XSLT 1.0 processors allow you to get around this restriction by using xx:node-set($v1)/v2
where xx is bound to some suiutable namespace.
The version of XSLT depends on what XSLT processor you are using. There are one or two processors that run XSLT 1.0 or 2.0 depending on what you ask for in the xsl:stylesheet version attribute, but a processor written in the XSLT 1.0 days doesn't know how to process XSLT 2.0, and most XSLT 2.0 processors if they see version="1.0" in the stylesheet will run XSLT 2.0 in "backwards compatibility mode", which doesn't impose all the restrictions of XSLT 1.0 (like the result-tree-fragment restriction), it merely makes some constructs behave the 1.0 way (for example, xsl:value-of will only output the first node in a node sequence).
It would be much easier to help you if you told us what your code output.
Upvotes: 2