Re: [xsl] Nesting XPath predicates

Subject: Re: [xsl] Nesting XPath predicates
From: Liam Quin <liam@xxxxxx>
Date: Wed, 23 Apr 2008 21:42:14 -0400
On Wed, Apr 23, 2008 at 04:43:01PM -0700, Nathan Potter wrote:
>     <xsl:template match="dataset">
>         <xsl:value-of select="//service/[@name='{serviceName}']/ 
> @base" />
>     </xsl:template-match>

Easier might be
   <xsl:template match="dataset">
     <xsl:variable name="sn" select="serviceName" />
     <xsl:value-of select="//service/[@name = $sn]/@base" />
   </xsl:template>

'{serviceName}' is looking for the literal constant string
{serviceName}.

And if you use @name = serviceName, your problem is that serviceName is
evaluated in the context of //service, and not the dataset of the
template.  I prefer to use a variable rather than trying to keep
track of contexts and foci, but maybe that's just me :-)  But it
makes the style sheet less fragile in the face of edits, e.g. if you
add an xsl;for-each around something.

Liam

-- 
Liam Quin, W3C XML Activity Lead, http://www.w3.org/People/Quin/
http://www.holoweb.net/~liam/ * http://www.fromoldbooks.org/

Current Thread