SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Mar 17, 2005, 10:55 #1
- Join Date
- Mar 2005
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
XSL How To Sort? and Output As XML
Can any body help an XML newbie
I have the following XML File:
<markers>
<book ID="War of the Worlds">
<highlights>
<highlight>
<start>2001</start>
<end>2005</start>
</highlight>
<highlight>
<start>2380</start>
<end>2410</start>
</highlight>
<highlight>
<start>10</start>
<end>32</end>
</highlight>
</highlights>
<book ID="Help">
<highlights>
<highlight>
<start>12</start>
<end>30</end>
</highlight>
<highlight>
<start>2></start>
<end>6</end>
</highlight>
</highlights>
</highlights>
</markers>
Can any body show me how to sort the start element in ascending order using XSL and output as XML, all the example's I have seen output as html, when I need xml output.
Many Thanks
-
Mar 17, 2005, 11:21 #2
Sorting:
HTML Code:<xsl:for-each select="highlight"> <xsl:sort select="start" data-type="number" order="descending"/> <xsl:value-of select="start"/> </xsl:for-each>
Code:<xsl:stylesheet...> <xsl:output method="xml" version="1.0" encoding="utf-8"/> <xsl:template...> </xsl:template> </xsl:stylesheet>
-
Mar 17, 2005, 11:54 #3
- Join Date
- Mar 2005
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I tried the following xsl stylesheet and it still not working
<xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/xsl/transform">
<xslutput method="xml" version="1.0"
encoding="utf-8"/>
<xsl:template match="markers/book/highlights">
<xsl:for-each select="highlight">
<xsl:sort select="start"
data-type="number"
order="ascending"/>
<xsl:value-of select="start"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Can somebody show me where I'm going wrong?
-
Mar 17, 2005, 20:55 #4
- Join Date
- Dec 2003
- Location
- Federal Way, Washington (USA)
- Posts
- 1,524
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
For starters, your XML file isn't well formed. For example:
Code:<start>2001</start> <end>2005</start>
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
Showcase your music collection on the Web
-
Mar 18, 2005, 03:57 #5
- Join Date
- Mar 2005
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sorry, that was just a quick and dirty post of xml the actual xml is here:
<?xml-stylesheet type="xml" href="sort.xsl"?>
<markers>
<book ID="War of the Worlds">
<highlights>
<highlight>
<start>2001</start>
<end>2005</end>
</highlight>
<highlight>
<start>2380</start>
<end>2410</end>
</highlight>
<highlight>
<start>10</start>
<end>32</end>
</highlight>
</highlights>
</book>
<book ID="Help">
<highlights>
<highlight>
<start>12</start>
<end>30</end>
</highlight>
<highlight>
<start>2</start>
<end>6</end>
</highlight>
</highlights>
</book>
</markers>
-
Mar 19, 2005, 09:57 #6
- Join Date
- Dec 2003
- Location
- Federal Way, Washington (USA)
- Posts
- 1,524
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, I managed to get something working last night but then I got too tired to try and figure out just what the differences were between your code and mine. However, I did note that one thing in particular seemed to make a difference. The top line of your XML file should read something like this:
Code:<?xml-stylesheet type="text/xsl" href="sort.xsl"?>
Code:<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="utf-8"/> <xsl:template match="markers/book/highlights"> <xsl:for-each select="highlight"> <xsl:sort select="start" data-type="number" order="ascending"/> <xsl:value-of select="start"/><br /> </xsl:for-each> </xsl:template> </xsl:stylesheet>
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
Showcase your music collection on the Web
Bookmarks