RE: [xsl] combining two variables to generate XPATH

Subject: RE: [xsl] combining two variables to generate XPATH
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 18 Dec 2002 10:07:28 -0000
> >> <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.

It's legal if the value of $branch is a sequence consisting entirely of
nodes. In the example given, the value of $branch is a string, so this
will give a type error.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 


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


Current Thread