troubleshooting Question

XSLT Grouping distinct values

Avatar of springy143
springy143 asked on
Web Languages and StandardsJavaScriptXML
8 Comments1 Solution425 ViewsLast Modified:
I have some xml and I want to group distinct by year and weekno. All the the attributes are in the same elements like this example.

<items>
<item id="2" name="kent" type="region">
      <item  id="07/05/2007" type="datesInfo" weekNo="19" year="2007" />
      <item  id="09/05/2007" type="datesInfo" weekNo="19" year="2007" />
      <item  id="02/02/2011" type="datesInfo" weekNo="5" year="2011" />
      <item  id="04/02/2011"  type="datesInfo" weekNo="5" year="2011" />
      <item  id="22/07/2011"  type="datesInfo" weekNo="29" year="2011" />
      <item  id="02/02/2013"  type="datesInfo" weekNo="5" year="2013" />
</items>

Output would look like this
2007 - 19
2011 - 5, 29
2013 - 5

I am trying to use the Muenchian method. Here is what I have so far. Below script just gets the unique years. I cant get the weeknumbers in a distinct group by.

  <xsl:key name="years" match="item" use="@year"/> 
 


<xsl:template match="//item">
    <ul>
    <xsl:for-each select="item[generate-id() = generate-id(key('years',@year)[1])]">
      <li>
      <xsl:value-of select="@year"/>
      </li>
    </xsl:for-each>
    </ul>
 </xsl:template>
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)
Information Architect
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros