XML で動物のリストを作成しています。それらをクラスごとにグループ化し、3 行のテーブルに表示したいと考えています。XSLT 2.0 と for-each-group を使用してこれを実現できます
<zoo>
<animal class="fish">Koi</animal>
<animal class="fish">Lamprey</animal>
<animal class="bird">Chicken</animal>
<animal class="fish">Firefish</animal>
<animal class="fish">Bluegill</animal>
<animal class="bird">Eagle</animal>
<animal class="fish">Eel</animal>
<animal class="bird">Osprey</animal>
<animal class="bird">Turkey</animal>
<animal class="fish">Guppy</animal>
</zoo>
XSLT は次のとおりです。
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" name="html" doctype-system="about:legacy-compat" />
<xsl:template match="/">
<html><head></head><body>
<xsl:for-each-group select="//animal" group-by="@class">
<table>
<xsl:for-each-group select="current-group()" group-adjacent="ceiling(position() div 3)">
<tr>
<xsl:for-each select="current-group()">
<xsl:apply-templates select="."/>
</xsl:for-each>
</tr>
</xsl:for-each-group>
</table>
</xsl:for-each-group>
</body></html>
</xsl:template>
<xsl:template match="animal">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>
動物の名前を並べ替える必要があることを除けば、出力はほぼ完璧です。
<xsl:perform-sort select="current-group()"> を使用してみました Michael Kay がここで誰かに提案したように。しかし、これによりスタックオーバーフローが発生しました。グループ化された複数列のリストで動物の名前を並べ替える方法はありますか?