Re: [xsl] Referencing unique values by their order number.

Subject: Re: [xsl] Referencing unique values by their order number.
From: David Carlisle <davidc@xxxxxxxxx>
Date: Sat, 9 Dec 2006 00:20:24 GMT
> I do not have a separate file - and I'd rather avoid it.

ah ok, time to bring out keys then (google for muenchian grouping)


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output indent="yes"/>
<xsl:key name="i" match="item" use="."/>

<xsl:template match="x">
  <a>
    <items>
      <xsl:copy-of
  select="item[generate-id()=generate-id(key('i',.))]"/>
    </items>
    <elements>
      <xsl:for-each select="text">
      <element>
        <item>
           <xsl:value-of
  select="count(key('i',preceding-sibling::item[1])[1]/preceding-sibling::item[generate-id()=generate-id(key('i',.))])"/>
    </item>
      <xsl:copy-of select="."/>
      </element>
      </xsl:for-each>
    </elements>
  </a>
</xsl:template>

</xsl:stylesheet>


<a>
   <items>
      <item>V1</item>
      <item>V2</item>
      <item>V3</item>
   </items>
   <elements>
      <element>
         <item>0</item>
         <text>(content)</text>
      </element>
      <element>
         <item>0</item>
         <text>(content)</text>
      </element>
      <element>
         <item>1</item>
         <text>(content)</text>
      </element>
      <element>
         <item>0</item>
         <text>(content)</text>
      </element>
      <element>
         <item>2</item>
         <text>(content)</text>
      </element>
      <element>
         <item>2</item>
         <text>(content)</text>
      </element>
   </elements>
</a>

Current Thread