Loading ...
Sorry, an error occurred while loading the content.

Numbered Headings in PDF

Expand Messages
  • Roger
    Dear DITA Users, The list archives contain several old threads[*] on various approaches for numbered headings in PDF output, but most of the suggestions are
    Message 1 of 4 , Apr 19 9:31 AM
    View Source
    • 0 Attachment
      Dear DITA Users,

      The list archives contain several old threads[*] on various approaches for
      numbered headings in PDF output, but most of the suggestions are several
      years old, so I'm not sure whether they work in the current toolkit version.

      Is there any consensus on the best way to achieve the following numbering
      scheme using DITA OT v1.5.4 and XEP?

      Chapter 1
      1.1 Topic Title
      1.2 Topic Title
      1.3 Topic Title
      Chapter 2
      2.1 Topic Title
      2.2 Topic Title
      2.3 Topic Title
      2.3.1 Topic Title
      2.3.1.1, etc.

      The old threads are a bit vague as to exactly which files must be modified
      or where the custom templates should be located. Any more specifics you can
      provide would be greatly appreciated.

      Thanks,

      Roger


      ---

      * http://tech.groups.yahoo.com/group/dita-users/message/3373 ... 23433
      * http://tech.groups.yahoo.com/group/dita-users/message/4751
    • Eliot Kimber
      I m looking at the 1.5.6 code, but it s likely the same in 1.5.4. The key template seems to be:
      Message 2 of 4 , Apr 19 11:29 AM
      View Source
      • 0 Attachment
        I'm looking at the 1.5.6 code, but it's likely the same in 1.5.4.

        The key template seems to be:

        <xsl:template name="getTitle"><!-- get fully-processed title content by
        whatever mechanism -->
        <xsl:apply-templates select="." mode="getTitle"/>
        </xsl:template>
        <xsl:template match="*" mode="getTitle">
        <xsl:choose>
        <!-- add keycol here once implemented-->
        <xsl:when test="@spectitle">
        <xsl:value-of select="@spectitle"/>
        </xsl:when>
        <xsl:otherwise>
        <xsl:apply-templates/>
        </xsl:otherwise>
        </xsl:choose>
        </xsl:template>


        From commons.xsl.

        You get to this template for all topic titles.

        So this would be the place to add generation of the topic number.

        To generate accurate numbers you'd want to use the map structure, which
        you're not actually in in this context.

        In this context, you're processing the merged topics, which is a flat list
        of topics with no publication-part distinction (frontmatter, body,
        backmatter, etc.).

        So, for example, to number the body sections but not the frontmatter
        sections, you have to use the map structure, assuming the map you're using
        provides the distinction, as it does in bookmaps and D4P publication maps.

        In this template you're processing the title of a topic. To get the map you
        need the topic's ID, which you can then use to find the corresponding
        topicref in the map, which is also included in the merged document.

        This would be something like this:


        <xsl:variable name="topicId" as="xs:string?"
        select="ancestor::*[contains(@class, ' topic/topic ')][1]/@id"
        />
        <xsl:variable name="topicref" as="element()*"
        select="$map//*[@id = $topicId]"
        />
        <xsl:variable name="topicNumber" as="xs:string">
        <xsl:choose>
        <xsl:when test="$topicref[1]/ancestor-or-self::[contains(@class, '
        bookmap/frontmatter]">
        <xsl:sequence select="''"/>
        </xsl:when>
        <xsl:when test="$topicref[1]/ancestor-or-self::[contains(@class, '
        bookmap/backmatter]">
        <xsl:sequence select="''"/>
        </xsl:when>
        <xsl:otherwise>
        <xsl:number count="$topicref[1]"
        level="multiple"
        format="1.1."
        />
        </xsl:otherwise>
        </xsl:choose>


        I haven't tested this so there's probably some detail I've overlooked.

        Note that the @as values for $topicId and $topicref use "?" and "*"
        respectively. That allows those values to be empty and, for $topicref,
        allows there to be multiple in case there's some bug in the merge process
        that results in multiple topicrefs with the same ID (shouldn't happen but
        you don't want your code to blow up in that case).

        It's unfortunate that Bookmap doesn't provide a <body> topicref parallel to
        <frontmatter> and <backmatter>, as that would make this numbering task
        easier in that you wouldn't need to explicitly test for the case of
        frontmatter or backmatter in order to not do the numbering, but would just
        be able to select the <body> branch in the map tree and go.

        [Looking over this again, I just realized this only works if all the topics
        have topicrefs, which is a typical case but isn't always the case. So a
        complete solution needs to use the map to determine whether or not numbering
        should happen and what the specific pattern is, and then use the merged
        topic structure to do the actual numbering, as that will correctly reflect
        the topic hierarchy.]

        Cheers,

        Eliot

        On 4/19/12 11:31 AM, "Roger" <infotexture@...> wrote:

        > Dear DITA Users,
        >
        > The list archives contain several old threads[*] on various approaches for
        > numbered headings in PDF output, but most of the suggestions are several
        > years old, so I'm not sure whether they work in the current toolkit version.
        >
        > Is there any consensus on the best way to achieve the following numbering
        > scheme using DITA OT v1.5.4 and XEP?
        >
        > Chapter 1
        > 1.1 Topic Title
        > 1.2 Topic Title
        > 1.3 Topic Title
        > Chapter 2
        > 2.1 Topic Title
        > 2.2 Topic Title
        > 2.3 Topic Title
        > 2.3.1 Topic Title
        > 2.3.1.1, etc.
        >
        > The old threads are a bit vague as to exactly which files must be modified
        > or where the custom templates should be located. Any more specifics you can
        > provide would be greatly appreciated.
        >
        > Thanks,
        >
        > Roger
        >
        > ---
        >
        > * http://tech.groups.yahoo.com/group/dita-users/message/3373 ... 23433
        > * http://tech.groups.yahoo.com/group/dita-users/message/4751
        >
        >
        >

        --
        Eliot Kimber
        Senior Solutions Architect, RSI Content Solutions
        "Bringing Strategy, Content, and Technology Together"
        Main: 512.554.9368
        www.rsicms.com
        www.rsuitecms.com
      • Mica Semrick
        Just saw this the other day on the list, but if you re not into editing XSLT files, http://dita-generator.appspot.com/ will generate you a new plugin to do,
        Message 3 of 4 , Apr 19 11:52 AM
        View Source
        • 0 Attachment
          Just saw this the other day on the list, but if you're not into editing XSLT files, http://dita-generator.appspot.com/ will generate you a new plugin to do, among other things, number chaper/sections.


          --
          Mica Semrick
           
          Technical Writer | Systems Engineer
          iCRco - The Innovative CR Company 
          P) 310-921-9559 x226 
          F) 310-542-7236 
          msemrick@... 
          http://www.icrcompany.com 
          --
          This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

        • Roger Sheen
          ... Thanks to Eliot and Mica for pointing me in the right direction, and to Jarno for his excellent plugin generator. I used that to create a new PDF style
          Message 4 of 4 , Apr 23 3:13 PM
          View Source
          • 0 Attachment
            On 2012-04-19 20:29, Eliot Kimber wrote:
            > I'm looking at the 1.5.6 code, but it's likely the same in 1.5.4.
            > The key template seems to be [...] <xsl:template name="getTitle"> [...]
            > From commons.xsl. You get to this template for all topic titles.
            > So this would be the place to add generation of the topic number.

            On 2012-04-19 20:52, Mica Semrick wrote:
            > If you're not into editing XSLT files, <http://dita-generator.appspot.com>
            > will generate you a new plugin to do, among other things, number
            > chaper/sections.


            Thanks to Eliot and Mica for pointing me in the right direction, and to
            Jarno for his excellent plugin generator.

            I used that to create a new PDF style plug-in and set the "Title numbering"
            option to "All levels". The resulting plugin code includes an override for
            the "getTitle" template in `/cfg/fo/xsl/custom.xsl`, which works well.

            To get the gist of it, see <https://gist.github.com/2473924>.

            As others have pointed out, the plugin generator indeed serves as an
            excellent starting point for PDF customizations--thanks again to Jarno!

            Regards,

            Roger
          Your message has been successfully submitted and would be delivered to recipients shortly.