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

[xsl] xsl:sort question: sorting element based upon particular child node


Subject: [xsl] xsl:sort question: sorting element based upon particular child node
From: "Bruce Rojas-Rennke" <brr@xxxxxxx>
Date: Wed, 13 Aug 2003 15:58:39 -0600

Hello all,

  I have a sorting prb, - I have to put all the 'ColData' elements for each
'DataRow' into a row like so...

2003-07-01  70103     AMS Courier      2003-08-15  0   27.50
2003-07-23  29190087  Aegis Staffing   2003-08-22  0  260.00
2003-00-01  93        Boulder CC       2003-09-01  0   70.00
2003-05-13  70103     Yellow Book USA  2003-06-12  0  285.00

  In short, I have to spit out all the 'DataRows''ColData' elements,
- sorted upon the '@value' attribute of only those ColData elements which
have an '@colID' = '4'.

  Or put another way, I have to sort on element(DataRow) and it's child
nodes(all named ColData), by evaluating one attribute(ColData/@value) based
upon the value(4) of another attribute(ColData/@colID).

  The crux of my prb, as I see it, is that all the child nodes of node
'DataRow' have the same bloody name (ColData).


Here is new test code: XSLT
(OK for the one ColData (@colID='4'),
 but not all the ColData elements)
*****************************************

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="ReportRet">
  <table>
    <xsl:for-each select="//DataRow/ColData[@colID='4']">
      <xsl:sort select="@value" data-type="text" />
    <tr>
      <td>
        <xsl:value-of select="@value"/>
      </td>
    </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>

Here is new input XML test code: *************************************

<?xml version="1.0"?>
<ReportRet>
  <ReportData>
    <DataRow rowNumber="2">
      <ColData colID="2" value="2003-07-01" />
      <ColData colID="3" value="70103" />
      <ColData colID="4" value="AMS Courier" />
      <ColData colID="5" value="2003-08-15" />
      <ColData colID="6" value="0" />
      <ColData colID="7" value="27.50" />
    </DataRow>
    <DataRow rowNumber="2">
      <ColData colID="2" value="2003-05-13" />
      <ColData colID="3" value="May03" />
      <ColData colID="4" value="Yellow Book USA" />
      <ColData colID="5" value="2003-06-12" />
      <ColData colID="6" value="56" />
      <ColData colID="7" value="285.00" />
    </DataRow>
    <DataRow rowNumber="3">
      <ColData colID="2" value="2003-07-23" />
      <ColData colID="3" value="29190087" />
      <ColData colID="4" value="Aegis Staffing Services, Inc." />
      <ColData colID="5" value="2003-08-22" />
      <ColData colID="6" value="0" />
      <ColData colID="7" value="260.00" />
    </DataRow>
    <DataRow rowNumber="4">
      <ColData colID="2" value="2003-08-01" />
      <ColData colID="3" value="93" />
      <ColData colID="4" value="Boulder CC" />
      <ColData colID="5" value="2003-09-01" />
      <ColData colID="6" value="0" />
      <ColData colID="7" value="70.00" />
    </DataRow>
  </ReportData>
</ReportRet>

Above gives me results as below:
(just for the one ColData element (colID='4')
*********************************************************************

Aegis Staffing Services, Inc.
AMS Courier
Boulder CC
Yellow Book USA


tanx all


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



Current Thread
Keywords