|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Problem with node-occurence statistics
Hi,
I have an xml document that is similar to this: <?xml version="1.0" encoding="utf-8"?> <report> <group> <groupid>group1</groupid> <goalcount>2</goalcount> <details> <team> <teamleader>P.P.</teamleader> <goal>[2]</goal> </team> <team> <teamleader>T.T.</teamleader> <goal>[2]</goal> </team> </details> </group> <group> <groupid>group2</groupid> <goalcount>3</goalcount> <details> <team> <teamleader>N.N.</teamleader> <goal>[3]</goal> </team> <team> <teamleader>P.P.</teamleader> <goal>[2]</goal> </team> <team> <teamleader>T.T.</teamleader> <goal>[3]</goal> </team> </details> </group> <group> <groupid>group3</groupid> <goalcount>1</goalcount> <details> <team> <teamleader>T.T.</teamleader> <goal>[1]</goal> </team> <team> <teamleader>P.P.</teamleader> <goal>[3]</goal> </team> </details> </group> </report> I want to produce a report that will show how many times the same number of goals have been acheived under the same teamleader. So the result should look something like this: teamleader goal number of occurences P.P. 2 2 P.P. 3 1 T.T. 2 1 T.T. 3 1 T.T. 1 1 N.N. 3 1 Please can someone tell me how to do this? I have got this but it doesn't work: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl utputmethod="html"/> <xsl:key name="IDs" match="teamleader" use="../goal" /> <xsl:key name="IDs2" match="attribvalue" use="../../teamleader" /> <xsl:template match="/"> <div><table cellpadding="5"> <tr><th>teamleader</th><th>goal</th><th>Number of occurences</th></tr> <xsl:for-each select="//teamleader"> <xsl:variable name="tmp"> <xsl:value-of select="../goal" /> </xsl:variable> <xsl:variable name="tmp2"> <xsl:value-of select="." /> </xsl:variable> <xsl:if test="generate-id(.) = generate-id(key('IDs',$tmp)[1])"> <tr><td><xsl:value-of select="."/></td> <td><xsl:value-of select="$tmp" /></td> <td><xsl:value-of select="count(key('IDs',$tmp))"/></td></tr> </xsl:if> </xsl:for-each> </table> </div> </xsl:template> </xsl:stylesheet> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Problem with node-occurence statistics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|