Can I use an XML fragment in an XSLT 2 variable?
Posted on 2011-03-08
I am an experienced programmer, using XSLT for the first time.
I find the documentation of XSLT variables quite stupefying!
I want to extract a fragment of an external xml file, using the document()
function and xpath, store that fragment somewhere (in an XSLT variable?),
then in subsquequent template statements select child nodes from that fragment.
Is something like this possible:?
<!-- extract the mynode fragment from other.xml into variable frag -->
<xsl:variable name="frag" select="document('other.xml')/long/xmlpath/expression/mynode" />
<!-- Now extract a child of mynode -->
<xsl:value-of select="$frag/childofmynode" />
(I have successfully used the document function with xpath.)