Re: [xsl] <br/> in FO?

Subject: Re: [xsl] <br/> in FO?
From: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Wed, 27 Feb 2002 16:07:45 +0100
"Gustaf Liljegren" <gustaf.liljegren@xxxxxx> wrote:
> I've found a reason for a <br/> tag in my DTD, and I wonder how to implement
> it in the XSL (to FO).

You have already been told that the FO equivalent of HTML

 <p>Stuff<br>more stuff</p>

is preferably

 <fo:block>
   <fo:block>Stuff</fo:block>
   <fo:block>more stuff</fo:block>
 </fo:block>

You asked also how to get from something resembling the first to the
second. This is easy if the <br/> is a immediate child of the <p>, one
solution is

 <xsl:template match="p">
   <fo:block>
     <fo:block>
       <xsl:apply-templates select="node()[not(previous-sibling::br)]"/>
     </fo:block>
     <xsl:for-each select="br">
       <fo:block>
         <xsl:apply-templates
          select="following-sibling::node()
              [generate-id(previous-sibling::br[1])=generate-id(current())]"/>
       </fo:block>
     </xsl:for-each>
   </fo:block>
 </xsl:template>

(untested)
or you can handle it as a more general grouping problem, see the XSLT FAQ.
If the <br/> could be nested, for example

 <p><em>Important Stuff<br/>more important stuff</em></p>

i can only think of a multipass solution which pulls up the <br/> to direct
child level, thereby splitting all elements it contains. (Not recommended
hack: use disable-output-escaping to generate "lone" tags)

If the above becomes unpracticable, you can have the FO processor honor
linefeed by setting the linefeed-treatment property to preserve.
(http://www.w3.org/TR/xsl/slice7.html#linefeed-treatment) That's more
of a kludge and may give unexpected results in some contexts, but you
might get a cheap shot. Inserting dummy blocks
 <xsl:template match="br">
   <fo:block/>
 </xsl:template>
(perhaps with some modifications) might also be a cheap if brittle solution
in you concrete case.

HTH
J.Pietschmann

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread