0

我在 .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”时,它会起作用。

文档中其他地方的其他一些“日期”元素是否可能会影响我的代码?

4

1 回答 1

1

其他indicator元素比其他元素更可能成为问题date。Muenchian 分组的本质是key应该只匹配您要分组的元素,因此请尝试更具体的键,例如

<xsl:key name="financialsByDate"
   match="financials/indicator" use="date" />
于 2013-03-29T11:39:57.793 回答