xsl-list
[Top] [All Lists]

Re: combining two variables to generate XPATH

2002-12-17 15:10:23
Jeff Kenton wrote:
bix xslt wrote:

What is different about a path with a single variable, and a path with two variables? Why can't I specify a second variable:

<xsl:template name="foo">
 <xsl:param name="node"/>
 <xsl:param name="branch" select="'someBranch'"/>
 <xsl:for-each select="$node/$branch/leaf">
   <xsl:value-of select="@id" />
 </xsl:for-each>
</xsl:template>


This is not legal. The only place a variable reference can appear in a Path Expression is at the beginning. $node is OK here, but $branch is not.


Minor follow-up, for XPath language lawyers who care:

In XPath 2.0, $node/$branch/leaf is legal, though deserving of at least a warning (again, assuming $node and $branch represent nodesets). What it does is effectively ignore $node and return the leaf children of $branch.

Thanks to Michael Kay for pointing this out in a previous message.

--
--------------------------
Jeff Kenton
DataPower Technology, Inc.



XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list