This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: <br/> in FO?


"Gustaf Liljegren" <gustaf.liljegren@xml.se> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]