This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: assigning sequence numbers to repeated tags.
- From: "Elovirta Jarno (NBI/Espoo)" <Jarno dot Elovirta at nokia dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 17 Jan 2002 10:08:25 +0200
- Subject: RE: [xsl] assigning sequence numbers to repeated tags.
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi,
> I need to loop through all repeated tags (with the same
> attrib number) and add a number reference to the attrib value.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
encoding="ISO-8859-1"
indent="no"/>
<xsl:key name="attrib" match="tag" use="@attrib" />
<xsl:template match="tag">
<xsl:copy>
<xsl:attribute name="attrib">
<xsl:value-of select="@attrib" />
<xsl:if test="count(key('attrib', @attrib)) > 1">
<xsl:variable name="current" select="@attrib" />
<xsl:text />[<xsl:number count="tag[@attrib = $current]"
/>]<xsl:text />
</xsl:if>
</xsl:attribute>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Will do it. There are probably more efficient ways of doing it, hope
this helps in writing them.
Santtu
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list