472,976 Members | 1,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,976 software developers and data experts.

Help sorting XML with XSL

Hello -

I need help sorting an xml file. I'd like to sort the xml based on the
value found in <colvalue> of the second <col>.

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="sort.xsl"?>
<rows>
<row>
<col><colname>VIEW_ID</colname><colvalue><![CDATA[YZGOSDC63_Q002_V001_AV01]]></colvalue></col>
<col><colname>VIEW_SIZE</colname><colvalue><![CDATA[S]]></colvalue></col>
<col><colname>TITLE</colname><colvalue><![CDATA[Small:
Indicator]]></colvalue></col>
<col><colname>PARENT_RPT</colname><colvalue><![CDATA[YZGOSDC63_Q002]]></colvalue></col>
<col><colname>TEMPLATE_ID</colname><colvalue><![CDATA[ZGO_EART_WWW_TEMPLATE_001]]></colvalue></col>
</row>
<row>
<col><colname>VIEW_ID</colname><colvalue><![CDATA[YZGOSDC63_Q002_V002_AV01]]></colvalue></col>
<col><colname>VIEW_SIZE</colname><colvalue><![CDATA[A]]></colvalue></col>
<col><colname>TITLE</colname><colvalue><![CDATA[Small: Latest
Budget]]></colvalue></col>
<col><colname>PARENT_RPT</colname><colvalue><![CDATA[YZGOSDC63_Q002]]></colvalue></col>
<col><colname>TEMPLATE_ID</colname><colvalue><![CDATA[ZGO_EART_WWW_TEMPLATE_001]]></colvalue></col>
</row>
<row>
<col><colname>VIEW_ID</colname><colvalue><![CDATA[YZGOSDC63_Q002_V003_AV01]]></colvalue></col>
<col><colname>VIEW_SIZE</colname><colvalue><![CDATA[Z]]></colvalue></col>
<col><colname>TITLE</colname><colvalue><![CDATA[Small: Last
Year]]></colvalue></col>
<col><colname>PARENT_RPT</colname><colvalue><![CDATA[YZGOSDC63_Q002]]></colvalue></col>
<col><colname>TEMPLATE_ID</colname><colvalue><![CDATA[ZGO_EART_WWW_TEMPLATE_001]]></colvalue></col>
</row>
</rows>

Here's the XSL I'm using. I've had some luck with <xsl:sort> , but I
haven't gotten it to work the way I need it to.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<xsl:for-each select="rows/row">
<tr>
<xsl:for-each select="col">
<td><xsl:value-of select="colvalue"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Jun 14 '06 #1
3 1193
>I'd like to sort the xml based on the
value found in <colvalue> of the second <col>.


<xsl:for-each select="rows/row">
<xsl:sort select="col[2]/colvalue"/>
...

.... right?

BTW, in the example you showed us, those <![CDATA[]]> sections don't
seem to be doing anything but burning bytes and wasting
transmission/parse time. Do you really need them?

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jun 15 '06 #2
That did the trick. Thanks!
You are correct that the CDATA isn't needed in this example. However, I
do have some situations where the data contained in <colvalue> is
html/xml . Perhaps I should search the string on the server side and
only add CDATA when needed. Thanks pointing it out.

Cheers
Joe Kesselman wrote:
I'd like to sort the xml based on the
>value found in <colvalue> of the second <col>.


<xsl:for-each select="rows/row">
<xsl:sort select="col[2]/colvalue"/>
...

... right?

BTW, in the example you showed us, those <![CDATA[]]> sections don't
seem to be doing anything but burning bytes and wasting
transmission/parse time. Do you really need them?

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry


Jun 15 '06 #3
dc24ua wrote:
do have some situations where the data contained in <colvalue> is
html/xml .


Simply wrapping it in <![CDATA[]]> will not always be enough in that
case. (Consider what happens when the contained XML itself contains a
CDATA section.)

If you're building the document through standard XML tools, they can
take care of escaping characters for you. If you're building it by doing
string manipulation, you're buying yourself a bunch of hassles.

Actually, the best answer is usually to make the contained XML just be
ordinary XML structure rather than trying to store its string
representation -- among other things, that way you don't have to
re-parse it if you need to look at it. Contained HTML... Well, I'd make
it XHTML and refer you to the preceeding sentence, but to each their own.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jun 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
2
by: D. Roshani | last post by:
Hello ! I wonder if any one can help me to create a cosomize sorting order (as Macro or added small program in c++ or c# which does this work) in a Access Database contaning one table only words...
3
by: Neil Hindry | last post by:
I wonder if you can help me. I have setup an address-book database in Access XP. I have the first name & surname as separate fields. As I wanted to sort my database by surname and then by first...
1
by: aredo3604gif | last post by:
On Sun, 10 Apr 2005 19:46:32 GMT, aredo3604gif@yahoo.com wrote: >The user can dynamically enter and change the rule connection between >objects. The rule is a "<" and so given two objects: >a <...
3
by: Don | last post by:
I have a "Report" that is created from a "Form". It prints a list of items, you may consider it a shopping list. In any event I use to run this in alphabetical order but have since decided to run...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
6
by: gopalsd | last post by:
Hi Friends, Can anyone pls help me to resolve my school test in PERL................ as follows..... #!/usr/bin/perl @data=N; $sum=0; print"enter the required No. of numbers to be inputed...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.