You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Steve Schwarz <sa...@hotmail.com> on 2003/12/09 04:55:31 UTC

Serializer preserve spaces

Hi
This must be a FAQ but I can't seem to find the answer in the wiki or the 
archives...
How do I configure the XMLSerializer to preserve whitespace?

Here's my test case:
Given an XML doc test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<text>Some text with            spaces</text>

I use an XSLT stylesheet text.xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="text"/>

<xsl:template match="text">
	<new-text><xsl:apply-templates/></new-text>
</xsl:template>
</xsl:stylesheet>

With this pipeline the extra whitespace is removed:
<map:match pattern="text.xml">
	<map:generate src="text.xml"/>
	<map:transform src="style/text.xsl"/>
	<map:serialize type="xml"/>
</map:match>

Changing to the TextSerializer preserves the whitespace.
Can  I control this behavior for the XMLSerializer?

Thanks for any help,
Steve

_________________________________________________________________
Get holiday tips for festive fun. 
http://special.msn.com/network/happyholidays.armx


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Serializer preserve spaces

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Steve Schwarz wrote:
> How do I configure the XMLSerializer to preserve whitespace?

The XML serializer preserves whitespace it gest from earlier
stages.

> Here's my test case:
> Given an XML doc test.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <text>Some text with            spaces</text>
> 
> I use an XSLT stylesheet text.xsl:
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
> version="1.0">
> <xsl:strip-space elements="*"/>
> <xsl:preserve-space elements="text"/>
> 
> <xsl:template match="text">
>     <new-text><xsl:apply-templates/></new-text>
> </xsl:template>
> </xsl:stylesheet>
> 
> With this pipeline the extra whitespace is removed:
> <map:match pattern="text.xml">
>     <map:generate src="text.xml"/>
>     <map:transform src="style/text.xsl"/>
>     <map:serialize type="xml"/>
> </map:match>
> 
> Changing to the TextSerializer preserves the whitespace.
> Can  I control this behavior for the XMLSerializer?

I suppose the multiple spaces between "with" and "spaces"
appear to be missing. What kind of tool do you use to view
the result? Try a plain text editor.

J.Pietschmann


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Serializer preserve spaces

Posted by Oleg Dulin <du...@olegdulin.com>.
Steve:

It is not that simple. I don't even think it is possible. Parsers are 
free to ignore whitespace they don't consider important or relevant, so 
the serializer simply generates whatever it can see in SAX or DOM.

Google for "XML Infoset" to read more on this subject.

Oleg


Steve Schwarz wrote:

> Hi
> This must be a FAQ but I can't seem to find the answer in the wiki or 
> the archives...
> How do I configure the XMLSerializer to preserve whitespace?
>
> Here's my test case:
> Given an XML doc test.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <text>Some text with            spaces</text>
>
> I use an XSLT stylesheet text.xsl:
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
> version="1.0">
> <xsl:strip-space elements="*"/>
> <xsl:preserve-space elements="text"/>
>
> <xsl:template match="text">
>     <new-text><xsl:apply-templates/></new-text>
> </xsl:template>
> </xsl:stylesheet>
>
> With this pipeline the extra whitespace is removed:
> <map:match pattern="text.xml">
>     <map:generate src="text.xml"/>
>     <map:transform src="style/text.xsl"/>
>     <map:serialize type="xml"/>
> </map:match>
>
> Changing to the TextSerializer preserves the whitespace.
> Can  I control this behavior for the XMLSerializer?
>
> Thanks for any help,
> Steve
>
> _________________________________________________________________
> Get holiday tips for festive fun. 
> http://special.msn.com/network/happyholidays.armx
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org