|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] ;) Was: Re: Accessing the element stack generically
I'm happy. XSL is slick.
Problem:
~~~~~~~
For particular nodes visited, I'd like to print
out their location.
Example:
~~~~~~~
With a given document:
<a><b x="y"><c/></b><b x="z" p="q"><c/></b></a>
Produce output:
<c-node location="/a/b[@x='y']/c" />
<c-node location="/a/b[@x='z'][@p='q']/c" />
Solution:
~~~~~~~~
<xsl:template match="c">
<xsl:element name="c-node" >
<xsl:attribute name="location">
<xsl:for-each select="ancestor-or-self::*">
<xsl:value-of select="concat('/',name())"/>
<xsl:for-each select="attribute::*">
<xsl:text>[@</xsl:text><xsl:value-of select="name()" />
<xsl:text>='</xsl:text><xsl:value-of select="." />
<xsl:text>']</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:attribute>
</xsl:element>
</xsl:template>
The default sort order is "document order", thus there
is no problem with portability.
Right?
Clark
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








