[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Looping on a set value

Subject: RE: Looping on a set value
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Sun, 23 Feb 2003 21:43:53 -0000
xsl set value
I wouldn't do this by recursion. I would do

<xsl:for-each select="StoryBody">
  <xsl:sort select="Priority" data-type="number"/>
  <xsl:if test="position() &lt; 4">
     ...


It's possible your recursive approach could be faster, depending on the
data. You can make it work by supplying two parameters on the recursive
call, (a) the next Priority to be output, and (b) the number of items
output so far.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Alex Dragowski
> Sent: 23 February 2003 18:59
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  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 &lt; 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
> 
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.