|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Grouping, Sorting on Aggegrated sum of the groupin
Darin,
Here's an approach using the extension function "nodeset". MSXML has it as "node-set". This can be done without nodeset, but AFAICT those approaches are longer. Thus, on your input (below), this XSL: <?xml version="1.0" encoding="iso8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="xalan"> <xsl:output method="xml" indent="yes"/> <xsl:template match="x"> <xsl:variable name="sorted-y"> <xsl:for-each select="y"> <xsl:sort select="@Value" order="descending" data-type="number"/> <xsl:copy-of select="."/> </xsl:for-each> </xsl:variable> <xsl:copy> <xsl:apply-templates select="xalan:nodeset($sorted-y)/y[position() <= 5]"/> <xsl:call-template name="sum-y"> <xsl:with-param name="n" select="xalan:nodeset($sorted-y)/y[position() > 5]"/> </xsl:call-template> </xsl:copy> </xsl:template> <xsl:template match="y">
<xsl:copy-of select="."/>
</xsl:template> <xsl:template name="sum-y">
<xsl:param name="n" select="/.."/>
<xsl:param name="total" select="0"/><xsl:choose> <xsl:when test="count($n) > 0"> <xsl:call-template name="sum-y"> <xsl:with-param name="n" select="$n[position() != 1]"/> <xsl:with-param name="total" select="$total + $n[1]/@Value"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <remainder Value="{$total}"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> produces: <?xml version="1.0" encoding="UTF-8"?> <x> <y Id="2" Name="Label1" Value="2760"/> <y Id="1" Name="Label" Value="2151"/> <y Id="14" Name="Label6" Value="193"/> <y Id="13" Name="Label5" Value="118"/> <y Id="25" Name="Label9" Value="100"/> <remainder Value="551"/> </x> Regards, --A From: "Darin" <darind@xxxxxxxxx> _________________________________________________________________ Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/
|
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








