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

Re: [xsl] multi level sorting method


Subject: Re: [xsl] multi level sorting method
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Sat, 06 Nov 2010 11:03:28 +0100

In addition, especially for grouping problems it is interesting to know whether you are restricted to XSLT 1.0 or whether an XSLT 2.0 solution will be acceptable.

If you cannot send real input data because it is either confidential or its overall complexity masks the actual problem, it is good to make up some sample data, which (this is important) should be well-formed XML.

For example:

<?xml version="1.0" encoding="utf-8"?>
<data>
  <item>
    <Classification>A</Classification>
    <Area>north</Area>
    <Customer>Joe</Customer>
    <Street1>a</Street1>
    <Street2>b</Street2>
    <Street3>c</Street3>
  </item>
  <item>
    <Classification>A</Classification>
    <Area>south</Area>
    <Customer>Jim</Customer>
    <Street1>f</Street1>
    <Street2>e</Street2>
    <Street3>d</Street3>
  </item>
  <item>
    <Classification>C</Classification>
    <Area>west</Area>
    <Customer>John</Customer>
    <Street1>k</Street1>
    <Street2>h</Street2>
    <Street3>i</Street3>
  </item>
  <item>
    <Classification>B</Classification>
    <Area>south</Area>
    <Customer>Bob</Customer>
    <Street1>o</Street1>
    <Street2>n</Street2>
    <Street3>m</Street3>
  </item>
  <item>
    <Classification>A</Classification>
    <Area>north</Area>
    <Customer>Ignatius</Customer>
    <Street1>q</Street1>
    <Street2>p</Street2>
    <Street3>r</Street3>
  </item>
  <item>
    <Classification>A</Classification>
    <Area>north</Area>
    <Customer>Joe</Customer>
    <Street1>x</Street1>
    <Street2>y</Street2>
    <Street3>z</Street3>
  </item>
  <item>
    <Classification>A</Classification>
    <Area>west</Area>
    <Customer>Linda</Customer>
    <Street1>u</Street1>
    <Street2>v</Street2>
    <Street3>w</Street3>
  </item>
  <item>
    <Classification>B</Classification>
    <Area>center</Area>
    <Customer>Mary</Customer>
    <Street1>a</Street1>
    <Street2>a</Street2>
    <Street3>a</Street3>
  </item>
</data>

Then I see at least two different approaches:

1. Just sort the items in a flat structure, but sorted for Classification first, then for Area, etc.

2. Also create some hierarchy that reflects the grouping, for example:

<data>
   <group by="Classification" grouping-key="A">
      <group by="Area" grouping-key="north">
         <group by="Customer" grouping-key="Ignatius">
            <group by="Street1" grouping-key="q">
               <group by="Street2" grouping-key="p">
                  <group by="Street3" grouping-key="r">
                     <item>
                        <Classification>A</Classification>
                        <Area>north</Area>
                        <Customer>Ignatius</Customer>
                        <Street1>q</Street1>
                        <Street2>p</Street2>
                        <Street3>r</Street3>
                     </item>
                  </group>
               </group>
            </group>
         </group>
         <group by="Customer" grouping-key="Joe">
            <group by="Street1" grouping-key="a">
               <group by="Street2" grouping-key="b">
                  <group by="Street3" grouping-key="c">
                     <item>
                        <Classification>A</Classification>
                        <Area>north</Area>
                        <Customer>Joe</Customer>
                        <Street1>a</Street1>
                        <Street2>b</Street2>
                        <Street3>c</Street3>
                     </item>
                  </group>
               </group>
            </group>
            <group by="Street1" grouping-key="x">
               <group by="Street2" grouping-key="y">
                  <group by="Street3" grouping-key="z">
                     <item>
                        <Classification>A</Classification>
                        <Area>north</Area>
                        <Customer>Joe</Customer>
                        <Street1>x</Street1>
                        <Street2>y</Street2>
                        <Street3>z</Street3>
                     </item>
                  </group>
               </group>
            </group>
         </group>
      </group>
      <group by="Area" grouping-key="south">
         <group by="Customer" grouping-key="Jim">
            <group by="Street1" grouping-key="f">
               <group by="Street2" grouping-key="e">
                  <group by="Street3" grouping-key="d">
                     <item>
                        <Classification>A</Classification>
                        <Area>south</Area>
                        <Customer>Jim</Customer>
                        <Street1>f</Street1>
                        <Street2>e</Street2>
                        <Street3>d</Street3>
                     </item>
                  </group>
               </group>
            </group>
         </group>
      </group>
      <group by="Area" grouping-key="west">
         <group by="Customer" grouping-key="Linda">
...

and so on.

Gerrit






On 06.11.2010 10:46, Michael Kay wrote:
On 06/11/2010 06:04, ahamed meeran wrote:

Sorry, but I think you'll have to explain your problem more clearly.
Perhaps show some real input with data in the records, and the output
you want from it. It's also useful to explain how far you got with the
problem and where you got stuck.

Michael Kay
Saxonica

Hi all

grouping with multi level sorting method.

my xml file:

<Classification><Classification>
<Area><Area>
<Customer><Customer>
<Street1><Street1>
<Street2><Street2>
<Street3><Street3>

First Classification wise
second Area wise
third Customer wise
then street 1 to 3
all sorting with alphabet

Regards,
Ahmed


-- Gerrit Imsieke Geschdftsf|hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vvckler


Current Thread
Keywords