以下變換:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="*">
<xsl:apply-templates select="@TEXT | node()"/>
</xsl:template>
<xsl:template match="node/@TEXT | text()">
<xsl:if test="normalize-space(.)">
<xsl:value-of select=
"concat(normalize-space(.), '
')"/>
</xsl:if>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
當針對這個XML文檔
<t>
<node TEXT=" txt A "/>
<node TEXT=" txt X"/>
<node>
<html>
<p> txt Y </p>
</html>
</node>
<node TEXT="txt B"/>
</t>
施加產生所想要的結果:
TXT - 答
TXT X
TXTŸ
TXT乙
請注意使用標準的XPath功能normalize-space(),它去掉了所有開頭和結尾的空格和其他替代空間的每個序列只用一個空間。