I am creating some xsl to transform my xml into text (which will be csv eventually). I am using VS2008. When I use the editor to create the xsl, the transformed output is
The XSLT processor strips white-space text nodes in the template only between XSLT elements.
So, in
<xsl:for-each select="//rows/row">
<![CDATA[row id=]]><xsl:value-of select="(@id)"/>
</xsl:for-each>
the xsl:for-each
element has two white-space text child nodes: One after xsl:value-of
, which is stripped; the other before the CDATA section, which is not stripped.
Bottom line: Use xsl:text
elements.
<xsl:for-each select="//rows/row">
<xsl:text><![CDATA[row id=]]></xsl:text>
<xsl:value-of select="@id"/>
</xsl:for-each>
You can use the xsl:strip element to declare which elements should not have whitespace (or use *
for all elements):
<xsl:strip-space elements="*"/>
The counter part is xsl:preserve
, which allows you to declare which elements should have whitespace preserved. You could use both:
<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="td span"/>
<!-- strip spaces from all elements apart from td and span elements -->