[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Nesting XPath predicates
On Thu, Apr 24, 2008 at 09:17:05AM +0100, Andrew Welch wrote: > 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: Good point. > //service[@name = current()/serviceName] That will work in the given example, but stops working if you put that line inside a for-each... or more precisely works differently :-) so it's fragile, and not a technique that people can build on well. > Ultimately though, you should use a key here: > <xsl:key name="service-by-name" match="service" use="@name"/> [...] > key('service-by-name', serviceName) That's probably a better solution. Best, Liam -- Liam Quin, W3C XML Activity Lead, http://www.w3.org/People/Quin/ http://www.holoweb.net/~liam/ * http://www.fromoldbooks.org/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|