Created
July 1, 2020 04:48
-
-
Save emchateau/23e45d4c07b89a725866123ef0156516 to your computer and use it in GitHub Desktop.
For each group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:template match="Person"> | |
<xsl:for-each-group select="Student/Info" group-by="@Country"> | |
<country name="{current-grouping-key()}"> | |
</country> | |
</xsl:for-each-group> | |
</xsl:template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:template match="Person"> | |
<xsl:for-each-group select="Student/Info" group-by="@Country"> | |
<country name="{current-grouping-key()}"> | |
<xsl:for-each-group select="current-group()" group-by="@Name"> | |
<student name="{current-grouping-key()}"> | |
<classes> | |
<xsl:for-each select="current-group()"> | |
<class><xsl:value-of select="@Class"/></class> | |
</xsl:for-each> | |
</classes> | |
</student> | |
</xsl:for-each-group> | |
</country> | |
</xsl:for-each-group> | |
</xsl:template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- https://stackoverflow.com/questions/19115109/how-to-use-for-each-group-in-xsl/19116371#19116371 --> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<Person> | |
<Student> | |
<Info Country="England" Name="Dan" Age="20" Class="C" /> | |
</Student> | |
<Student> | |
<Info Country="England" Name="Dan" Age="20" Class="B" /> | |
</Student> | |
<Student> | |
<Info Country="England" Name="Sam" Age="20" Class="A" /> | |
</Student> | |
<Student> | |
<Info Country="Australia" Name="David" Age="22" Class="D" /> | |
</Student> | |
<Student> | |
<Info Country="Australia" Name="David" Age="22" Class="A" /> | |
</Student> | |
</Person> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment