xsl-list
[Top] [All Lists]

Re: combining two variables to generate XPATH

2002-12-17 13:58:21
bix xslt wrote:
Is that FAQ outdated??  I know that the following code works just fine:

<xsl:template match="proc">
 <xsl:call-template name="foo">
   <xsl:with-param name="node" select="." />
 </xsl:call-template>
</xsl:template>

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

This is legal, as long as $node represents a nodeset (which it does here).


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.

Various previous messages suggest using evaluate() or name tests to solve your problem. They should work.



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



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