[Home] [By Thread] [By Date] [Recent Entries]
Alan Williamson wrote:
Morning one and all.
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:output method="xml" indent="yes" /> <xsl:template match="@*|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates
select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template> <xsl:template match="*">
<xsl:element name="{name()}">
<xsl:attribute name="depth" >
<xsl:value-of select="count(ancestor-or-self::*)" />
</xsl:attribute>
<xsl:apply-templates
select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:element>
</xsl:template></xsl:stylesheet> you should get a copy of xml with a depth attribute node...the operative term here doing the heavy lifting is the select statement count(ancestor-or-self::*) which if u change it to recognize li should get you the dashcount you want; as in count(ancestor-or-self::li) should give you the right count....
<xsl:template match="@*|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates
select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template> <xsl:template match="*">
<xsl:element name="{name()}">
<xsl:attribute name="dashes" >
<xsl:value-of select="count(ancestor-or-self::li)" />
</xsl:attribute>
<xsl:apply-templates
select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:element>
</xsl:template></xsl:stylesheet> this results in (using your xml); <?xml version="1.0" encoding="utf-8"?>
<ul depth="0">
<li dashes="1">Element1</li>
<li dashes="1">Element2
<ul dashes="1">
<li dashes="2">Element2.1
<ul dashes="2">
<li dashes="3">Element2.1.1</li>
</ul>
</li>
</ul>
</li>
<li dashes="1">Element 3</li>
</ul>sine you are just interested in the dashes attribute on li attributes you can ignore everything else now, with your 2nd stage transformation just applying the dashes using whatever method. is a good introduction to printing out things x number of times...look at the hypen example... http://www.xml.com/pub/a/2001/08/01/gettingloopy.html?page=2 good luck, Jim Fuller
|

Cart



