OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]

Subject: Re: [docbook-apps] xsl-stylesheets: long titles / splitting gentext output

----- Original Message ----- 
From: "Michael Weiser" <michael@weiser.dinsnail.net>
To: <docbook-apps@lists.oasis-open.org>
Sent: Wednesday, February 04, 2004 12:29 PM
Subject: [docbook-apps] xsl-stylesheets: long titles / splitting gentext

> Hi all,
> sorry if this is an FAQ but I'm somewhat puzzled by it and found no
> reference to it anywhere.
> I have a docbook-xml (dtd 4.2) document, that I transform to FO's using
> xsl-stylesheets-1.61.2 and xsltproc (libxml-2.6.2/libxslt-1.1.0) and
> then format it to PDF using XEP-3.6.3. Now I have some style problems
> with the output which boil down to the way, translated strings are
> returned by gentext.
> For one long titles get rendered like
> 2.3.2 This is a title so long that it has to
> be broken onto the next line
> But I'd rather have it look like
> 2.3.2 This is a title so long that it has to
>       be broken onto the next line
> ^^^^^^ This space should be automatically adjusted to the width of the
> label
> I had a look into the FO stylesheets to see if I could adjust them to
> produce some proper fo:blocks I could use for this adjustment. But I
> found that gentext is already returning the whole string including the
> label so that I would have to split it again using some substring-after()
> XPath function or the like.
> My other problem is with the chapter titlepages. I'd like to emulate the
> TeX look and change the standard layout
> Chapter 1. Title of the Chapter
> to something like
> Chapter 1.
> Title of the Chapter
> Same problem: To do so I'd have to split the text returned by gentext.
> So my questions are:
> 1. Are there mechanisms already in place I haven't found yet that would
> accomplish the functions I need?
> 2. If no: Is there a clean way (meaning something else than scanning for
> ". " using substring-after()) to make gentext do what I want and get
> label and title string in separate pieces?

I've formatted section titles with number labels in the manner you want.
The trick is to customize a template earlier in the sequence to avoid
having the parse the string returned by the gentext machinery.

Titles for sections are generated from the titlepage.templates.xml spec,
which is used to generate the titlepage.templates.xsl template file. In
fo/sections.xsl, the template with match="sect1" uses a call to this

<xsl:call-template name="sect1.titlepage"/>

The sect1.titlepage template is in titlepage.templates.xsl. You can go
ahead and customize that template do what you want, heading off
all the other sect1 titlepage processing which you probably don't need
(most people don't need a verso titlepage for a section).  Here is
an example of such a customized template, using fo:list-block with
the label on the left and the title in the body.

The hard part is to calculate the approximate width of the label.
XSL-FO has no provision for measuring the width of a typeset
string, so you have to count characters and estimate em's.

<xsl:template name="sect1.titlepage">

  <xsl:variable name="label">
    <xsl:apply-templates select="." mode="label.markup"/>

  <xsl:variable name="label.length">
    <xsl:value-of select="concat(string-length($label), 'em + 0.25em')"/>

  <fo:list-block provisional-label-separation="0.2em"
      <fo:list-item-label end-indent="label-end()" text-align="start">
          <xsl:apply-templates select="." mode="label.markup"/>
      <fo:list-item-body start-indent="body-start()">
          <xsl:apply-templates select="." mode="title.markup"/>


The label.markup mode returns just the number label for the current element.
The title.markup mode returns just the title for the current element.
Those templates are used by the gentext machinery as well.

Bob Stayton
Sagehill Enterprises
DocBook Consulting

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]