Problems with linefeed treatment

Here should go questions about transforming XML with XSLT and FOP.
ehernandez
Posts: 4
Joined: Mon Mar 13, 2006 2:43 pm

Problems with linefeed treatment

Post by ehernandez » Mon Mar 13, 2006 2:45 pm

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

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

Post by george » Mon Mar 13, 2006 4:17 pm

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
Last edited by george on Mon Mar 13, 2006 5:01 pm, edited 1 time in total.

ehernandez
Posts: 4
Joined: Mon Mar 13, 2006 2:43 pm

Post by ehernandez » Mon Mar 13, 2006 4:26 pm

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

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

Post by george » Mon Mar 13, 2006 4:39 pm

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

ehernandez
Posts: 4
Joined: Mon Mar 13, 2006 2:43 pm

Post by ehernandez » Mon Mar 13, 2006 4:47 pm

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

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

Post by george » Mon Mar 13, 2006 5:04 pm

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

ehernandez
Posts: 4
Joined: Mon Mar 13, 2006 2:43 pm

Post by ehernandez » Mon Mar 13, 2006 6:06 pm

Hi again George!

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

Best regards,
Kike

Post Reply