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

Stylesheet to remove comments and insignificant whites

Subject: Stylesheet to remove comments and insignificant whitespace
From: "Scott Moore" <puffandtoot@xxxxxxx>
Date: Fri, 28 Feb 2003 09:18:20 -0500
xsl remove comments
I'm in the process of creating a stylesheet which removes all comments from
the source document but keeps everything else.  I would also like to remove
all insignificant whitespace, but seem to be having problems in that
particular area.  So far, here's my feeble attempts:


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

 <xsl:template match="@* | * | text() | processing-instruction()">
  <xsl:copy>
   <xsl:apply-templates select="@* | * | text() |
processing-instruction()"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="text()">
  <xsl:if test="not(normalize-space(text()) = ' ')">
   <xsl:copy/>
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>


The source documents are mostly pretty printed, so I believe the carriage
returns may be the root of the problem.  Is there any way to make this work
within a stylesheet?  I'm using Xalan 2.4.1 for the transformation.

Thanks,
Scott

P.S. I am aware that the above test may remove some significant whitespace
(e.g., <xsl:text> </xsl:text>).  I'm not worried about that right now, but
will add the proper tests once I get the above working (e.g., checking for
sibling elements of the text node).


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.