Hello all,
I am having an issue trying to set a conditional variable (which I know is tricky anyway in XSLT) to a path.
I am declaring the variable name first, and then within the xsl:variable tags I have the xsl:choose that checks a condition and outputs one of two possible paths - the aim being that I can then use the variable as a 'root' for all other paths in the stylesheet.
Below is the code for the variable:
Code:
<xsl:variable name="Root">
<xsl:choose>
<xsl:when test="somepath/sometag = 'abcd'">
rootone/roottwo[@desc='firsttype']
</xsl:when>
<xsl:otherwise>
rootone/roottwo[@desc='othertype']
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
I have tried doing this with <xsl:text> tags around the paths, <xsl:value-of> and <xsl:copy-of> tags, but no joy.
With these I get the error:
org.apache.xpath.objects.XRTreeFrag cannot be cast to org.apache.xpath.objects.XNodeSet
if I try to use the variable within an XPath expression, for example:
$Root/name/surname/.
If the variable isn't conditional, e.g.:
Code:
<xsl:variable name="Root" select="rootone/roottwo[@desc='firsttype']" />
then it works fine.
I understand that a conditional variable will set the variable value to a RTF (result tree fragment) rather than a node-set, which is what I need to be able to use it within another path.
I had thought converting it to text would work as it would add it to the additional path and read it as a path.
Please could someone advise how else I can use this conditional variable?
I am using xslt 1.0, but couldn't see any node-set functions even in xslt 2.0.
Thanks in advance,