[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] better way to get the path to a node?

Subject: Re: [xsl] better way to get the path to a node?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sat, 1 Dec 2012 07:42:27 -0800

I have used this pure XSLT 1.0 code ,since 2003, for building an XPath
expression to any kind of node: not only to an element but to a text
node, to a processing instruction, to a comment, to an attribute and
even to a namespace node:



On Sat, Dec 1, 2012 at 5:48 AM, Graydon <graydon@xxxxxxxxx> wrote:
> On Sat, Dec 01, 2012 at 11:28:28AM +0100, Martin Honnen scripsit:
>> Graydon wrote:
>> >If I want to return the XPath path to a specific node when that node is
>> >the context node, is there a better way than:
>> >
>> ><xsl:sequence
>> >select="string-join(ancestor-or-self::*/concat('/',name(),'[',for $x in . return count(preceding-sibling::*[name() eq $x/name()])+1,']'),'')"/>
>> >
>> >"Better" here means "more efficient"; I'll be using various Saxon 9.*
>> >for this, either in oXygen or from java.
>> With Saxon there is
>> http://www.saxonica.com/documentation/extensions/functions/path.xml.
>> I haven't checked exactly however for which versions of Saxon 9.* it
>> is available.
> Thank you!
> I haven't, either, but can burn that bridge on Monday. (and check that
> saxon:path() really is faster for the data-set in question than the
> above.  I'll be really surprised if it's not.)
> -- Graydon

Dimitre Novatchev
Truly great madness cannot be achieved without significant intelligence.
To invent, you need a good imagination and a pile of junk
Never fight an inanimate object
To avoid situations in which you might make mistakes may be the
biggest mistake of all
Quality means doing it right when no one is looking.
You've achieved success in your field when you don't know whether what
you're doing is work or play
Facts do not cease to exist because they are ignored.
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
I finally figured out the only reason to be alive is to enjoy it.

Current Thread