This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: assigning sequence numbers to repeated tags.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]