xsl-list
[Top] [All Lists]

Re: [xsl] Nesting XPath predicates

2008-04-23 18:42:51
On Wed, Apr 23, 2008 at 04:43:01PM -0700, Nathan Potter wrote:
    <xsl:template match="dataset">
        <xsl:value-of select="//service/[(_at_)name='{serviceName}']/ 
@base" />
    </xsl:template-match>

Easier might be
   <xsl:template match="dataset">
     <xsl:variable name="sn" select="serviceName" />
     <xsl:value-of select="//service/[(_at_)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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>