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

RE: [xsl] sort order="descending" question


Subject: RE: [xsl] sort order="descending" question
From: Jeff Beadle <Jbeadle@xxxxxxxx>
Date: Thu, 7 Aug 2003 17:09:35 -0400

By default the xsl:sort will treat the datatype of the @select as "text" ...
you just need to define yours as "number".

The xsl:sort/@data-type attribute has two enumerations:  "text" and
"number";

This should do the trick:

   <xsl:sort select="position()" order="descending" data-type="number"/>

-Jeff

-----Original Message-----
From: Jessica P. Hekman [mailto:jphekman@xxxxxxxxxxxx]
Sent: Thursday, August 07, 2003 4:49 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] sort order="descending" question


I'm getting some weird behavior, and I've tried using three different XSLT 
processors, all of which do the same thing; so it must be me 
misunderstanding XSLT.

Basically, I have a list of elements in the input document, and I'm trying
to reverse their order in the output document.

Input:

  <bar>
    <baz>1</baz>
    <baz>2</baz>
    <baz>3</baz>
    <baz>4</baz>
    <baz>5</baz>
    <baz>6</baz>
    <baz>7</baz>
    <baz>8</baz>
    <baz>9</baz>
    <baz>10</baz>
    <baz>11</baz>
    <baz>12</baz>
  </bar>

XSL:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">

  <xsl:template match="/">
    <bar>
      <xsl:apply-templates select="/bar/baz">
        <xsl:sort select="position()" order="descending"/>
      </xsl:apply-templates>
    </bar>
  </xsl:template>

  <xsl:template match="baz">
    <baz><xsl:apply-templates/></baz>
  </xsl:template>

</xsl:stylesheet>


Output:

<bar>
  <baz>9</baz>
  <baz>8</baz>
  <baz>7</baz>
  <baz>6</baz>
  <baz>5</baz>
  <baz>4</baz>
  <baz>3</baz>
  <baz>2</baz>
  <baz>12</baz>
  <baz>11</baz>
  <baz>10</baz>
  <baz>1</baz>
</bar>


So I'd expect the output to be 12, 11, 10, 9, 8... But it's out of order. 
If I have only 9 elements, they are output in order; it's when I add the 
tenth that this misordering starts. All processors I tried (Sablotron, 
xsltproc, and Xalan) produced exactly the same output.

Does anyone know what's going on?

Thanks very much,
Jessica



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

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



Current Thread
Keywords