Linebreak question

Here should go questions about transforming XML with XSLT and FOP.
smaug42
Posts: 44

Linebreak question

Fri Feb 25, 2005 1:37 pm

Here's a tough one.... (I'm a little new at this so bear with me)...

I have some XML that looks something like this:

Code: Select all

<p>text1<br/>
text2<br/>
text3</p>

When I transform to HTML I get this:

Code: Select all

text1
text2
text3

which is what I want.

When I convert to PDF (using Docbook as an intermediate step) I either get:

Code: Select all

text1 text2 text3

or

Code: Select all

text1

text2

text3


All on one line isn't much help, and the extra spacing is also not a solution that works.

Docbook doesn't have any way to handle the BR tag in the way it's handled in HTML (according to their documentation). I could use the <literallayout> tag, but this presents all new problems since the BR tag is used in the XML in places I can't or don't want to use the <literallayout> (because it also respects the spacing in addition to the hard returns).

I've tried using <literallayout> with just a hard return as a subset of the <para> tag (using teh xsl to look for the <br/> tag and insert the <literallayout> wrapping a hard return), but I get the extra "paragraph" spacing I don't want....

So.. does anyone have any suggestions for what I could try or use to insert a linebreak in the Docbook text. If I'm up against a "you can't do this" situation, I'm willing to adjust my XML and make a new tag for the instances I want the BR and map that specifically to the <literallayout> tag in the xsl... but I figure it's worth asking before I do this...
sorin_ristache
Posts: 4144

Mon Feb 28, 2005 2:40 pm

Hello,

I think it is a bad idea to include in the XML document formatting information like where the lines should break. Such presentation issues should be handled in a XSLT stylesheet. In the HTML case the document fragment that you describe may be something like:

Code: Select all

<section>
    <p>text1</p>
    <p>text2</p>
    <p>text3</p>
</section>


and the stylesheet should generate HTML code that inserts a <br/> tag between two neighbor <p> elements from the source XML document, like this:

Code: Select all

<p>text1<br/>
text2<br/>
text3</p>


In the PDF case it is a "you can't do this" situation :). You can insert a <literallayout> tag between two neighbor <p> tags with the help of a XSLT stylesheet.

I hope that helps,
Sorin
smaug42
Posts: 44

Thu Mar 03, 2005 12:05 pm

Thanks.. that's useful information. I agree.. the <br/> tag shouldn't be used in the XML source... but... it's a historical thing that came over from the translation from HTML to XML. I'm slowly weeding out the HTML fragments that still exist - but I still have to maintian a doc set that can be built on a daily basis... so small changes.. and test.. small changes and test.. and so on.

That's what lead me to this question, and trying to find a neat and tidy way of doing this. I'll tinker with the XSL and see if I can manage to test for adjacent <p> tages and format them neatly :-) My other option is to create a new tag specifically for these instances where I need this linebreak formatting and use <literallayout>.

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 2 guests