MatthewNicoll
asked on
Can I use an XML fragment in an XSLT 2 variable?
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:?
<xsl:template match="something">
<!-- extract the mynode fragment from other.xml into variable frag -->
<xsl:variable name="frag" select="document('other.xm l')/long/x mlpath/exp ression/my node" />
<!-- Now extract a child of mynode -->
<xsl:value-of select="$frag/childofmynod e" />
</xsl:template>
(I have successfully used the document function with xpath.)
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:?
<xsl:template match="something">
<!-- extract the mynode fragment from other.xml into variable frag -->
<xsl:variable name="frag" select="document('other.xm
<!-- Now extract a child of mynode -->
<xsl:value-of select="$frag/childofmynod
</xsl:template>
(I have successfully used the document function with xpath.)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Gertone, that gives me the courage to keep experimenting.
welcome
Simply copying a fragment in a variable and doing some XPath on it works in both XSLT1 and XSLT2 (and that is what you do)
Reconstructing a tree in a variable and doing XPath on it, only works in XSLT2, not in XSLT1