I am trying to get multiple html documents for every User in an XML document using XSLT based on the answer in: how to apply group by on xslt elements however without succes.
XML:
<root>
<ArrayOfResult>
<Result>
<Men>
<BowlerResult>
<Person>
<Name>name 1</Name>
</Person>
<Data>
<Score1>1</Score1>
<Score2>1</Score2>
<Score3>1</Score3>
</Data>
</BowlerResult>
<BowlerResult>
<Person>
<Name>name 2</Name>
</Person>
<Data>
<Score1>2</Score1>
<Score2>2</Score2>
<Score3>2</Score3>
</Data>
</BowlerResult>
</Men>
<Women>
<BowlerResult>
<Person>
<Name>name 3</Name>
</Person>
<Data>
<Score1>3</Score1>
<Score2>3</Score2>
<Score3>3</Score3>
</Data>
</BowlerResult>
</Women>
</Result>
<Result>...</Result>
</ArrayOfResult>
<ArrayOfResult>...</ArrayOfResult>
Person can be in more Leagues
What I want to achieve:
for every Person (distinct on Person/Name) i want to accumulate data from all ‘BowlerResult’ elements
The XSLT I have right now:
<xsl:key name="keyPerson" match="BowlerResult" use="Person/Name" />
<xsl:template match="text()" />
<xsl:template match="/root">
<root>
<xsl:apply-templates />
</root>
</xsl:template>
<xsl:template
match="BowlerResult[generate-id(.)=generate-id(key('keyPerson',Person/Name)[1])]">
<Person value="{Person/Name}">
<xsl:for-each select="key('keyPerson', Person/Name)">
<Result>
<id>
<xsl:value-of select="Person/Name" />
</id>
</Result>
</xsl:for-each>
</Person>
</xsl:template>
But this only gives me the an iteration of the first Person.
Your XSLT has a bunch of issues but the main problem here was that the first template has a path that doesn’t match anything (TeamResult is not directly under root and there is no Result element. Also, the key is named “keyPerson”, not “keyBowler”.
This XSLT successfully groups the players once per player. Could you give it a try? (n.b. the actual input XML uses element names BowlerResult and Bowler)