|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
integer).
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
instead:
<xsl:value-of select="ancestor::* -> name()"
separator="/" />
[The separator attribute on xsl:value-of is one of the unexpected
delights of XSLT 2.0 :)]
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|

Cart








