xsl-list
[Top] [All Lists]

[xsl] Problem with count iterate values

2009-09-17 05:49:24
Hello
I have following xml:

<?xml version="1.0"?>
<?xml-stylesheet href="xsl.xsl" type="text/xsl" ?>
<elements>
        <Row Nr="1">
                <value>1</value>
                <code>22</code>
        </Row>
        <Row Nr="2">
                <value>1</value>
                <code>1</code>
        </Row>
        
        <Row Nr="3">
                <value>2</value>
                <code>2</code>
        </Row>
        <Row Nr="4">
                <value>1</value>
                <code>2</code>
        </Row>
        <Row Nr="5">
                <value>44</value>
                <code>2</code>
        </Row>
        <Row Nr="6">
                <value>1</value>
                <code>0</code>
        </Row>
</elements>
expected output:
4 times the same value in file: 0 values
3 times the same value in file: 0 values
2 times the same value in file: 3 values
1 times the same value in file: 1 values

I would like count how many values is occur in file, I mean
I would like get following output:
Number of occur value in this file
for example:
4 times the same value in file: 5 values
3 times the same value in file: 2 values
2 times the same value in file: 1 values
1 times the same value in file: 27 values
Element code can't be '0'

So I write folowing xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
        <xsl:template match="/" >
                <html>
                        <body>
                                <xsl:apply-templates />
                        </body>
               </html>
        </xsl:template>

        <xsl:key name="list" match="elements/Row" use="value" />
        <xsl:template match="elements"> 
                        <table border="1" bordercolor="black">
                        <thead>
                                <tr>
                                <th>How many times</th>
                                </tr>
                        </thead>
                        <tbody>
                        <xsl:for-each select="Row[count(. | key('list', 
value)[1]) = 1]">
                                <tr>
                                <td><xsl:value-of select="count(key('list_1', 
value)[code != '0']/value)"/>
                                </tr>
                        </xsl:for-each>
                        </tbody>
                        </table>
       </xsl:template>
</xsl:stylesheet>

but this give me list of values and number of occur every value
separately, something like this:
for example
<tr><td>2</td></tr>
<tr><td>1</td></tr>
<tr><td>3</td></tr>
<tr><td>2</td></tr>

How can I count number for each one occur? Thank you for help.
Kind regards
J23

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--