xsl-list
[Top] [All Lists]

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

2012-12-01 09:42:59
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:

http://stackoverflow.com/questions/4746299/generate-get-xpath-from-xml-node-java

Cheers,
Dimitre

On Sat, Dec 1, 2012 at 5:48 AM, Graydon <graydon(_at_)marost(_dot_)ca> 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




-- 
Cheers,
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.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--