使用XSL我試圖把這個XML:問題的for-each
<book><title>This is a <b>great</b> book</title></book>
這個XML:
<book>This is a <bold>great</bold> book</book>
使用這個XSL:
<xsl:for-each select="book/title/*">
<xsl:choose>
<xsl:when test="name() = 'b'">
<bold>
<xsl:value-of select="text()"/>
</bold>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
但我的輸出是這樣的:
<book><bold>great</bold></bold>
任何人都可以解釋爲什麼<title>
的根文本正在迷路?我相信我的for-each select語句可能需要修改,但我無法弄清楚應該是什麼。
請記住,由於樣式表的複雜性,我不能使用<xsl:template match>
。
謝謝!
上面的XSL代碼是否在xsl:template中?如果是這樣,你可以添加代碼嗎? – 2009-11-30 17:19:37
@帕維爾的回答是正確的。然而,你接近這個問題的方式看起來非常脆弱(即非常規並且很容易破壞你輸入文件改變的一分鐘)。你可能會考慮更詳細地描述問題。 – 2009-11-30 17:22:41
對於一個寫得好的問題+1 + – 2009-11-30 17:23:26