Subject: [xsl] Looping on a set value while ordering by value From: Alex Dragowski <alex@xxxxxxxxxx> Date: Wed, 12 Mar 2003 14:04:19 -0500 |
I'm trying to sort a long XML file, and ouput a set number of nodes after the sort. Using the following XML data file: <!- XML source --> <stories> <StoryBody> <Priority>4</ Priority > <name>My name</name> <content>Some content</content> </ StoryBody > <StoryBody> <Priority>2</ Priority > <name>Your name</name> <content>Some content</content> </ StoryBody > <StoryBody> < Priority >6</ Priority > <name>Her name</name> <content>Some content</content> </StoryBody> <StoryBody> < Priority >4</ Priority > <name>His name</name> <content>Some content</content> </StoryBody> <StoryBody> < Priority >1</ Priority > <name>Their name</name> <content>Some content</content> </StoryBody> <!-- More Content --> </stories> I'd like to sort by <Priority> but only output a set number of results (in this case, output 3 nodes which would be StoryBody 1, 2 and only the first 4, not the second). I'm having trouble with this. The following gives me my sort by Priority, but outputs by matching Priority number, not by the number of nodes (3) that I'm after (Displays only StoryBody for Priority(s) 1&2, although I want to output 3 nodes (StoryPriority for Priority1,2 &4): <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <table bgcolor="#ffffff" border="0" cellpadding="2" cellspacing="2" width="450"> <xsl:call-template name="displayitems"/> </table> </xsl:template> <xsl:template name="displayitems"> <xsl:param name="index" select="1"/> <xsl:for-each select="stories/StoryBody[Priority=$index]"> <tr> <td> <!-Content --> </td> </tr> </xsl:for-each> <!-Here's where I run into problems --> <xsl:if test="$index < 3"> <xsl:call-template name="displayitems"> <xsl:with-param name="index" select="$index + 1"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> I need to be recursive for (3) nodes, and I need to have them sorted by Priority also. I need a recursive loop within a loop. My test is incorrect and needs to be by position() but I can't work it out. Any direction with this would be greatly appreciated. Thank you much, Alex XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Auto-Numbering, Mike Brown | Thread | Re: [xsl] copy XML and add attribut, Rick Taylor |
Re: [xsl] is there really a need fo, Wendell Piez | Date | [xsl] manipulate xml with xsl/javas, Mac Martine |
Month |