我想用空格輸出,但是我想保留<xsl:strip-space elements="*"/>
以及xslt。目前,在XSLT之下是「無上的」,沒有空間。如果我刪除<xsl:strip-space elements="*"/>
標籤輸出將如預期那樣是「一二四」(注意單詞之間有兩個空格2個&四位一體的額外的空間是由於subitem3)避免在子節點中剝去空白
注:「subitem3」標籤有一個空間,這應該保留在輸出中。
有什麼辦法可以讓我保留<xsl:strip-space elements="*"/>
標籤並且還有空格(所以輸出應該像這樣=>「one two four」)。
如果這是不可能的,因爲在頂部包含xsl:strip-space,至少子項目3的空間可以保留(所以在這種情況下,期望的輸出可以是在「4」字前的「onetwo four」到subitem3)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:template match="item">
<xsl:for-each select="child::node()">
<xsl:choose>
<xsl:when test="name() = 'some_tag'">
<!-- Do nothing for now -->
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="descendant-or-self::text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
XML:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>
<subitem1>one</subitem1> <subitem2>two</subitem2> <subitem3> </subitem3> <subitem4>four</subitem4>
</item>
</items>
本輸出: onetwofour
預期輸出: 一個兩個四 OR ONETWO 4
你的問題是不可理解的:你的樣式在你的輸入匹配什麼,你不告訴我們,你的輸出**應該。 –
請再次看到我的問題,希望它更有意義 – user593029