RE: [xsl] combining two variables to generate XPATH

Subject: RE: [xsl] combining two variables to generate XPATH
From: "Robert Koberg" <rob@xxxxxxxxxx>
Date: Tue, 17 Dec 2002 14:54:59 -0800
Hi bix,

I think everyone is getting caught up in your explicit question :) and not
understanding what you want, or perhaps I am missing something...

Based on previous examples:
concat($node,'/',$type,'/item') -- assuming $type is the name of an element
select="'someBranch'" -- assuming 'someBranch' is the name of an element

this is very simple to solve in XSLT 1.0, as I posted earlier:

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

best,
-Rob


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Michael Kay
> Sent: Tuesday, December 17, 2002 1:55 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] combining two variables to generate XPATH
>
>
> > 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>
> >
> > 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>
> >
>
> The first step in a path expression can be any expression that returns a
> node-set. The value of $node is a node-set. In XPath 2.0, subsequent
> steps can also be expressions that return a node-set. But they can't be
> expressions that return strings: the value of $branch is not a node-set,
> it is a string.
>
> XPath variables represent values, they aren't macros that represent
> parts of an expression.
>
> Michael Kay
> Software AG
> home: Michael.H.Kay@xxxxxxxxxxxx
> work: Michael.Kay@xxxxxxxxxxxxxx
> >
> >
> > >From: Mark Wilgus <mwilgus@xxxxxxxxx>
> > >
> > >I believe this is not possible.  XSLT doesn't allow you
> > >to use a variable for an XPath expression.  See number 2 at the
> > >following list:
> > >
> > >http://www.dpawson.co.uk/xsl/sect2/nono.html
> > >
> > > > -----Original Message-----
> > > > From: bix xslt [mailto:bix_xslt@xxxxxxxxxxx]
> >
> > > > >        <xsl:variable name="branch"
> > > > >select="concat($node,'/',$type,'/item')" />
> > > > >        <xsl:value-of select="$branch" />
> > > > ><!--        <xsl:for-each select="$branch">
> > > >
> >
> >
> >
> > _________________________________________________________________
> > Protect your PC - get McAfee.com VirusScan Online
> > http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
> >
> >
> >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> >
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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


Current Thread