Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] generate xpath expression in web links

From: "Michael Kay" <mike@------------>
To:
Date: 9/1/2006 9:11:00 AM
> 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>
> 

Firstly, you mean "a" path expression, not "the" path expression. There are
many path expressions that uniquely identify a node.

Your particular version doesn't tackle namespaces, which is the biggest
problem in creating such an expression. If all you are concerned about is to
get back to the original element, an expression such as

/*/*[3]/*[5]/*[2]

removes this problem.

You could use <xsl:number/> rather than counting preceding siblings.

Michael Kay
http://www.saxonica.com/



> 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(cur
> rent())])+
> 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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent