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

RE: Iterating through a subset of the available nodes

Subject: RE: Iterating through a subset of the available nodes
From: "Chris Bayes" <chris@xxxxxxxxxxx>
Date: Wed, 29 Aug 2001 21:08:55 +0100
iterate through xml nodes
Steve,
Not sure what you are doing here but this stylesheet will do what I
think you want
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/test">
		<xsl:for-each select="acct">
			<xsl:sort select="@mkt_val" data-type="number"
order="descending" />
			<xsl:if test="position() &lt; 11">
				<xsl:apply-templates select="." />
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="acct">
		<xsl:value-of select="@mkt_val" />
		<!-- do some other formatting-->
	</xsl:template>
</xsl:stylesheet>

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Steve Bruce
> Sent: 29 August 2001 20:00
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Iterating through a subset of the available nodes
> 
> 
> I am attempting to create a top ten list from a list of 10 or 
> more items. In my example, I have the following XML:
> 
> <acct acct_id="2601956" mkt_val="100">
> ??? <dtl col_id="1">ABC</dtl>
> ??? <dtl col_id="2">100</dtl>
> 
> </acct>
> 
> This block is repeated numerous times with different values.? 
> For my output, I want to create a top ten list for a specific 
> account that is sorted by mkt_val.? It would look something like:
> 
> ABC??? 100
> 
> And, so on...
> 
> My first pass at solving this, I tried the code below:
> 
> <xsl:variable name="acct_id" select="2601956"/>
> <xsl:for-each select="//acct[@acct_id=$acct_id]">
> <xsl:variable name="mkt_val" select="@mkt_val"/>
> <xsl:sort select="@mkt_val" data-type="number" 
> order="descending"/> <xsl:call-template name="top10">
> ????? <xsl:with-param name="times" select="10"/> </xsl:call-template>
> 
> </xsl:for-each>
> 
> <xsl:template name="top10">
> 
> ?<xsl:param name="times"/>
> ?<xsl:if test="$times > 0">
> 
> ?<tr valign="top">
> ????? <td align="left"><xsl:value-of select="./dtl[@col_id=1]"/></td>
> ????? <td align="right"><xsl:value-of 
> select="format-number(./dtl[@col_id=2],'###,###,###,###,##0.00
> ')"/></td>
> ?</tr>
> 
> ?<xsl:call-template name="top10">
> ????? <xsl:with-param name="times" select="$times - 1"/>
> ?</xsl:call-template>
> 
> ?</xsl:if>
> 
> </xsl:template>
> 
> Of course, this doesn't work.? In this scenario, I receive 
> all the //acct/dtl rows 10 times.? Do you know how I can 
> iterate through these nodes just 10 times returning only the 
> top ten sorted values?
> 
> Thanks,
> Steve
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at 
> http://explorer.msn.com/intl.asp
> 
> 
>  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.