This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Iterating through a subset of the available nodes
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] Iterating through a subset of the available nodes
- From: "Chris Bayes" <chris at bayes dot co dot uk>
- Date: Wed, 29 Aug 2001 21:08:55 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
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() < 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@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of
> Steve Bruce
> Sent: 29 August 2001 20:00
> To: XSL-List@lists.mulberrytech.com
> Subject: [xsl] 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