Vypis Part-u v TOC

Pavol Vaskovic pavol.vaskovic na softproject.de
Pátek Září 19 13:37:03 CEST 2003


Jirka Kosek wrote:

> Pavol Vaskovic wrote:
>
>> Dakujem za promptnu odpoved, bol to zaujimavy pokus. Text "Part" sa 
>> skutocne objavil aj v obsahu, skoda, ze za celym textom je bodka 
>> namiesto dvojbodky. Ta sa zjavne doplna niekde inde. V obsahu mam 
>> teraz: "Part I. Part Name".
>
> Můžete to změnit pomocí parametru $autotoc.label.separator
> ale ten platí pro vše. Pokud to pro "part" chcete jinak, musíte 
> upravit šablonu toc.line v autotoc.xsl tak, aby se pro part chovala 
> odlišně.

Presne to je ten problem, nechcem to ovplyvnit u vsetkych - len pri 
part. Uz mam upravenu sablonu toc.line, momentalne mi robi tmave pozadie 
a svetle pismo a prepne leader-pattern z bodiek na medzery. Vysledok je 
celkom pekny. Ale sposob akym sa vyplna text riadku, ktory vytahuje z 
part jeho 'title' a ako pred neho vlozi cislo je dost zahadny. Viem ze 
tam je jadro mojho problemu, ale nechapem tu hierarchiu volani... :-(
Experimentovanim s vasim templatom a s l10n som dosiahol stav, ked mam 
vsade v texte a v bookmarkoch: "Part I: Part name" a v obsahu a "Part I. 
Part name".

Relevantne casti stylu su tu:

<xsl:template match="part" mode="label.markup">
  <xsl:choose>
    <xsl:when test="@label">
      <xsl:value-of select="@label"/>
    </xsl:when>
    <xsl:when test="$part.autolabel != 0">
      Part <xsl:number from="book" count="part" format="I"/>
    </xsl:when>
  </xsl:choose>
</xsl:template>

<!-- Xref & title customization -->
<xsl:param name="local.l10n.xml" select="document('')"/>
<i18n xmlns="http://docbook.sourceforge.net/xmlns/l10n/1.0">

  <!-- Localization -->
  <l10n language="en">
        <gentext name="hyphenation-character" text="-"/>
       
        <gentext key="Part" text=""/>
        <gentext key="part" text=""/>

    <context name="title">         
            <!-- <template name="part" text="Part %n: %t"/> -->
            <template name="part" text="%n: %t"/>
    </context>

  </l10n>
</i18n>

Neviem najst kde sa pri generovani obsahu pripaja za cislo ta bodka. 
Potom by bolo mozne upravit tu konkretnu sablonu pre specialny pripad 
Part na jednom mieste... a nejako tu upravu zjednodusit. Teraz mam pocit 
ze som predefinoval dost vela veci. Nevidim vo vysledku sice ziaden 
problem, ale nemam z toho najlepsi pocit.

Este pre zaujimavost, tu je moja uprava toc.line, ktory tucnym pismom 
zvyraznuje kapitoly a ostatne elementy typu component.

<!-- TOC customization - bold components, special markup for Parts -->
<xsl:template name="toc.line">
  <xsl:variable name="id">
    <xsl:call-template name="object.id"/>
  </xsl:variable>

  <xsl:variable name="label">
    <xsl:apply-templates select="." mode="label.markup"/>
  </xsl:variable>
   
  <xsl:variable name="component">
    <xsl:call-template name="is.component"/>
  </xsl:variable>
   
  <xsl:variable name="part">
    <xsl:choose>
      <xsl:when test="local-name(.) = 'part'">1</xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <fo:block text-align-last="justify"
            end-indent="{$toc.indent.width}pt"
            last-line-end-indent="-{$toc.indent.width}pt">
    <xsl:if test="$part = 1">
      <xsl:attribute name="font-weight">bold</xsl:attribute>
      <xsl:attribute name="color">white</xsl:attribute>
      <xsl:attribute name="background-color">#333333</xsl:attribute>
      <xsl:attribute name="padding-left">.4em</xsl:attribute>
      <xsl:attribute name="space-before">.7em</xsl:attribute>
      <xsl:attribute name="space-after">.5em</xsl:attribute>
    </xsl:if>
    <fo:inline keep-with-next.within-line="always">
      <xsl:if test="$component = 1">
        <xsl:attribute name="font-weight">bold</xsl:attribute>
      </xsl:if>
      <fo:basic-link internal-destination="{$id}">
        <xsl:if test="$label != ''">
          <xsl:copy-of select="$label"/>
          <xsl:value-of select="$autotoc.label.separator"/>
        </xsl:if>
        <xsl:apply-templates select="." mode="title.markup"/>
      </fo:basic-link>
    </fo:inline>
    <fo:inline keep-together.within-line="always">
      <xsl:if test="$component = 1">
          <xsl:attribute name="font-weight">bold</xsl:attribute>
      </xsl:if>
      <xsl:text> </xsl:text>
      <fo:leader leader-pattern-width="3pt"
                 leader-alignment="reference-area"
                 keep-with-next.within-line="always">
         <xsl:choose>
           <xsl:when test="$part = 1">
             <xsl:attribute name="leader-pattern">space</xsl:attribute>
           </xsl:when>
           <xsl:otherwise>
            <xsl:attribute name="leader-pattern">dots</xsl:attribute>
           </xsl:otherwise>
        </xsl:choose>
      </fo:leader>
      <xsl:text>  </xsl:text>
      <fo:basic-link internal-destination="{$id}">
        <fo:page-number-citation ref-id="{$id}"/>
      </fo:basic-link>
    </fo:inline>
  </fo:block>
</xsl:template>

S pozdravom
Pavol Vaskovic



Další informace o konferenci Docbook