Subject: Re: [xsl] RE: Postional predicates de-mystified From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 4 Jan 2002 12:36:57 +0000 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] RE: Postional predicates , David Carlisle | Thread | RE: [xsl] RE: Postional predicates , DPawson |
Re: [xsl] RE: Postional predicates , David Carlisle | Date | Re: [xsl] RE: Postional predicates , Jeni Tennison |
Month |