You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Stephen Haberman <st...@chase3000.com> on 2002/11/05 06:59:55 UTC

breaking paragraphs and lines

Hi,

After much debate between whether I'd pick up LaTeX or XML-FO as my
preferred environment for writing reports and the like, I went with
XML-FO, FOP specifically, and have been enjoying it so far (ah, clean
separate of data and presentation).

However, I've run into a small problem I thought some others might be
able to shed some light on.

One of the things I liked about LaTeX was that two newlines were taken
to mean separate paragraphs. As far as reproducing this before with FOP
using XML/XSLT is that I'd probably have to:

1) Use Xalan to stitch XML/XSLT together. All text blocks would be in
generic fo:blocks, e.g.:

<fo:block color="grey">
  <fo:block>
    text

    text
  </fo:block>
</fo:block>

2) Run this result through a text manipulation program to replace all of
the \n\n with </fo:block><fo:block> to simulate a paragraph break.

3) Run this result through FOP.

I'm thinking this will work once I get some scripts setup for it, but
I'm just wondering if there is a better, within-FO/FOP way?

Also, a subset of this problem is that I was wanting to have a little
bit of control over breaking from the XML file, e.g. force a line break.
E.g.:

<content>
   This is a long line that I want broken<br/>here.
</content>

So I was going to use the same approach of a double <fo:block> to put
the text in, but then have a match against br and insert an artificial
block/inline-container type thing. The problem is that the match against
br has to look like:

<xsl:template match="br">
  <xsl:text disable-output-escaping="yes">
    &lt;/fo:block&gt;
    &lt;fo:block&gt;
  </xsl:text>
</xsl:template>

With straight Xalan, the result is exactly what I want... the closing,
opening fo:block comes out in XML just like the previous opening
fo:block. However, FOP seems to ignore this
disable-output-escaping="yes" attribute and I see the literal
"</fo:block><fo:block>" text in the PDF instead of it being interpreted
it as FO commands. If I run the result of Xalan on the same XML/XSLT
file through FOP via -fo, then it works great.

Any insight into either of the two issues I'm pondering would be greatly
appreciated. This is fun stuff.

Thanks,
Stephen


RE: breaking paragraphs and lines

Posted by Stephen Haberman <st...@chase3000.com>.
> Processing xml as text is kinda dangerous, especially when you are
trying to
> fiddle with tags, I believe a better and more safe way is to handle
\n\n stuff
> one stage earlier - during fo generation, that's pretty simple in xslt
to
> tokenize string into blocks by any delimiter, trivial recursive
template can
> do that.

Very cool. I'm really surprised to see how powerful, though arcane, XSLT
is. I naively thought that since I can't write imperatively, it's not a
programming language, and if something isn't in the XSL spec, it's
hard/impossible to do.

But with the hint of the tokenizing stuff be trivial, I took the
initiative I should have had before and found some 3rd
libraries/algorithms to do the \n\n -> <fo:block/> conversion. Nice.

> > <content>
> >    This is a long line that I want broken<br/>here.
> > </content>
> Search in the archive - that's faq, you can use either <block/> or
unicode
> line separator (&#x2028;).

Egads. Sorry for not following the best practice of searching the
archives. This little topic of breaking is mentioned all over the place.

> > <xsl:template match="br">
> >   <xsl:text disable-output-escaping="yes">
> >     &lt;/fo:block&gt;
> >     &lt;fo:block&gt;
> >   </xsl:text>
> > </xsl:template>
> Wrong way, disable-output-escaping implies serialization of a result
tree
> hence doesn't work otherwise, e.g. in mozilla, cocoon and fop. This
facility
> is for generating text (e.g. SQL), but not markup.

Huh. Interesting.

Thanks for all the great information, things are going much smoother
now. And sorry for not doing my homework first; I really should have
known better.

- Stephen


Re: breaking paragraphs and lines

Posted by Oleg Tkachenko <ol...@multiconn.com>.
Stephen Haberman wrote:

> 2) Run this result through a text manipulation program to replace all of
> the \n\n with </fo:block><fo:block> to simulate a paragraph break.
> 
> 3) Run this result through FOP.
> 
> I'm thinking this will work once I get some scripts setup for it, but
> I'm just wondering if there is a better, within-FO/FOP way?
Processing xml as text is kinda dangerous, especially when you are trying to 
fiddle with tags, I believe a better and more safe way is to handle \n\n stuff 
one stage earlier - during fo generation, that's pretty simple in xslt to 
tokenize string into blocks by any delimiter, trivial recursive template can 
do that.

> Also, a subset of this problem is that I was wanting to have a little
> bit of control over breaking from the XML file, e.g. force a line break.
> E.g.:
> 
> <content>
>    This is a long line that I want broken<br/>here.
> </content>
Search in the archive - that's faq, you can use either <block/> or unicode 
line separator (&#x2028;).

> <xsl:template match="br">
>   <xsl:text disable-output-escaping="yes">
>     &lt;/fo:block&gt;
>     &lt;fo:block&gt;
>   </xsl:text>
> </xsl:template>
Wrong way, disable-output-escaping implies serialization of a result tree 
hence doesn't work otherwise, e.g. in mozilla, cocoon and fop. This facility 
is for generating text (e.g. SQL), but not markup.

-- 
Oleg Tkachenko
eXperanto team
Multiconn Technologies, Israel