This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]