Re: XSLT function "path()" required

> I have been working with XSLT files quite a lot and I think that a function
> that could give the absolute path of the current node would be very useful
> in cases where you have no idea about the structure of the XML file you are
> processing.
> The result returned by the "path()" function would look something like this:
> "/book/chapter[2]/paragraph[5]/title"

Perhaps you want

string-join(for $n in ancestor-or-self::* return ('/', name($n), '[', 
string(count($n/preceding-sibling::*[name()=name($n)])+1), ']'), '')

(this is an extension of the [fixed] string-joing example in the 
Functions and Operators specification)

Note also the fn:node-kind function in case you want to know the type
of the current node.

Cheers,
Oliver
(Not a member of the WG, so actually I shouldn't have responded ... ;-)


/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@informatik.hu-berlin.de             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/

Received on Friday, 26 September 2003 04:49:17 UTC