添加此爲第二個答案,因爲在第一個的解釋仍然是(希望)足夠的信息,以保持它。
假設通過「微調」你的意思是「刪除所有空白開盤後和結束標記之前立即」,那麼以下附加模板規則應該做的伎倆:
<xsl:variable name="whitespace"> 	
</xsl:variable>
<!-- Trim all whitespace at beginning of string -->
<xsl:template name="trim-start">
<xsl:param name="text"/>
<xsl:variable name="first-char" select="substring($text, 1, 1)" />
<xsl:choose>
<xsl:when test="contains($whitespace, $first-char)">
<xsl:call-template name="trim-start">
<xsl:with-param name="text" select="substring($text, 2)" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Trim all whitespace at end of string -->
<xsl:template name="trim-end">
<xsl:param name="text"/>
<xsl:variable name="last-char" select="substring($text, string-length($text), 1)" />
<xsl:choose>
<xsl:when test="contains($whitespace, $last-char)">
<xsl:call-template name="trim-end">
<xsl:with-param name="text" select="substring($text, 1, string-length($text) - 1)" /> </xsl:call-template>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="text()">
<xsl:call-template name="trim-start">
<xsl:with-param name="text">
<xsl:call-template name="trim-end">
<xsl:with-param name="text" select=".">
</xsl:call-template>
<xsl:param>
</xsl:call-template>
</xsl:template>
感謝這樣一個複雜的解釋帕維爾。事實上,我對功能的理解是錯位的。 現在,因爲這是不可能的,是有辦法「裝飾」的使用XSLT樣式表中的所有文本節點的值。 – Vini 2009-07-15 22:27:50
@Winnie - 你有沒有找到一個解決方案來修剪複製節點中的文本? – 2012-07-06 17:31:08