[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

generate xpath expression in web links

Subject: generate xpath expression in web links
From: "David Murphy" <david@xxxxxxxxxxxxxx>
Date: Fri, 1 Sep 2006 00:12:39 +0100
generate xpath expression java
Hello

Our web app needs to generate the XPath expression that uniquely
identifies a particular node, something like:

<a href="/project[1]/admin[3]/project-manager[5]/full-name[2]">Some
Name</a>

This is what I've come up with so far.

===========================

<a><xsl:call-template name="generatePath"/><xsl:value-of
select="some-link"/></a>

<xsl:template name="generatePath">
	<xsl:attribute name="href">
		<xsl:for-each select="ancestor-or-self::*">
			<xsl:text>/</xsl:text>
			<xsl:value-of select="local-name(.)"/>
			<xsl:text>[</xsl:text>
			<xsl:value-of
select="count(preceding-sibling::*[local-name()=local-name(current())])+
1"/>
			<xsl:text>]</xsl:text>
		</xsl:for-each>
	</xsl:attribute>
</xsl:template>

===========================

It works ok, but I just wanted to check to see if I was missing anything
to make it more efficient. I'm using xslt2.

Thanks, David

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.