docbook-apps

  • 1.  convert HTML TOC from

    Posted 06-17-2011 19:31
    Hi,

    I'm using the NS stylesheets to output a single HTML file from a DocBook <book> file. My final output (through PrinceXML) doesn't play nicely with the
    ,
    , and
    structures of the TOC. I'm trying to write it into my customization layer that

    becomes

    becomes

    And
    becomes

    and picks up a class attribute.

    I copied out the html/toc.xsl template and made the these changes, but the TOC comes out unchanged. Have I missed something?

    <xsl:template match="d:set/d:toc | d:book/d:toc | d:part/d:toc">
    <xsl:variable name="toc.params">
    <xsl:call-template name="find.path.params">
    <xsl:with-param name="node" select="parent::*"/>
    <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
    </xsl:call-template>
    </xsl:variable>


    <xsl:if test="not(contains($toc.params, 'toc')) and
    ($process.source.toc != 0 or $process.empty.source.toc != 0)">
    <xsl:variable name="content">
    <xsl:choose>
    <xsl:when test="* and $process.source.toc != 0">
    <xsl:apply-templates />
    </xsl:when>
    <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">

    <xsl:for-each select="parent::*">
    <xsl:choose>
    <xsl:when test="self::d:set">
    <xsl:call-template name="set.toc">
    <xsl:with-param name="toc.title.p"
    select="contains($toc.params, 'title')"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:when test="self::d:book">
    <xsl:call-template name="division.toc">
    <xsl:with-param name="toc.title.p"
    select="contains($toc.params, 'title')"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:when test="self::d:part">
    <xsl:call-template name="division.toc">
    <xsl:with-param name="toc.title.p"
    select="contains($toc.params, 'title')"/>
    </xsl:call-template>
    </xsl:when>
    </xsl:choose>
    </xsl:for-each>
    </xsl:when>
    </xsl:choose>
    </xsl:variable>

    <xsl:if test="string-length(normalize-space($content)) != 0">
    <xsl:copy-of select="$content"/>
    </xsl:if>
    </xsl:if>
    </xsl:template>

    <xsl:template match="d:chapter/d:toc | d:appendix/d:toc | d:preface/d:toc | d:article/d:toc">
    <xsl:variable name="toc.params">
    <xsl:call-template name="find.path.params">
    <xsl:with-param name="node" select="parent::*"/>
    <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
    </xsl:call-template>
    </xsl:variable>


    <xsl:if test="not(contains($toc.params, 'toc')) and
    ($process.source.toc != 0 or $process.empty.source.toc != 0)">
    <xsl:choose>
    <xsl:when test="* and $process.source.toc != 0">


    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates select="d:title"/>

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates select="*[not(self::d:title)]"/>


    <xsl:call-template name="component.toc.separator"/>
    </xsl:when>
    <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">

    <xsl:for-each select="parent::*">
    <xsl:call-template name="component.toc">
    <xsl:with-param name="toc.title.p"
    select="contains($toc.params, 'title')"/>
    </xsl:call-template>
    </xsl:for-each>
    <xsl:call-template name="component.toc.separator"/>
    </xsl:when>
    </xsl:choose>
    </xsl:if>
    </xsl:template>

    <xsl:template match="d:section/d:toc
    |d:sect1/d:toc
    |d:sect2/d:toc
    |d:sect3/d:toc
    |d:sect4/d:toc
    |d:sect5/d:toc">

    <xsl:variable name="toc.params">
    <xsl:call-template name="find.path.params">
    <xsl:with-param name="node" select="parent::*"/>
    <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
    </xsl:call-template>
    </xsl:variable>


    <xsl:if test="not(contains($toc.params, 'toc')) and
    ($process.source.toc != 0 or $process.empty.source.toc != 0)">
    <xsl:choose>
    <xsl:when test="* and $process.source.toc != 0">

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates select="d:title"/>

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates select="*[not(self::d:title)]"/>


    <xsl:call-template name="section.toc.separator"/>
    </xsl:when>
    <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">

    <xsl:for-each select="parent::*">
    <xsl:call-template name="section.toc">
    <xsl:with-param name="toc.title.p"
    select="contains($toc.params, 'title')"/>
    </xsl:call-template>
    </xsl:for-each>
    <xsl:call-template name="section.toc.separator"/>
    </xsl:when>
    </xsl:choose>
    </xsl:if>
    </xsl:template>



    <xsl:template match="d:tocpart|d:tocchap
    |d:toclevel1|d:toclevel2|d:toclevel3|d:toclevel4|d:toclevel5">
    <xsl:variable name="sub-toc">
    <xsl:if test="d:tocchap|d:toclevel1|d:toclevel2|d:toclevel3|d:toclevel4|d:toclevel5">
    <xsl:choose>
    <xsl:when test="$toc.list.type = 'div'">

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:element name="{$toc.list.type}">
    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates select="d:tocchap|d:toclevel1|d:toclevel2|
    d:toclevel3|d:toclevel4|d:toclevel5"/>
    </xsl:element>

    </xsl:when>
    <xsl:otherwise>
    <xsl:element name="{$toc.list.type}">
    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates select="d:tocchap|d:toclevel1|d:toclevel2|
    d:toclevel3|d:toclevel4|d:toclevel5"/>
    </xsl:element>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:if>
    </xsl:variable>

    <xsl:apply-templates select="d:tocentry[position() != last()]"/>

    <xsl:choose>
    <xsl:when test="$toc.list.type = 'div'">


    <xsl:attribute name="class"><xsl:value-of select="local-name(.)"/></xsl:attribute>
    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates select="d:tocentry[position() = last()]"/>


    <xsl:copy-of select="$sub-toc"/>
    </xsl:when>
    <xsl:otherwise>

  • <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates select="d:tocentry[position() = last()]"/>
    <xsl:copy-of select="$sub-toc"/>

  • </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template match="d:tocentry|d:tocdiv|d:lotentry|d:tocfront|d:tocback">
    <xsl:choose>
    <xsl:when test="$toc.list.type = 'div'">


    <xsl:attribute name="class"><xsl:value-of select="local-name(.)"/></xsl:attribute>
    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:call-template name="tocentry-content"/>


    </xsl:when>
    <xsl:otherwise>

  • <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:call-template name="tocentry-content"/>

  • </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template match="d:tocentry[position() = last()]" priority="2">
    <xsl:call-template name="tocentry-content"/>
    </xsl:template>

    <xsl:template name="tocentry-content">
    <xsl:variable name="targets" select="key('id',@linkend)"/>
    <xsl:variable name="target" select="$targets[1]"/>

    <xsl:choose>
    <xsl:when test="@linkend">
    <xsl:call-template name="check.id.unique">
    <xsl:with-param name="linkend" select="@linkend"/>
    </xsl:call-template>

    <xsl:attribute name="href">
    <xsl:call-template name="href.target">
    <xsl:with-param name="object" select="$target"/>
    </xsl:call-template>
    </xsl:attribute>
    <xsl:apply-templates/>

    </xsl:when>
    <xsl:otherwise>
    <xsl:apply-templates/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template match="d:toc/d:title">

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates/>

    </xsl:template>

    <xsl:template match="d:toc/d:subtitle">

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates/>

    </xsl:template>

    <xsl:template match="d:toc/d:titleabbrev">
    </xsl:template>




    <xsl:template match="d:book/d:lot | d:part/d:lot">

    <xsl:variable name="content">
    <xsl:choose>
    <xsl:when test="* and $process.source.toc != 0">

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates />

    </xsl:when>
    <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
    <xsl:call-template name="process.empty.lot"/>
    </xsl:when>
    </xsl:choose>
    </xsl:variable>

    <xsl:if test="string-length(normalize-space($content)) != 0">
    <xsl:copy-of select="$content"/>
    </xsl:if>
    </xsl:template>

    <xsl:template match="d:chapter/d:lot | d:appendix/d:lot | d:preface/d:lot | d:article/d:lot">
    <xsl:choose>
    <xsl:when test="* and $process.source.toc != 0">

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates />

    <xsl:call-template name="component.toc.separator"/>
    </xsl:when>
    <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
    <xsl:call-template name="process.empty.lot"/>
    </xsl:when>
    </xsl:choose>
    </xsl:template>

    <xsl:template match="d:section/d:lot
    |d:sect1/d:lot
    |d:sect2/d:lot
    |d:sect3/d:lot
    |d:sect4/d:lot
    |d:sect5/d:lot">
    <xsl:choose>
    <xsl:when test="* and $process.source.toc != 0">

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates/>

    <xsl:call-template name="section.toc.separator"/>
    </xsl:when>
    <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
    <xsl:call-template name="process.empty.lot"/>
    </xsl:when>
    </xsl:choose>
    </xsl:template>

    <xsl:template name="process.empty.lot">

    <xsl:message>
    <xsl:text>Warning: don't know what to generate for </xsl:text>
    <xsl:text>lot that has no children.</xsl:text>
    </xsl:message>
    </xsl:template>

    <xsl:template match="d:lot/d:title">

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates/>

    </xsl:template>

    <xsl:template match="d:lot/d:subtitle">

    <xsl:apply-templates select="." mode="common.html.attributes"/>
    <xsl:apply-templates/>

    </xsl:template>

    <xsl:template match="d:lot/d:titleabbrev">
    </xsl:template>


    Jason Zech | Project Manager, Digital Workflow | New Product Development
    [ph] 773-281-1818 x212 [fax] 773-281-4129 | zech@loyolapress.com<mailto:cortes@loyolapress.com>

    LoyolaPress. | A Jesuit Ministry
    3441 N. Ashland Ave. | Chicago, IL 60657 | www.loyolapress.com<http://www.loyolapress.com/>
    Join our online community of advisors: www.SpiritedTalk.org<http://www.spiritedtalk.org/>




  • 2.  Re: [docbook-apps] convert HTML TOC from

    Posted 06-19-2011 21:21
    On 17.6.2011 21:31, Jason Zech wrote:

    > I copied out the html/toc.xsl template and made the these changes, but the TOC comes out unchanged. Have I missed something?

    I suppose that you do not create ToC manually in DocBook file using
    <toc> element, but rather ToC is built automatically for you from
    structure of chapters/sections/etc. In this case you have to modify
    templates in html/autotoc.xsl.

    Out of curiosity -- why you are going through HTML and PrinceXML to PDF
    and instead of using XSL-FO stylesheets for PDF output?


    Jirka

    --
    ------------------------------------------------------------------
    Jirka Kosek e-mail: jirka@kosek.cz http://xmlguru.cz
    ------------------------------------------------------------------
    Professional XML consulting and training services
    DocBook customization, custom XSLT/XSL-FO document processing
    ------------------------------------------------------------------
    OASIS DocBook TC member, W3C Invited Expert, ISO JTC1/SC34 member
    ------------------------------------------------------------------