sorting attributes based on another attribute

Discussion in 'XML' started by noureensyed@gmail.com, Oct 25, 2005.

  1. Guest

    Hi there,


    Any ideas on how to sort an xml of the type below. I want to output the

    exact same xml as well just sorted. However in my case I want to select

    a particular column tag below, say "Last Name" and then sort all row by

    the VALUE attribute of this particular column. So I have to first check

    if the ID Attribute matches to my desired sort key and then sort
    according to value.


    ....(more parent nodes here)
    <ROW ID="0">
    <COLUMN ID="Id" VALUE="2SIA-1772Z"></COLUMN>
    <COLUMN ID="First Name" VALUE="Ed"></COLUMN>
    <COLUMN ID="Last Name" VALUE="Holden"></COLUMN>

    <COLUMN ID="Type" VALUE=""></COLUMN>
    <COLUMN ID="Primary Specialty"
    VALUE=""></COLUMN>
    <COLUMN ID="Street Address" VALUE="1 Brookside
    Ln."></COLUMN>
    <COLUMN ID="City" VALUE="Salt Lake
    City"></COLUMN>
    <COLUMN ID="State" VALUE="UT"></COLUMN>
    <COLUMN ID="Postal Code"
    VALUE="84105"></COLUMN>
    </ROW>
    <ROW ID="1">
    <COLUMN ID="Id" VALUE="2-AGN"></COLUMN>
    <COLUMN ID="First Name" VALUE="Petra"></COLUMN>

    <COLUMN ID="Last Name" VALUE="H?ndel"></COLUMN>

    <COLUMN ID="Type" VALUE=""></COLUMN>
    <COLUMN ID="Primary Specialty"
    VALUE=""></COLUMN>
    <COLUMN ID="Street Address" VALUE=""></COLUMN>
    <COLUMN ID="City" VALUE=""></COLUMN>
    <COLUMN ID="State" VALUE=""></COLUMN>
    <COLUMN ID="Postal Code" VALUE=""></COLUMN>
    </ROW>
    <ROW ID="2">
    <COLUMN ID="Id" VALUE="1-11G4"></COLUMN>
    <COLUMN ID="First Name"
    VALUE="Patricia"></COLUMN>
    <COLUMN ID="Last Name" VALUE="Haas"></COLUMN>
    <COLUMN ID="Type" VALUE=""></COLUMN>
    <COLUMN ID="Primary Specialty"
    VALUE=""></COLUMN>
    <COLUMN ID="Street Address" VALUE=""></COLUMN>
    <COLUMN ID="City" VALUE=""></COLUMN>
    <COLUMN ID="State" VALUE=""></COLUMN>
    <COLUMN ID="Postal Code" VALUE=""></COLUMN>
    </ROW>
    ....


    I have no clue on how to go about sorting this right now. My current
    xsl looks like as below and simply returns the row nodes, with
    immediate parent back to me. Which is what I want but with sorting, for

    the new xml.


    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="DATATABLES/DATATABLE[@ID='TARGET']">
    <xsl:apply-templates select="ROW"/>
    </xsl:template>
    <xsl:template match="ROW">
    <xsl:copy-of select=".."/> <xsl:value-of select=".."/>
    </xsl:template>
    </xsl:stylesheet>


    Thanks in advance.
     
    , Oct 25, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    1,092
    Henry S. Thompson
    Mar 6, 2006
  2. Replies:
    8
    Views:
    532
  3. Replies:
    11
    Views:
    1,064
    Randolf Richardson
    Feb 3, 2007
  4. senthil
    Replies:
    4
    Views:
    107
    Joel VanderWerf
    Mar 13, 2007
  5. senthil
    Replies:
    6
    Views:
    428
    Alex Young
    Mar 27, 2007
Loading...

Share This Page