docbook-apps

Re: [docbook-apps] clean and mode-less param switching ideas

  • 1.  Re: [docbook-apps] clean and mode-less param switching ideas

    Posted 06-24-2009 18:38
    This can be done using a customization of the template named
    'set.flow.properties' as well as a couple of attribute-sets. Generally, the
    body font is set in only a few places in an FO file. The root.properties
    attribute-set puts the font-family property on the fo:root element, which
    makes it the font for all text not otherwise specified. That means it is
    applied to all page-sequences, unless one of them overrides it. Setting the
    font-family property on an fo:flow start tag in a page-sequence will
    override the root font value.

    First, let me mention that when resetting the XSL-FO font-family property,
    just setting it to a new font name is generally not sufficient for handling
    symbols. Most fonts don't have all the symbols. So the font-family
    property should be set to a comma-separated font list that adds at least the
    Symbol font, and possibly others. The DocBook stylesheets use an internal
    param named 'body.fontset' for that reason. See this doc for more info:

    http://www.sagehill.net/docbookxsl/SpecialChars.html#fontFamilyList

    So I would suggest you create new params 'alt.body.font.family' and
    'alt.body.fontset' to specify the font name and font list, respectively.
    Then you can use the new fontset in the customized templates and
    attribute-sets.

    Here is a sample customization that detects when a part element has a
    role="part2" attribute and changes the font. You can change the test to
    whatever criteria you use.

    <xsl:param name="alt.body.font.family">Helvetica</xsl:param>

    <xsl:param name="alt.body.fontset">
    <xsl:value-of select="$alt.body.font.family"/>
    <xsl:if test="$alt.body.font.family != ''
    and $symbol.font.family != ''">,</xsl:if>
    <xsl:value-of select="$symbol.font.family"/>
    </xsl:param>

    <xsl:template name="set.flow.properties">
    <xsl:param name="element" select="local-name(.)"/>
    <xsl:param name="master-reference" select="''"/>





    <xsl:variable name="pageclass">
    <xsl:choose>
    <xsl:when test="contains($master-reference, '-draft')">
    <xsl:value-of select="substring-before($master-reference,
    '-draft')"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$master-reference"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:choose>
    <xsl:when test="$fop.extensions != 0 or $passivetex.extensions != 0">

    </xsl:when>
    <xsl:when test="starts-with($pageclass, 'body') or
    starts-with($pageclass, 'lot') or
    starts-with($pageclass, 'front') or
    $element = 'preface' or
    (starts-with($pageclass, 'back') and
    $element = 'appendix')">
    <xsl:attribute name="start-indent">
    <xsl:value-of select="$body.start.indent"/>
    </xsl:attribute>
    <xsl:attribute name="end-indent">
    <xsl:value-of select="$body.end.indent"/>
    </xsl:attribute>
    </xsl:when>
    </xsl:choose>


    <xsl:if test="ancestor::part[@role = 'part2']">
    <xsl:attribute name="font-family">
    <xsl:value-of select="$alt.body.fontset"/>
    </xsl:attribute>
    </xsl:if>

    </xsl:template>



    <xsl:attribute-set name="footer.content.properties">
    <xsl:attribute name="font-family">
    <xsl:choose>
    <xsl:when test="ancestor::part[@role = 'part2']">
    <xsl:value-of select="$alt.body.fontset"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$body.fontset"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribute-set name="header.content.properties">
    <xsl:attribute name="font-family">
    <xsl:choose>
    <xsl:when test="ancestor::part[@role = 'part2']">
    <xsl:value-of select="$alt.body.fontset"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$body.fontset"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    </xsl:attribute-set>

    There are a few other attribute-sets that use $body.fontset, such as
    footnotes. If you want complete coverage, check out the fo/param.xsl file
    and use similar xsl:choose statements for the font-family in those
    attribute-sets as well.

    Bob Stayton
    Sagehill Enterprises
    bobs@sagehill.net