xsl-list
[Top] [All Lists]

Re: [xsl] Nesting XPath predicates

2008-04-24 12:41:35


Liam and Andrew,

Thank you for your thoughtfull replies!

I'll be trying to understand keys this afternoon.


Nathan




On Apr 24, 2008, at 10:35 AM, Liam Quin wrote:

On Thu, Apr 24, 2008 at 09:17:05AM +0100, Andrew Welch wrote:
On 24/04/2008, Liam Quin <liam(_at_)w3(_dot_)org> wrote:
Easier might be
   <xsl:template match="dataset">
     <xsl:variable name="sn" select="serviceName" />
     <xsl:value-of select="//service/[(_at_)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[(_at_)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/

--~------------------------------------------------------------------
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>
--~--


============================================================
Nathan Potter                 Oregon State University, COAS
ndp at coas.oregonstate.edu   104 Ocean. Admin. Bldg.
541 737 2293 voice            Corvallis, OR   97331-5503
541 737 2064 fax



--~------------------------------------------------------------------
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>