RE: [xsl] removing tab formatting during XSLT?

Subject: RE: [xsl] removing tab formatting during XSLT?
From: "Richard Lander" <rlander@xxxxxxxxxxxxx>
Date: Thu, 10 Oct 2002 14:35:50 -0700
Just as an FYI ...

I do all of my XSLT work in Visual XSLT, which is a VS.Net add-in. I
really enjoy using both tools ... Visual XSLT definitely has some nice
productivity-boosting features. Since I write C# the rest of the time,
it is nice to be able to stay in VS for XSLT ... and schema too ... 

Visual XSLT uses the XML and XSLT namespace/classes in the .net
framework, although it can be made to use Xalan.

Back to the issue at hand ... you should be wary of using
normalize-space(). It is a pretty powerful tool that can be problematic
at times, or at least has been for me.

Given:
<para>here 	 is    some <inline>text</inline> as an
example</para>

Result after normalize-space:

<para>here is some<inline>text</inline>as an example</para>

What I'd really want:
<para>here is some <inline>text</inline> as an example</para>

Anyway, there are ways of handling this situation, but you have to be
careful.

Thanks,

Rich

-----Original Message-----
From: Macaulay,Malcolm (US) [mailto:Malcolm.Macaulay2@xxxxxxxxx] 
Sent: Thursday, October 10, 2002 2:13 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx

Thanks Richard, Joerg, and Michael,

That works great. I did the transform using Instant Saxon and all the
tabs were gone. I need to have a play with MSXML in my application and
confirm that this works. I've been using XMLSpy, but this is misleading
me, because:

 - XMLSpy indents (i.e. 'pretty-prints') the resulting XML if your use
it's 'Apply XSL' facility
 - XMLSpy does not however format files which you open

Thanks again!

cheers

Malcolm



-----Original Message-----
From: Richard Lander [mailto:rlander@xxxxxxxxxxxxx]
Sent: Thursday, October 10, 2002 3:16 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] removing tab formatting during XSLT?


Does this help?

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

	<xslt:template match="/">
		<xslt:apply-templates/>
	</xslt:template>
	
	<xslt:template match="node() | @*">
		<xslt:copy>
			<xslt:apply-templates select="node() | @*"/>
		</xslt:copy>
	</xslt:template>

	<xslt:template match="text()">
		<xslt:value-of select="normalize-space(.)"/>
	</xslt:template>	

</xslt:stylesheet>

Rich 
 
-----Original Message-----
From: Macaulay,Malcolm (US) [mailto:Malcolm.Macaulay2@xxxxxxxxx] 
Sent: Thursday, October 10, 2002 1:01 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx

Thanks Richard,

Still no go however. I changed my XLST to:

<?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()}">
			<xsl:apply-templates/>
		</xsl:element>
	</xsl:template>
	
	<xsl:variable name="tab">&#x9;</xsl:variable>
	
	<xsl:template match="text()">
		<xsl:value-of select="translate(. , $tab , '')"/>
	</xsl:template>

</xsl:stylesheet> 

However the match="text()" template does not get invoked on the *
element below:

<?xml version="1.0"?>
<A>
	*<B att="att">a</B>
	<C>b</C>
	<D>c</D>
</A>

I'm clearly misunderstanding this. Is there a text element in the *
position?

Any additional help would be greatly appreciated.

cheers

Malcolm


-----Original Message-----
From: Richard Lander [mailto:rlander@xxxxxxxxxxxxx]
Sent: Thursday, October 10, 2002 2:18 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] removing tab formatting during XSLT?


I've done this sort of thing before ... 

You have two problems, as I see it.

1- you are referencing a named entity (nbsp;) w/o really doing so. You
would need to use '&nbsp;'. Still, that probably doesn't make any sense,
given that a non-breaking space isn't the same as a tab.

2. You should search on '&#x9;' instead. I'm pretty sure that that is
the tab character ...

Rich
 
-----Original Message-----
From: Macaulay,Malcolm (US) [mailto:Malcolm.Macaulay2@xxxxxxxxx] 
Sent: Thursday, October 10, 2002 10:55 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx

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

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


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




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


 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