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

Re: RE: Postional predicates de-mystified

Subject: Re: RE: Postional predicates de-mystified
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 4 Jan 2002 12:36:57 +0000
Re:  RE: Postional predicates de-mystified
Dave Pawson wrote:
> <xsl:value-of select=" for $i in 1 to count(ancestor::*)
>    return name((ancestor::*)[$i])" separator = "/"/> 
> Provides the 'path' to the current node! Pretty neat.
> (or should I be saying a document order sequence?)

I think Dave was trying out the numeric predicates, but more neatly,
you could just use:

  <xsl:value-of select="for $e in ancestor::* return name($e)"
                separator="/" />

There's no need for the range variable (i.e. $e in the above case) in
the for expression to be an integer; indeed, with experience from
xsl:for-each, it's probably more approachable to imagine the range
variable as the 'context node'.

I can see the for expression leading to this 'error' fairly commonly
(OK, it produces the correct results, but it does so in a fairly
roundabout way, with a lot more node visits than are necessary),
because it's more in tune with how for expressions work in other
programming language (where the range variable is commonly an

Which another reason for dropping the range variable:

  <xsl:value-of select="for (ancestor::*) return name()"
                separator="/" />

Or, as I've argued, using an operator syntax for the for expression

  <xsl:value-of select="ancestor::* -> name()"
                separator="/" />

[The separator attribute on xsl:value-of is one of the unexpected
delights of XSLT 2.0 :)]



Jeni Tennison

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


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.
First Name
Last Name
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.