RE: [xsl] grouping and ordering. SOS, one week and i don't know how to solve this problem

Subject: RE: [xsl] grouping and ordering. SOS, one week and i don't know how to solve this problem
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Fri, 20 Aug 2004 07:25:39 +0300
Hi,

> hello i have one xml file (bellow one stract) and i want to
> group noder and
> order using xslt.
> i have into one xml a lot of nodes like this:
>
> <registro>
> <producto_id>1</producto_id>
> <top_orden>1</top_orden>
> <categoria_id>1</categoria_id>
> <categoriadetalle_nombre>uno</categoriadetalle_nombre>
> </registro>
> <registro>
> <producto_id>3</producto_id>
> <top_orden>2</top_orden>
> <categoria_id>4</categoria_id>
> <categoriadetalle_nombre>uno</categoriadetalle_nombre>
> </registro>
> <registro>
> <producto_id>21</producto_id>
> <top_orden>2</top_orden>
> <categoria_id>2</categoria_id>
> <categoriadetalle_nombre>dos</categoriadetalle_nombre>
> </registro>
> ..................
>
> i want  to group using categoriadetalle_nombre and order by top_orden

  <xsl:key name="cat" match="registro" use="categoriadetalle_nombre"/>
  <xsl:template match="*[registro]">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:for-each select="registro[generate-id() = generate-id(key('cat',
categoriadetalle_nombre))]">
        <cat num="{categoriadetalle_nombre}">
          <xsl:apply-templates select="key('cat', categoriadetalle_nombre)">
            <xsl:sort select ="top_orden"/>
          </xsl:apply-templates>
        </cat>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

But you didn't mention what do you want to order. The groups, or the entries
inside the groups? The stylesheet above does the latter. If you want to order
the groups, did you want to order by the largest number in the group?

Cheers,

Jarno - Imminent Starvation: Tentack One

Current Thread