[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] How to prevent blank lines and blank inserts for this script?


Subject: [xsl] How to prevent blank lines and blank inserts for this script?
From: "Ben Stover" <bxstover@xxxxxxxxxxx>
Date: Mon, 07 Dec 2009 16:32:00 +0100

When I apply the XSLT script at the bottom of this posting then it works fine
in general. The purpose is to remove empty elements and empty attributes.
But I guess this purpose is not important.

However there is one problem. The result XML doc contains a blank line at the 
location of the removed element and the following element is shifted some blanks 
to the left border. Simplified example for the input.xml:

...
(3 blanks)<ns1:myelem>
(6 blanks)<ns2:aaa>123</ns2:aaa>
(6 blanks)<ns2:bbb></ns2:bbb>
(6 blanks)<ns2:ccc>456</ns2:ccc>
(3 blanks)</ns1:myelem>
...

I am getting an output.xml similar to:

...
(3 blanks)<ns1:myelem>
(6 blanks)<ns2:aaa>123</ns2:aaa>
(3 blanks)
(2 blanks)<ns2:ccc>456</ns2:ccc>
(3 blanks)</ns1:myelem>
...

How do I get rid of the blank line?
How do I get rid of the left shift of element <ns2:ccc>

Ben

XSLT script:

<?xml version="1.0"?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

   <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>


Current Thread
Keywords