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

Counting and double sorting on parameter

Subject: Counting and double sorting on parameter
From: Xavier Outhier <xavier.outhier@xxxxxxxxxxx>
Date: Thu, 08 Feb 2007 13:24:09 +0100
 Counting and double sorting on parameter
Hi all,

I would like to make a summary of a file by counting the occurence
of the value of a parameter of a certain element. I've used
6. Dynamically counting an attribute from
http://www.dpawson.co.uk/xsl/sect2/N2018.html.
I've problem to sort the result. Can someone have an idea?
What are the change I have to do in the XSLT?

I'm using Saxon.

Below are my data
1) the XML input
2) The expected output:
3) the current output
4) the complete XSL

Thanx,

Xavier.

1) the XML input
<?xml version="1.0" encoding="UTF-8"?>
<tiptop>
   <qwerty>
       <CPU partNum="1234"/>
       <CPU partNum="234"/>
       <CPU partNum="234"/>
       <CPU partNum="1234"/>
       <CPU partNum="54"/>
   </qwerty>
   <qwerty>
       <CPU partNum="89"/>
       <CPU partNum="94"/>
       <CPU partNum="934"/>
       <CPU partNum="934"/>
   </qwerty>
   <CPU partNum="12"/>
   <CPU partNum="26"/>
</tiptop>

2) The expected output:

partNum      Qty
1234     2
234     2
934     2
12     1
26     1
54     1
89     1
94     1

3) the current output

partNum      Qty
1234     2
234     2
54     1
89     1
94     1
934     2
12     1
26     1

4) the complete XSL

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:key name="CPUs" match="*[@partNum]" use="@partNum" />
<xsl:template match="/">
<html><head></head>
<body>
<xsl:apply-templates select="*"/>
</body>
</html>
</xsl:template>
<xsl:template match="tiptop">
<table>
<tr><th>partNum</th><th>Qty</th></tr>
<xsl:apply-templates select="//*[@partNum and generate-id(.)=generate-id(key('CPUs', @partNum))]" >
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="*[@partNum]">
<tr>
<!-- first column is the value of the partNum attribute -->
<td><xsl:value-of select="@partNum" /></td>
<!-- second column is the number of parts with that partNum -->
<td><xsl:value-of select="count(key('CPUs', @partNum))" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>


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.