我已經在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
也許這只是使用英語。該程序根據語言規範正常工作。這並不意味着它正在做你想做的事。 –