|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Function from-ancestors and parent element name.
At 99/09/08 11:41 -0400, Stephane St-Denis wrote:
Using the XSLT-19990813 Working Draft, you would use predicates in the fashion shown in the example below. Note that I am not using variables where I could, but I'm hoping the way I've coded it illustrates what you need. I'm asking for a count of all ancestor elements whose name is equal to the name of the parent of the current element ... which is what I think you are asking for. I hope this helps. ........ Ken T:\ftemp>type test.xml
<?xml version="1.0"?>
<test>
<test attr="a">
<test attr="b">
<other attr="c">
<test attr="d">
<test attr="e">
<other attr="f">
<test attr="g">
<test attr="h"/>
</test>
</other>
</test>
</test>
</other>
</test>
</test>
</test>T:\ftemp>type test.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"> <xsl:output method="xml"/> <xsl:template match="text()"/> <xsl:template match="/*"> <!--don't report document element--> <xsl:apply-templates/> </xsl:template> <xsl:template match="*"> <xsl:text>Element </xsl:text> <xsl:value-of select="@attr"/> <xsl:text> has parent </xsl:text> <xsl:value-of select="name(..)"/> <xsl:text>, being number </xsl:text> <xsl:value-of select="count(ancestor::*[name(.)=name(current()/..)])"/> <xsl:text>.
</xsl:text> <xsl:apply-templates/> </xsl:template> </xsl:stylesheet> T:\ftemp>call xsl test.xml test.xsl test.txt T:\ftemp>type test.txt Element a has parent test, being number 1. Element b has parent test, being number 2. Element c has parent test, being number 3. Element d has parent other, being number 1. Element e has parent test, being number 4. Element f has parent test, being number 5. Element g has parent other, being number 2. Element h has parent test, being number 6. T:\ftemp>
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








