WhiteSpace

Here should go questions about transforming XML with XSLT and FOP.
ameyzzin
Posts: 8
Joined: Tue Feb 15, 2005 12:00 am

WhiteSpace

Post by ameyzzin »

I have a xsl which copies a xml file to another xml file while inserting new elements,attributes etc. I use MSXSL to do the transform.
I have noticed in while looking under the hex editor that the newer xml the whitespaces have changed there were place which had a 2 bit whitespace which is converted to a 5 bit whitespace.
I do not know why t his happens.Can i preserve the whitespace.?
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi,

What do you mean by 2 bit withespace? Two whitespace characters?
If yes then I think that preserving the whitespaces depends on your stylesheet. For instance the following stylesheet will give you a copy of the input document as output and preserves the whitespaces:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Best Regards,
George
ameyzzin
Posts: 8
Joined: Tue Feb 15, 2005 12:00 am

Post by ameyzzin »

George,

In my XML i have an attribute which has base64binary data.This data has some whitespace in it .after i do a <copy-of> and i look under a Hex editor
the whitespace has changed from "OD OD OA" to "26 23 78 41".

I can send you my XML and XSL files if you want.

Thanks
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi,

Yes, send them or better a cut down version that can be used to reproduce the behavior at support at oxygenxml.com.

Best Regards,
George
ameyzzin
Posts: 8
Joined: Tue Feb 15, 2005 12:00 am

Post by ameyzzin »

george i have sent the file to support @ oxygenxml
thanks
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Amey,

You cannot keep the whitespaces inside the attribute values when you transform a document using a stylesheet because the document is parsed before it gets to the transformer and in this process the XML processor will normalize the attribute values. See http://www.w3.org/TR/2004/REC-xml-20040204/#AVNormalize for more details.

Best Regards,
George
ameyzzin
Posts: 8
Joined: Tue Feb 15, 2005 12:00 am

Post by ameyzzin »

So there is no way you can keep the original data ..this isesentially the parsing mucking up the data.
Can we have a different XSLT which will read the normalized data and convert it back to what it was originally
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Amey,

If you know what the data is supposed to be it *may* be possible, but in the general case you cannot do that as more white spaces (inclusing space, new lines, etc) are converted to a single space so you need additional information to change that space back to new lines, spaces or what was in your document.

If you have control on the input then use elements instead attributes to store that data.

Best Regards,
George
Post Reply