我没有查看你的相关链接,但请查看
this page on Muenchian Grouping
。它很好地解释了XSLT 1.0中的分组。
您没有以代码的形式提供所需的输出,因此下面的示例只是添加了分组。您可能需要调整它以获得所需的显示。
XSLT 1.0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="i" match="contacte" use="@inicial"/>
<xsl:template match="/">
<html>
<head>
<title>Contactes</title>
<link rel="stylesheet" href="agenda.css"/>
</head>
<body>
<h1>Contactes</h1>
<xsl:call-template name="mostrar_contactes"/>
</body>
</html>
</xsl:template>
<xsl:template name="mostrar_contactes">
<xsl:for-each select="agenda/contacte[count(.|key('i',@inicial)[1])=1]">
<xsl:sort select="cognom1"/>
<h4><xsl:value-of select="@inicial" /></h4>
<xsl:apply-templates select="key('i',@inicial)"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="contacte">
<div class="contacte">
<xsl:if test="foto=''">
<img src="imatges/perfilneutre.jpg"/>
</xsl:if>
<xsl:if test="foto!=''">
<img src="imatges/{foto}"/>
</xsl:if>
<h2 class="nom"><xsl:value-of select="nom"/></h2>
<h2><xsl:value-of select="cognom1"/></h2>
<h3><xsl:value-of select="telefons/telmovil"/></h3>
</div>
</xsl:template>
</xsl:stylesheet>
小提琴:
http://xsltfiddle.liberty-development.net/3NzcBsC