Subject: <xsl:strip-space> does NOT work when comment lines are involved (directly before).
From: "Ben Stover" <bxstover@xxxxxxxxxxx>
Date: Tue, 08 Dec 2009 10:12:01 +0100
|
In my previous posting I asked for a way to prevent blank lines.
Some users recommend to insert
<xsl:strip-space elements="*"/>
on top of the XSLT script. That work fine as long as there are no comments involved (directly before).
However when I have an input.xml file like
<ns1:myelem>
<ns2:aaa>123</ns2:aaa>
<!-- some comment -->
<ns2:bbb></ns2:bbb>
<ns2:ccc>456</ns2:ccc>
</ns1:myelem>
then the resulting output.xml would be:
<ns1:myelem>
<ns2:aaa>123</ns2:aaa>
<!-- some comment --><ns2:ccc>456</ns2:ccc>
</ns1:myelem>
Mind the appended XML node DIRECTLY AFTER the comment on the same line!
How can I let XSLT insert/keep the CR/eol char after the comment line
AND the keep indent (for node <ns2:ccc>?
Furthermore with
<xsl:strip-space elements="*"/>
ALL existing blank lines are removed. But I want to remove only these blank lines which are created
when empty elements are removed (with the templates of the remaining script).
How can I achieve this?
Ben
The current xslt script would be:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[normalize-space( concat(.,@*) )='']"/>
</xsl:stylesheet>
|