[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

<xsl:strip-space> does NOT work when comment lines are

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
 <xsl:strip-space> does NOT work when comment lines are
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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.