您可以使用
distinct-values
在这里获得不同的
property
钥匙,而不是
xsl:for-each-group
<xsl:variable name="properties" select="distinct-values(element/property/@key)" />
folder
然后,对于每个
element
在XML中,可以按如下方式列出属性的值
<xsl:variable name="current" select="." />
<xsl:for-each select="$properties">
<td>
<xsl:value-of select="$current/property[@key=current()]/@value" separator=", " />
</td>
</xsl:for-each>
试试这个XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="xsi">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="folder">
<xsl:variable name="properties" select="distinct-values(element/property/@key)" />
<table>
<tr>
<th>Name</th>
<th>Type</th>
<th>Text</th>
<xsl:for-each select="$properties">
<th><xsl:value-of select="."/></th>
</xsl:for-each>
</tr>
<xsl:for-each select="element">
<tr>
<td>
<xsl:value-of select="@name"/>
</td>
<td>
<xsl:value-of select="@xsi:type"/>
</td>
<td>
<xsl:value-of select="documentation"/>
</td>
<xsl:variable name="current" select="." />
<xsl:for-each select="$properties">
<td>
<xsl:value-of select="$current/property[@key=current()]/@value" separator=", " />
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
xsi
命名空间前缀。我还在XSLT中声明它以进行检索
xsl:type
编辑:如果只能使用XSLT 1.0处理器,则无法使用
去拿钥匙。相反,您需要使用一种称为
Muenchian Grouping
获取不同的键。(您也不能使用
separator
属性打开
xsl:value-of
).
请尝试以下XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="xsi">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:key name="properties" match="property" use="@key" />
<xsl:template match="folder">
<xsl:variable name="properties" select="//property[generate-id() = generate-id(key('properties', @key)[1])]/@key" />
<table>
<tr>
<th>Name</th>
<th>Type</th>
<th>Text</th>
<xsl:for-each select="$properties">
<th><xsl:value-of select="."/></th>
</xsl:for-each>
</tr>
<xsl:for-each select="element">
<tr>
<td>
<xsl:value-of select="@name"/>
</td>
<td>
<xsl:value-of select="@xsi:type"/>
</td>
<td>
<xsl:value-of select="documentation"/>
</td>
<xsl:variable name="current" select="." />
<xsl:for-each select="$properties">
<td>
<xsl:for-each select="$current/property[@key=current()]/@value">
<xsl:if test="position() > 1">,</xsl:if>
<xsl:value-of select="." />
</xsl:for-each>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>