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

RE: removing tab formatting during XSLT?

Subject: RE: removing tab formatting during XSLT?
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 11 Oct 2002 10:34:37 +0100
xsl remove tab
> Could someone please enlighten me on how I can remove tab 
> formatting from my resulting XML.
> 
> Here's an example:
> 
> Source XML:
> 
> <?xml version="1.0"?>
> <A>
> 	<B att="att">a</B>
> 	<C>b</C>
> 	<D>c</D>
> </A>
> 
> Desired output XML (i.e. the same as input but with all tabs removed):
> 
> <?xml version="1.0"?><A><B att="att">a</B><C>b</C><D>c</D></A>
> 
> XSLT (which doesn't work):

Your XSLT should work. In fact, the following much simpler code should
work:

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
  <xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

But I see that in a later post, you changed your example, so that A had
mixed content. If you want to remove whitespace from text nodes that
also include non-whitespace characters, you need to use
normalize-space().

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:output method="xml" version="1.0" encoding="UTF-8" 
> indent="no"/>
> 	
> 	<xsl:strip-space elements="*"/>
> 	
> 	<xsl:template match="/">
> 		<xsl:apply-templates/>
> 	</xsl:template>
> 	
> 	<xsl:template match="*">
> 		<!-- recreate the element -->
> 		<xsl:element name="{name()}">
> 			<!-- copy existing attributes-->
> 			<xsl:for-each select="@*">
> 				<xsl:copy/>
> 			</xsl:for-each>
> 			<xsl:apply-templates/>
> 		</xsl:element>
> 	</xsl:template>
> 	
> 	<xsl:variable name="tab">nbsp;</xsl:variable>
> 	
> 	<xsl:template match="text()">
> 		<xsl:value-of select="translate(. , $tab , '')"/>
> 	</xsl:template>
> 
> 	<!-- original attempt	
> 	<xsl:template match="text()">
> 		<xsl:value-of select="normalize-space(.)"/>
> 	</xsl:template>
>  	-->
>  
> </xsl:stylesheet>
> 
> I want to remove the tabs because this significantly reduces 
> the size of the file.
> 
> Thanks in advance.
> 
> cheers
> 
> Malcolm
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 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.