【问题标题】:incorrect results from forfor 的结果不正确
【发布时间】:2013-03-04 09:10:17
【问题描述】:

我正在使用 xerces 使用两个 xsl 文件处理 xml,并且在我的 xsl:for-each 循环中得到错误的结果,
for 循环返回 8 个结果而不是 4 个结果
如何调试此错误?
感谢您的帮助!

xml:

<Updates>
  <update_record displayTimestamp="2013-03-08 11:44:00">
    <user>MNM3322</user>
  </update_record>
  <update_record displayTimestamp="2013-03-08 11:45:00">
    <user>MNM3323</user>
  </update_record>
  <update_record displayTimestamp="2013-03-08 11:46:00">
    <user>MNM3322</user>
  </update_record>
  <update_record displayTimestamp="2013-03-08 11:47:00">
    <user>MNM3325</user>
  </update_record>
  <LatestUpdate/>
</Updates>

first.xsl

<xsl:variable name="updates" select="//Updates"/>

second.xsl

<xsl:variable name="updatesCount"
              select="count($updates/update_record)"/>

<xsl:include href="first.xsl"/>

<xsl:value-of select="$updatesCount"/>  this gives correct result (4)
<xsl:for-each select="$updates/update_record"> this gives incorrect output (8 rows instead of 4)
       <xsl:value-of select="position()"/>
</xsl:for-each>

【问题讨论】:

  • 您的源文档是否有多个Updates 元素? $updatesCount 定义在哪里?
  • 只有一个 Updates 元素 - 我编辑以包含 updatesCount
  • 上面显示的 XSLT 是为for-each 输出“12345678”还是“12341234”或其他什么?
  • 您向我们展示的代码没有任何问题。要么你没有向我们展示一些东西,要么你误解了输出,或者(非常不可能)你有一个有问题的 XSLT 处理器。
  • 是 - 输出是 12345678 ,XERCES 版本是 Xerces-J 2.7.1 Xalan java 2.7.0

标签: xml xslt xerces


【解决方案1】:

发现问题。它的 XALAN 错误

请看这里:
如果在全局变量中使用递归模板,则循环变量/参数引用

https://issues.apache.org/jira/browse/XALANJ-2430
谢谢!

【讨论】:

    猜你喜欢
    • 2014-06-19
    • 2019-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多