xsl-list
[Top] [All Lists]

Re: [xsl] Sorting seems not to work completely

2011-07-27 13:19:48
Thanks Martin,
I believe I am using the free version of Saxon 9 (but did not know how to obtain the version number directly) called in a windows batch file with the command :

java -jar c:\Users\HP\saxon\saxon9.jar xml\all-themes.xml xslt\get-dates.xsl > work\dates.xml

The template, a selection of the input file, and the corresponding selection from the output file appear below.
Thanks,
Mark

Again, my template is:

<xsl:template match="List">
   <xsl:element name="List">
<xsl:for-each-group select="Item/Stamp" group-by="concat(Date/@year, ' ', Date/@month, ' ', Date/@day)">
      <xsl:sort select="Date/@year" data-type="number"></xsl:sort>
      <xsl:sort select="Date/@month" data-type="number"></xsl:sort>
      <xsl:sort select="Date/@day" data-type="number"></xsl:sort>
<xsl:sort select="@value" order="descending" data-type="number"></xsl:sort>
      <xsl:element name="Item">
<xsl:copy-of select="current()/Date" copy-namespaces="no"></xsl:copy-of> <xsl:copy-of select="current-group()" copy-namespaces="no"></xsl:copy-of>
      </xsl:element>
      </xsl:for-each-group>
   </xsl:element>
 </xsl:template>

A suitable selection of the input file [edited to remove <Stamp>'s numerous sibling elements not involved in this process]:

<List>
<Item>
<Stamp scott-number="2888" pofis-number="12" value="1" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
<Inscription czech="Ceské Budejovice" eng="Ceske Budejovice"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
   </Item>
 <Item>
<Stamp scott-number="2889" pofis-number="13" value="2" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
<Inscription czech="Ústí nad Labem" eng="Usti nad Labem"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
   </Item>
 <Item>
<Stamp scott-number="2890" pofis-number="14" value="3" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
     <Inscription czech="Ceský Crumlov" eng="Cesky Crumlov"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
   </Item>
 <Item>
<Stamp scott-number="2892" pofis-number="15" value="5" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
     <Inscription czech="Plzeň" eng="Pilzen"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
    </Item>
 <Item>
<Stamp scott-number="2895" pofis-number="16" value="8" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
     <Inscription czech="Olomouc" eng="Olomouc"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
    </Item>
 <Item>
<Stamp scott-number="2896" pofis-number="17" value="10" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
<Inscription czech="Hradec Králové" eng="Hradec Kralove"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
    </Item>
 <Item>
<Stamp scott-number="2897" pofis-number="18" value="20" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
     <Inscription czech="Praha" eng="Prague"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
    </Item>
 <Item>
<Stamp scott-number="2898" pofis-number="19" value="50" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
     <Inscription czech="Opava" eng="Opava"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
</Item>
</List>

The complete output for the sample input. My output is not in descending according to the value attribute:
<List>
<Item>
   <Date year="1993" month="7" day="1"></Date>
<Stamp scott-number="2888" pofis-number="12" value="1" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
<Inscription czech="Ceské Budejovice" eng="Ceske Budejovice"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
<Stamp scott-number="2889" pofis-number="13" value="2" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
<Inscription czech="Ústí nad Labem" eng="Usti nad Labem"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
<Stamp scott-number="2890" pofis-number="14" value="3" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
     <Inscription czech="Ceský Crumlov" eng="Cesky Crumlov"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
<Stamp scott-number="2892" pofis-number="15" value="5" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
     <Inscription czech="Plzeň" eng="Pilzen"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
<Stamp scott-number="2895" pofis-number="16" value="8" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
     <Inscription czech="Olomouc" eng="Olomouc"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
<Stamp scott-number="2896" pofis-number="17" value="10" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
<Inscription czech="Hradec Králové" eng="Hradec Kralove"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
<Stamp scott-number="2897" pofis-number="18" value="20" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
     <Inscription czech="Praha" eng="Prague"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
<Stamp scott-number="2898" pofis-number="19" value="50" type="definitive">
     <Date year="1993" month="7" day="1"></Date>
     <Inscription czech="Opava" eng="Opava"></Inscription>
     <Theme>Cities</Theme>
   </Stamp>
 </Item>
<List>

-----Original Message----- From: Martin Honnen
Sent: Wednesday, July 27, 2011 10:40 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Sorting seems not to work completely

Mark wrote:
I cannot get the @value to sort in descending order. My XML (simplified)
and template are below. The sorts on the Date attributes work, but the
one on the value attribute does not. Please, what am I doing wrong?

I don't see anything wrong with the snippets you posted. You might want
to provide more details such as an input sample you are trying to group
and sort, the result you get, the one you want, and details of the XSLT
processor you used, so that we can reproduce the problem.

--

Martin Honnen --- MVP Data Platform Development
http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--