[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Nesting XPath predicates

Subject: Re: Nesting XPath predicates
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Thu, 24 Apr 2008 09:17:05 +0100
Re:  Nesting XPath predicates
On 24/04/2008, Liam Quin <liam@xxxxxx> wrote:
> Easier might be
>    <xsl:template match="dataset">
>      <xsl:variable name="sn" select="serviceName" />
>      <xsl:value-of select="//service/[@name = $sn]/@base" />
>    </xsl:template>

It is easier to use a variable when you're learning, but this is what
the current() function is for:

//service[@name = current()/serviceName]

(I've also dropped the odd / after service)

The current() function changes the context node to what is was outside
of the XPath, so the <dataset> element in this case.

Ultimately though, you should use a key here:

<xsl:key name="service-by-name" match="service" use="@name"/>

with

key('service-by-name', serviceName)


cheers
-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.