[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: grouping and ordering. SOS, one week and i don't k

Subject: RE: 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
don.tk
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.