Page 1 of 1

Problems with linefeed treatment

Posted: Mon Mar 13, 2006 2:45 pm
by ehernandez
Hi everyone!

I'm trying to get a pdf file from my xml file using xsl-fo, but I have problems with linefeed treatment.
I put in my xsl file the next atributtes:

<fo:root linefeed-treatment="preserve" white-space-collapse="false" white-space-treatment="preserve">

Well, now if I have an xml like this:

<DOCUMENT>
<TEXT>The first line
The second line</TEXT>
</DOCUMENT>


The linefeed are preserved correctly, but If my xml is like this other:

<DOCUMENT TEXT="The first Line
The second line" />


The linefeed are not preserved.
How can I preserve the linefeed using xsl-fo if my xml is like the second one???

Best regards! Thanks in advance

Posted: Mon Mar 13, 2006 4:17 pm
by george
Hi,

Any XML parser that reads your document must normalize the attribute values, and will convert your new line character to space before that reaches the FOP. What you can do is to write the new line as a character entiry for instance:

<DOCUMENT TEXT="The first Line &#10;The second line" />

(not tested)

Best Regards,
George

Posted: Mon Mar 13, 2006 4:26 pm
by ehernandez
Hi!

The problem is that the data of the xml comes from a text area of an applet and I don't want to change it before call fop.

I try to replace the carriage return into
but when I put this code (an example from internet):

[b]contains(@TEXT,'&#xA')[/b]

It doesn't works. Before call fop I print the value of each of the characters in the xml and I can see that it contains 0x010 (&#xA) but the replace doesn't works.

I don't know what more can I do.

Best Regards,
Kike

Posted: Mon Mar 13, 2006 4:39 pm
by george
Hi,

As I said if you parse the XML that has a new line in an attribute value the parser is required to normalize that, see:
http://www.w3.org/TR/2004/REC-xml-20040204/#AVNormalize
***
Before the value of an attribute is passed to the application or checked for validity, the XML processor MUST normalize the attribute value by applying the algorithm below, or by using some other method such that the value passed to the application is the same as that produced by the algorithm.
[...]
Note that if the unnormalized attribute value contains a character reference to a white space character other than space (#x20), the normalized value contains the referenced character itself (#xD, #xA or #x9). This contrasts with the case where the unnormalized value contains a white space character (not a reference), which is replaced with a space character (#x20) in the normalized value and also contrasts with the case where the unnormalized value contains an entity reference whose replacement text contains a white space character; being recursively processed, the white space character is replaced with a space character (#x20) in the normalized value.
***

So your only chance to see the new line is to encode it as a character reference.

Best Regards,
George

Posted: Mon Mar 13, 2006 4:47 pm
by ehernandez
Hi again :)

So the only thing that I can do is have an xml like this before call fop?

[b]<DOCUMENT TEXT="The first Line &#10;The second line" /> [/b]

Or use the other xml:

[b]<DOCUMENT>
<TEXT>The first line
The second line</TEXT>
</DOCUMENT> [/b]

Isn't it?

Best regards,
Kike

Posted: Mon Mar 13, 2006 5:04 pm
by george
Hi Kike,

I see that the &#10; was replaced with a newline in the above posts, I edited them to correclty specify the charcter reference.
Yes, you should either use a character reference in an attribute value or use a text node to contain the new line.

Best Regards,
George

Posted: Mon Mar 13, 2006 6:06 pm
by ehernandez
Hi again George!

Thanks a lot for your help, you resolve my doubt very fast!

Best regards,
Kike