Keepspace template
The keepspace template implements a standard identity transform that recursively copies all attributes and nodes, while ignoring whitespace in text nodes.
<xsl:template match="@*|node()" mode="keepspace">
<xsl:copy>
<xsl:apply-templates
select="@*|node()" mode="keepspace"/>
</xsl:copy>
</xsl:template>
This template makes the assumption that elements preserving space do not contain processing instructions. If necessary, you could create templates similar to the processing instruction template that used the keepspace mode.
Next Page:
Using the stylesheet
