【发布时间】: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