xsl-list
[Top] [All Lists]

RE: Group and sort by group element occurrences

2003-08-18 22:19:42
Hi,

I need to transform this this into a grouped and sorted list of page
id's, so that the instances of pageid that occur the most 
frequently are
first, and so that each pageid is listed only once. The above 
xml would
then look like this.

<docroot>
      <pageid>84</pageid>
      <pageid>3</pageid>
      <pageid>5</pageid>
      <pageid>1</pageid>
</docroot>

  <xsl:key name="id" match="pageid" use="."/>
  <xsl:template match="docroot">
    <xsl:copy>
      <xsl:for-each select="token/pageid[generate-id(.) = generate-id(key('id', 
.))]">
        <xsl:sort select="count(key('id', .))" data-type="number" 
order="descending"/>
        <xsl:copy-of select="."/>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>

Cheers,

Jarno - Delerium: After All

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>