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

Subject: [xsl] better way to get the path to a node?
From: Graydon <graydon@xxxxxxxxx>
Date: Fri, 30 Nov 2012 21:52:15 -0500
Greetings --

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.

I keep thinking there's a way to do this without the combination of
count() and preceding-sibling, but what it might be eludes me.

Thanks!
Graydon

Current Thread