Exslt automation: node-set?

Not sure if this is possible, but trying to configure something that doesn't force me to type exslt: node -set when pulling values ​​from a dynamically created node block. I save the entire set of nodes in a variable and wrap it in exslt: node -set, but why does this not work when I try to extract from it. Is it possible?

<xsl:variable name="LANG"> <xsl:variable name="tmp"> <xsl:element name="foo"> <xsl:element name="bar">Hello</xsl:element> </xsl:element> </xsl:variable> <xsl:value-of select="exslt:node-set($tmp)"/> </xsl:variable> <!-- Love to be able to do this --> <xsl:value-of select="$LANG/foo/bar"/> <!-- This does work --> <xsl:value-of select="exslt:node-set($LANG)/foo/bar"/> 
+2
source share
1 answer

In XSLT 1.0, a variable defined as in your example is called a result tree fragment (RTF), and you can use xsl:copy-of to copy the entire fragment to the resulting tree or xsl:value-of to copy the entire contents. Example

  <xsl:copy-of select="$LANG"/> 

If you want to treat the variable as a temporary tree, you will need the extension node-set() .

A common way to handle static tree fragments (for example, lookup tables) in XSLT 1.0 is to define them as children of the root elements of the stylesheet (using a custom namespace). Then you can use the document() function to get the required value.

Note If you use Saxon (v> 6.5), you can simply install the stylesheet version 1.1 and you can manage RTF without any node -set extension.


[XSLT 1.0]

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:empo="http://stackoverflow.com/users/253811/empo"> <empo:LANG> <empo:foo> <empo:bar>Hello</empo:bar> </empo:foo> </empo:LANG> <xsl:template match="/"> <xsl:variable name="LANG" select="document('')/*/empo:LANG"/> <xsl:value-of select="$LANG/empo:foo/empo:bar"/> </xsl:template> </xsl:stylesheet> 
+2
source

All Articles