次の変換:
<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 A
txt X
txt Y
txt B
標準の XPath 関数normalize-space()の使用に注意してください。これは、先頭と末尾のスペースをすべて取り除き、他の一連のスペースをすべて 1 つのスペースだけに置き換えます。