|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Looping on a set value
Greetings. I hope folks can give me some direction. I'm trying to loop nodes
on a set number, after perfroming a sort. I have the follwoing example:
<!-- XML source --> <stories> <StoryBody> <Priority>4</ Priority > <name>My name</name> <content>Some content</content> </ StoryBody > <StoryBody> <Priority>2</ Priority > <name>My name</name> <content>Some content</content> </ StoryBody > <StoryBody> < Priority >6</ Priority > <name>Your name</name> <content>Some content</content> </StoryBody> <StoryBody> < Priority >4</ Priority > <name>Her name</name> <content>Some content</content> </StoryBody> <StoryBody> < Priority >1</ Priority > <name>His 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, nodes for StoryBody 1, 2 and only the first 4, not the second). I'm having trouble with this. The following gives me my Priority sort but matches by Priority number, not by the first 3 nodes of the tree which is what I?m after (Displays only StoryBody for Priority(s) 1&2, although I want to output 3 nodes (StoryPriority for Priority 1,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>I know the problem is in my test, and that I need a param, or variable, and be recursive by position() but I can?t work it out. If I can keep track and test for my current node list I?ll be ok. Any help would be appreciated. Thanks _________________________________________________________________ The new MSN 8: advanced junk mail protection and 2 months FREE* http://join.msn.com/?page=features/junkmail XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








