docbook-apps

  • 1.  Better FO footnote symbols

    Posted 10-03-2006 17:01
    Hey,

    I had to rewrite the footnote symbol handler for work this morning to
    comply with the Chicago Manual of Style 14e, 12.51. I don't really
    like the way the current stylesheets eventually go for symbols to
    numbers, so I'm sharing in hope that it might help somebody else (FO
    only):


    <xsl:param name="footnote.number.symbols"
    select="'*†‡§‖#'"/>

    helper, anywhere:
    <xsl:template name="dup">
    <xsl:param name="input"/>
    <xsl:param name="count" select="2"/>
    <xsl:choose>
    <xsl:when test="not($count) or not($input)"/>
    <xsl:when test="$count = 1">
    <xsl:value-of select="$input"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:if test="$count mod 2">
    <xsl:value-of select="$input"/>
    </xsl:if>
    <xsl:call-template name="dup">
    <xsl:with-param name="input" select="concat($input, $input)"/>
    <xsl:with-param name="count" select="floor($count div 2)"/>
    </xsl:call-template>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    in fo/footnote.xsl:
    <xsl:template match="footnote" mode="footnote.number">
    <xsl:choose>
    <xsl:when test="string-length(@label) != 0">
    <xsl:value-of select="@label"/>
    </xsl:when>
    <xsl:when test="ancestor::table or ancestor::informaltable">
    <xsl:variable name="tfnum">
    <xsl:number level="any" from="table|informaltable" format="1"/>
    </xsl:variable>
    <xsl:variable name="tfsymnum"
    select="string-length($table.footnote.number.symbols)"/>
    <xsl:call-template name="dup">
    <xsl:with-param name="input"
    select="substring($table.footnote.number.symbols, $tfnum mod
    $tfsymnum, 1)"/>
    <xsl:with-param name="count" select="ceiling($tfnum div $tfsymnum)"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:variable name="fnum">

    <xsl:number level="any"

    from="chapter|appendix|preface|article|refentry|bibliography"
    count="footnote[not(@label)][not(ancestor::table)
    and not(ancestor::informaltable)]|ulink[node()][@url !=
    .][not(ancestor::
    format="1"/>

    </xsl:variable>
    <xsl:variable name="symnum"
    select="string-length($footnote.number.symbols)"/>
    <xsl:call-template name="dup">
    <xsl:with-param name="input"
    select="substring($footnote.number.symbols, $fnum mod $symnum, 1)"/>
    <xsl:with-param name="count" select="ceiling($fnum div $symnum)"/>
    </xsl:call-template>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>


    Comments encouraged.


    Keith



  • 2.  Re: Better FO footnote symbols

    Posted 10-03-2006 18:19
    Oops, I screwed up my 1-based indexing math.. here's a correctly
    substring-ing version:
    <xsl:template match="footnote" mode="footnote.number">
    <xsl:choose>
    <xsl:when test="string-length(@label) != 0">
    <xsl:value-of select="@label"/>
    </xsl:when>
    <xsl:when test="ancestor::table or ancestor::informaltable">
    <xsl:variable name="tfnum">
    <xsl:number level="any" from="table|informaltable" format="1"/>
    </xsl:variable>
    <xsl:variable name="tfsymnum"
    select="string-length($table.footnote.number.symbols)"/>
    <xsl:call-template name="dup">
    <xsl:with-param name="input"
    select="substring($table.footnote.number.symbols, (($tfnum + 5) mod
    $tfsymnum) + 1, 1)"/>
    <xsl:with-param name="count" select="ceiling($tfnum div $tfsymnum)"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:variable name="fnum">

    <xsl:number level="any"

    from="chapter|appendix|preface|article|refentry|bibliography"
    count="footnote[not(@label)][not(ancestor::table)
    and not(ancestor::informaltable)]|ulink[node()][@url !=
    .][not(ancestor::
    format="1"/>

    </xsl:variable>
    <xsl:variable name="symnum"
    select="string-length($footnote.number.symbols)"/>
    <xsl:message>
    FNum: <xsl:value-of select="$fnum"/>
    Symnum <xsl:value-of select="$symnum"/>
    Sub: <xsl:value-of select="$fnum mod $symnum"/>
    Mark: <xsl:call-template name="dup">
    <xsl:with-param name="input"
    select="substring($footnote.number.symbols, (($fnum + 5) mod $symnum)
    + 1, 1)"/>
    <xsl:with-param name="count" select="ceiling($fnum div $symnum)"/>
    </xsl:call-template>
    </xsl:message>
    <xsl:call-template name="dup">
    <xsl:with-param name="input"
    select="substring($footnote.number.symbols, $fnum mod $symnum, 1)"/>
    <xsl:with-param name="count" select="ceiling($fnum div $symnum)"/>
    </xsl:call-template>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    Any suggestions on a better way to do the math better than the ridiculous:
    substring($footnote.number.symbols, (($fnum + 5) mod $symnum) + 1, 1)
    ?

    Thanks,
    Keith