因爲你只是想從字符串中刪除第一個和最後一個字符,這個簡單的轉變正是這樣做的:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="yyy/text() | zzz/text()">
<xsl:value-of select="substring(.,2, string-length() -2)"/>
</xsl:template>
</xsl:stylesheet>
當所提供的XML文檔施加:
<xxx>
<yyy>
some text with spaces inside
</yyy>
<zzz>
another text
</zzz>
</xxx>
的希望,正確的結果產生:
<xxx>
<yyy>some text with spaces inside</yyy>
<zzz>another text</zzz>
</xxx>
請注意:在更復雜的情況下,你可能要剝離工作的所有前導空格和所有尾隨witespace。
下面是使用trim()
的演示:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="trim.xsl"/>
<!-- to be applied on trim.xml -->
<xsl:output method="text"/>
<xsl:template match="/">
'<xsl:call-template name="trim">
<xsl:with-param name="pStr" select="string(/*)"/>
</xsl:call-template>'
</xsl:template>
</xsl:stylesheet>
當這種轉變是在應用
這可以,如果你使用trim()
功能/模板從FXSL完成以下XML文檔:
<someText>
This is some text
</someText>
的通緝(修剪)結果產生:
'This is some text'
您是右,上面的代碼刪除ALL換行符。這不完全是我所需要的。 – 2012-03-08 13:30:02