【发布时间】:2013-12-16 17:35:08
【问题描述】:
我在 xsl for-each 循环中应用了一个逻辑,但它的行为不正确。谁能帮帮我。
XML
<a>
<b>
<c>
<string>16</string>
<string>4</string>
<string>id</string>
<int>123</int>
</c>
<c>
<string>16</string>
<string>4</string>
<string>id</string>
<int>123</int>
</c>
</b>
</a>
XSL
<xsl:for-each select="/a/b/c">
<c>
<xsl:for-each select="/a/b/c/string">"
<xsl:variable name ="pos" select="position()"/>
<xsl:if test="position() mod 2!=0">
<xsl:choose>
<xsl:when test="self::node()[text()='16']">
<int>16</int><int>4</int>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{/a/b/c/string[position()=$pos]}">"
<xsl:value-of select="/a/b/c/string[position()=$pos+1]\/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</c> </xsl:for-each>
期望的输出
<a>
<b>
<c>
<int>16</int>
<int>4</int>
<id>123</id>
</c>
<c>
<int>16</int>
<int>4</int>
<id>123</id>
</c>
</b>
</a>
实际输出
<a>
<b>
<c>
<int>16</int>
<int>4</int>
<id>123</id>
<int>16</int>
<int>4</int>
</c>
<c>
<int>16</int>
<int>4</int>
<id>123</id>
<int>16</int>
<int>4</int>
</c>
</b>
</a>
内部 for-each 循环存在一些问题,但我无法找到
【问题讨论】:
-
您提出问题的方式表明存在心态问题。如果一个程序没有达到你的预期,那么你的预期有 99.9% 的可能性是错误的。首先说“我犯了一个错误”,而不是“程序行为不正确”,然后您立即将自己定位在正确的位置开始寻找原因。
-
对不起@MichaelKay,但我写的 xsl for-each 循环不能正常工作(逻辑)。我到处提到我已经应用了一个逻辑,但这个逻辑对我来说不起作用,我清楚地说它只是我的错误,而不是 prog 的...... :) 无论如何,我会记住你的建议。
-
也许只是用英语吧。该程序根据语言规范正常工作。这并不意味着它正在做你想做的事情。
标签: xslt foreach iteration transform