|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Counting the nesting level of an element
Hi,
Xavier Cazin <cazinx@xxxxxxxxx> writes:
> I can't seem to be able to resolve this problem by myself: I'd just like to
> count the nesting level of <sect> in my document, in order to affect the
> result to HTML heading levels, so that I get h1, h2, etc...
>
> <xsl:template match="sect">
> <xsl:variable name="sect_nesting">
> <xsl:number level="any" count="?" format="1"/>
> </xsl:variable>
> <xsl:element name="h{$sect_nesting}">
> <xsl:apply-templates select="title/text()"/>
> </xsl:element>
> <xsl:apply-templates select="*[position() > 1]"/>
> </xsl:template>
>
> I've tried dozens of patterns to fill the count attribute of <xsl:number>,
> without being able to find the right combination of ancestors, descendants,
> or selfs... Any clue out there?
I think that none of patterns for <xsl:number> will match your needs.
I suggest this code instead :
<xsl:template match="sect">
<xsl:variable name="sect_nesting">
<xsl:value-of select="count(ancestor-or-self::sect)"/>
</xsl:variable>
<xsl:element name="h{$sect_nesting}">
<xsl:apply-templates select="title/text()"/>
</xsl:element>
<xsl:apply-templates select="*[position() > 1]"/>
</xsl:template>
It counts the number of <sect> elements that are ancestors of a given
<sect>.
--
+---------------------------+--------------------------------+
| Michel CASABIANCA | http://www.sdv.fr/pages/casa |
| mailto:casa@xxxxxx | Articles sur Java et XML |
| Développement Java et XML | Applications et Applets de Jeu |
+---------------------------+--------------------------------+
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








