sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
noureensyed@gmail.com's Avatar

sorting attributes based on another attribute


Question posted by: noureensyed@gmail.com (Guest) on October 25th, 2005 04:15 PM
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.

0 Answers Posted
 
Not the answer you were looking for? Post your question . . .
196,792 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,792 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors