<xsl:variable name="mydata"> <foo>1</foo> <bar>2</bar> </xsl:variable> <xsl:value-of select="exslt:node-set($mydata)/foo" /> <xsl:value-of select="$mydata/foo" />
If the contents of the variable are statically defined, then it is possible to access it from an XPath expression without using the xxx:node-set() extension function.
An example :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:variable name="mydata"> <foo>1</foo> <bar>2</bar> </xsl:variable> <xsl:template match="/"> <xsl:value-of select= "document('')/*/xsl:variable[@name='mydata']/bar"/> </xsl:template> </xsl:stylesheet>
when this conversion is applied to any XML document (not used), the desired, correct result is obtained :
2
source share