我已经在xsl中为每个循环应用了一个逻辑,但它的行为不正确。谁能帮我吗。xsl为每个循环无法正常工作(逻辑)
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="https://stackoverflow.com/a/b/c">
<c>
<xsl:for-each select="https://stackoverflow.com/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="https://stackoverflow.com/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为每个循环不正常工作(逻辑)。无论我在哪里提到我已经应用了logice,但该逻辑并不符合我的要求,我明确表示它的错误仅仅是编的... :)无论如何,我会记住你的建议。 – Pulkit
也许这只是使用英语。该程序根据语言规范正常工作。这并不意味着它正在做你想做的事。 –