Development and Programming
xsl:param and xsl:with-param
For both the parameter and variable elements, if a value is assigned by the XPath expression, then one of the four basic XPath types will be returned: Boolean, string, number, or node set. When the value is given by using a non-empty template body, then a non-XPath data type is returned, and that will be a result tree fragment. XSLT adds one such type: result tree fragment. Thus,
both create RTFs, while
<xsl:variable name="c" select="1"/>
<xsl:variable name="d" select="'hello world'"/>
do not. ($c is a number, $d a string, $e an empty string)
The code above creates a result tree fragment and binds it to the variable myRtf, so XPath expressions can now refer to $myRtf when they want to use the
fragment. The fragment consists of 1 root node. That node has 2 'elem' element nodes as children, and one of those has a 'hello' text node as its child.
XSLT 1.0 imposes a fundamental limitation on result tree fragments: they can only be used in XPath expressions where strings can be used. Thus you can't
say $myRtf/elem/text() to identify the 'hello' text node in the example above. You can say <xsl:copy-of select="$myRtf"/>, though. And
<xsl:value-of select="$myRtf"/> will work as you would expect it to. This will also work as it should, but not how you would expect:
<xsl:if test="$myRtf">... if you think of boolean($someNodeSet) youll see that it returns true when there is a node in the node-set; well, a
result tree fragment always has 1 node, so it's always true.
XSLT 2.0 eliminated result tree fragments, just saying that xsl:variable and xsl:param create node-sets.
© 2019 Digcode.com. All rights reserved.