这就是我想出的:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:key name="kLang" match="languageGrp" use="language/@lang" />
<xsl:key name="kDescrip" match="descrip"
use="concat(../../../language/@lang, '+', @type)" />
<xsl:variable name="uniqueLangs"
select="/mtf/conceptGrp/languageGrp
[generate-id() = generate-id(key('kLang', language/@lang)[1])]" />
<!-- A set of the first item of each <descrip>, grouped by @lang and @type -->
<xsl:variable name="uniqueDescrip"
select="/mtf/conceptGrp/languageGrp/termGrp/descripGrp/descrip
[generate-id() =
generate-id(key('kDescrip',
concat(../../../language/@lang, '+', @type))[1])]" />
<xsl:template match="mtf">
<html>
<body>
<h2>Terminologie</h2>
<table>
<tr>
<!--Zeile 1-->
<td>Konzept-ID</td>
<xsl:apply-templates select="$uniqueLangs" mode="header"/>
</tr>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="conceptGrp">
<xsl:apply-templates select="languageGrp" mode="maxGroup">
<xsl:sort select="count(termGrp)" order="descending" data-type="number"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="languageGrp" mode="header">
<td>
<xsl:value-of select="language/@type"/>
</td>
<xsl:apply-templates
select="$uniqueDescrip[../../../language/@lang =
current()/language/@lang]"
mode="header" />
</xsl:template>
<xsl:template match="descrip" mode="header">
<td>
<xsl:value-of select="@type"/>
</td>
</xsl:template>
<xsl:template match="languageGrp" mode="maxGroup">
<!-- Only use the first group out of the sorting (most termGrps) -->
<xsl:if test="position() = 1">
<xsl:apply-templates select="termGrp" />
</xsl:if>
</xsl:template>
<xsl:template match="termGrp">
<tr>
<td>
<xsl:value-of select="../../concept"/>
</td>
<!-- Iterate through all of the distinct languages -->
<xsl:apply-templates select="$uniqueLangs" mode="item">
<xsl:with-param name="currConcept" select="../.." />
<xsl:with-param name="pos" select="position()" />
</xsl:apply-templates>
</tr>
</xsl:template>
<xsl:template match="languageGrp" mode="item">
<xsl:param name="currConcept" />
<xsl:param name="pos" />
<xsl:variable name="matchingTermGrp"
select="$currConcept/languageGrp[language/@lang =
current()/language/@lang]
/termGrp[$pos]" />
<td>
<xsl:value-of select="$matchingTermGrp/term"/>
</td>
<xsl:apply-templates
select="$uniqueDescrip[../../../language/@lang = current()/language/@lang]"
mode="value">
<xsl:with-param name="termGrp" select="$matchingTermGrp" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="descrip" mode="value">
<xsl:param name="termGrp" />
<td>
<xsl:value-of select="$termGrp/descripGrp/descrip[@type = current()/@type]" />
</td>
</xsl:template>
</xsl:stylesheet>
在此输入 XML 上运行时:
<mtf>
<conceptGrp>
<concept>1</concept>
<languageGrp>
<language lang="DE" type="Deutsch"/>
<termGrp>
<term>Abbildung</term>
</termGrp>
</languageGrp>
<languageGrp>
<language lang="PL" type="Polnisch"/>
<termGrp>
<term>ilustracja</term>
</termGrp>
</languageGrp>
<languageGrp>
<language lang="RU" type="Russisch"/>
<termGrp>
<term>иллюстрация</term>
<descripGrp>
<descrip type="Other">Sales</descrip>
</descripGrp>
</termGrp>
<termGrp>
<term>рисунок</term>
<descripGrp>
<descrip type="Other">Marketing</descrip>
</descripGrp>
</termGrp>
</languageGrp>
<languageGrp>
<language lang="CS" type="Tschechisch"/>
<termGrp>
<term>vyobrazení</term>
<descripGrp>
<descrip type="Autor">MK</descrip>
<descrip type="Kontext">Marketing</descrip>
</descripGrp>
</termGrp>
</languageGrp>
</conceptGrp>
</mtf>
这会产生:
<html>
<body>
<h2>Terminologie</h2>
<table>
<tr>
<td>Konzept-ID</td>
<td>Deutsch</td>
<td>Polnisch</td>
<td>Russisch</td>
<td>Other</td>
<td>Tschechisch</td>
<td>Autor</td>
<td>Kontext</td>
</tr>
<tr>
<td>1</td>
<td>Abbildung</td>
<td>ilustracja</td>
<td>иллюстрация</td>
<td>Sales</td>
<td>vyobrazení</td>
<td>MK</td>
<td>Marketing</td>
</tr>
<tr>
<td>1</td>
<td></td>
<td></td>
<td>рисунок</td>
<td>Marketing</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>