XSLTransformer process removes extra spaces?

Hi,I’d like to create a TXT with extra spaces, from a XML file.

For this purpose I create a XSL file that repeats char " " as required, and I use the XSLTransformer.process

Unfortunately I lose the spaces.

If I change spaces by another char, for instance “0”, then It’s ok.

My java code:

…

FileWriter fw = new FileWriter(Fout);

XSLTInputSource XMLSourceIS = new XSLTInputSource(XMLSource);

XSLTInputSource StyleSheetIS = new XSLTInputSource(StyleSheet);

XSLTResultTarget tout = new XSLTResultTarget(fw);

XSLTransformer.process(XMLSourceIS, StyleSheetIS, tout);

…

I get same results using StringWriter, instead of FileWriter.

Note: if I transform the XML, file with the same stylesheet, using WSAD I get the right output.

Any ideas, here?

Thanks,

Sofia.

Subject: XSLTransformer process removes extra spaces?

You do get inconcistencies in the way whitespace is handled across different XML transformation engines.

The safest way is to include all whitespace you want preserved in an xsl text tag i.e.

xsl:text </xsl:text>

HTH - Rufus.

Subject: hit the nail on the head!!!

Rufus,Although, I cannot use the xsl:text directly as the substring of spaces is computed, you gave an excellence clue.

  • This is how I get the substring:

[…]

<xsl:value-of select=“substring($nSpaces, 1, $paddingwidth)”/>

[…]

  • I’ve created the nSpaces variable as a fixed string of n “& # 1 6 0;” enclosed by xsl:text (since now it was computed calling a template)

… and it works!!!

I see it’s very important to maintain the spaces “out of danger”.

Thanks a lot,

Sofia.

Subject: XSLTransformer process removes extra spaces?

Have you tried using xsl:preserve-space? Some examples are found at:Controlling Whitespace, Part 1

  • Johan

johan@kanngard.net

http://dev.kanngard.net

Subject: RE: XSLTransformer process removes extra spaces?

Yes, I use it at the beginning of the XSL.<xsl:transform version=“1.0” xmlns:xsl=“XSLT Namespace”>

<xsl:output method=‘text’ encoding=“UTF-16”/>

<xsl:preserve-space elements=“*”/>

…

Thanks.