|
Subject: RE: [xsl] Counting and double sorting on parameter From: Kolací Tomáš <kolaci@xxxxxxx> Date: Thu, 8 Feb 2007 13:32:14 +0100 |
Maybe this way:
<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:sort
select="count(key('CPUs', @partNum))"
data-type="number"
order="descending"/>
</xsl:apply-templates>
</table>
</xsl:template>
Tomas
> -----Original Message-----
> From: Xavier Outhier [mailto:xavier.outhier@xxxxxxxxxxx]
> Sent: Thursday, February 08, 2007 1:24 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] 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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Counting and double sorting o, Xavier Outhier | Thread | Re: [xsl] Counting and double sorti, Xavier Outhier |
| RE: [xsl] Newbie question on XSL tr, Michael Kay | Date | Re: [xsl] Counting and double sorti, Xavier Outhier |
| Month |