[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Yet another grouping question


Subject: [xsl] Yet another grouping question
From: Shawn McKenzie <smckenzie23@xxxxxxxxx>
Date: Wed, 15 Sep 2004 21:26:31 -0700

So I've gone through the 'XSLT Questions and Answers' and Jeni's site
and it is still not clear to me why my Muenchien grouping isn't
working. Specificaly, the step related to limiting responses to the
first in the group.

Imagine I have an XML file like this:

<indexRoot>
  <indexItem primary="ide" secondary="object repository"/>
  <indexItem primary="ide" secondary="Project Manager"/>
  <indexItem primary="ide" secondary="Code Editor"/>
  <indexItem primary="projects" secondary="type of"/>
  <indexItem primary="projects" secondary="additional projects"/>
  <indexItem primary="unmanaged code"/>
</indexRoot>


I would like to group it something like:


      <index>
           <primary name="ide">
                 <secondary name="object repository"/>
                 <secondary name="Project Manager"/>
                 <secondary name="Code Editor"/>
           </primary>
           <primary name="projects">
                 <secondary name="type of"/>
                 <secondary name="additional projects"/>
           </primary>
           <primary name="unmanaged code"/>
      </index>

I have defined a key like this:

 <xsl:key name="index-by-primary" match="indexItem" use="@secondary" />

When I try to get the first with something like:

 <xsl:for-each select="indexItem[count(. | key('index-by-primary',
@primary)[1]) = 1]">
    <xsl:message>
       <xsl:value-of select="@primary"/>, <xsl:value-of select="@secondary"/>
    </xsl:message>
  </xsl:for-each>

I get a message for every indexItem, not just the first of each unique
@secondary.


Current Thread
Keywords
xml