我在 .NET 的 XSLT 中使用 Muenchian 分组来按日期对指示符元素进行分组。
我的 XML 和 XSLT 的片段:
<financials>
<indicator>
<date>2010</date>
<labeltype>2</labeltype>
</indicator>
<indicator>
<date>2009</date>
<labeltype>2</labeltype>
</indicator>
<indicator>
<date>2008</date>
<labeltype>2</labeltype>
</indicator>
...
</financials>
<xsl:key name="financialsByDate" match="indicator" use="date" />
<xsl:template match="financials">
<xsl:for-each select="indicator[generate-id(.) = generate-id(key('financialsByDate', date)[1])]">
<financial>
...
</financial>
</xsl:for-each>
</xsl:template>
此代码在我提取用于测试的小型 XML 文档中运行良好,但在具有更多元素的原始 XML/XSLT 中根本无法运行。
奇怪的是,当我将文本“日期”更改为“foobar”时,它会起作用。
文档中其他地方的其他一些“日期”元素是否可能会影响我的代码?