Book title in bookmarks as first top level element

Here should go questions about transforming XML with XSLT and FOP.
josecotes
Posts: 19

Book title in bookmarks as first top level element

Wed Nov 18, 2015 6:52 pm

Hi there,

How do I add the book title (from a bookmap/ditamap) as the main first element in my bookmark?

This is how it looks like now:

Code: Select all

- Chapter 1
    - Content xxxx
    - Content xxxx
- Chapter 2
    - Content xxxx
    - Content xxxx
    - Content xxxx
- Chapter 3



This is what I am intending on achieving:

Code: Select all

Book title
    - Chapter 1
        - Content xxxx
        - Content xxxx
    - Chapter 2
        - Content xxxx
        - Content xxxx
        - Content xxxx
    - Chapter 3


Thanks for your help.
radu_pisoi
Posts: 302
Location: Craiova

Re: Book title in bookmarks as first top level element

Fri Nov 20, 2015 2:59 pm

Hi,

I assume that you want to change the bookmarks' structure for the DITA-OT PDF output.

DITA Open Toolkit PDF output can be customized in several ways:
* creating a DITA Open Toolkit plugin which adds extensions to the PDF plugin.
* creating a customization directory and using it from the PDF transformation scenario.

You can find more details in our user manual:
https://www.oxygenxml.com/doc/versions/ ... ation.html

For your request, you can follow the next procedure. This customization is based on the 'Custom directory' method. I've tested with DITA-OT 1.8.5.
* Copy the entire directory: DITA_OT_DIR\plugins\org.dita.pdf2\Customization to another location (for instance, C:\Customization).
* Rename C:\Customization\catalog.xml.orig to: C:\Customization\catalog.xml.
* Open the catalog.xml in Oxygen XML Editor and uncomment this line:

Code: Select all

  <uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/>   

* Rename C:\Customization\fo\xsl\custom.xsl.orig to: C:\Customization\fo\xsl\custom.xsl
* Modify the custom.xsl file by adding an import to bookmarks.xsl

Code: Select all

<xsl:import href="bookmarks.xsl"/>

* Create the bookmarks.xsl with the follow content:

Code: Select all

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:exsl="http://exslt.org/common"
                xmlns:opentopic="http://www.idiominc.com/opentopic"
                xmlns:opentopic-index="http://www.idiominc.com/opentopic/index"
                xmlns:exslf="http://exslt.org/functions"
                xmlns:opentopic-func="http://www.idiominc.com/opentopic/exsl/function"
                xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder"
                extension-element-prefixes="exsl"
                exclude-result-prefixes="opentopic-index opentopic exslf opentopic-func ot-placeholder"
                version="2.0">

    <xsl:template name="createBookmarks">
      <xsl:variable name="bookmarks" as="element()*">
        <xsl:choose>
          <xsl:when test="$retain-bookmap-order">
            <xsl:apply-templates select="/" mode="bookmark"/>
          </xsl:when>
          <xsl:otherwise>
           
            <!--
              start patch
              Generate the 'fo:bookmark' for the book title
            -->
            <fo:bookmark>
              <xsl:attribute name="internal-destination">
                <xsl:call-template name="generate-toc-id"/>
              </xsl:attribute>
             
              <xsl:variable name="bookmapTitle" select="//*[contains(@class, 'bookmap/mainbooktitle')]"/>
              <fo:bookmark-title>
                <xsl:value-of select="normalize-space($bookmapTitle)"/>
              </fo:bookmark-title>
             
              <!--
                end patch
              -->
              <xsl:for-each select="/*/*[contains(@class, ' topic/topic ')]">
                <xsl:variable name="topicType">
                  <xsl:call-template name="determineTopicType"/>
                </xsl:variable>
                <xsl:if test="$topicType = 'topicNotices'">
                  <xsl:apply-templates select="." mode="bookmark"/>
                </xsl:if>
              </xsl:for-each>
              <xsl:choose>
                <xsl:when test="($ditaVersion &gt;= 1.1) and $map//*[contains(@class,' bookmap/toc ')][@href]"/>
                <xsl:when test="($ditaVersion &gt;= 1.1) and ($map//*[contains(@class,' bookmap/toc ')]
                  or /*[contains(@class,' map/map ')][not(contains(@class,' bookmap/bookmap '))])">
                  <fo:bookmark internal-destination="{$id.toc}">
                    <fo:bookmark-title>
                      <xsl:call-template name="insertVariable">
                        <xsl:with-param name="theVariableID" select="'Table of Contents'"/>
                      </xsl:call-template>
                    </fo:bookmark-title>
                  </fo:bookmark>
                </xsl:when>
                <xsl:when test="$ditaVersion &gt;= 1.1"/>
                <xsl:otherwise>
                  <fo:bookmark internal-destination="{$id.toc}">
                    <fo:bookmark-title>
                      <xsl:call-template name="insertVariable">
                        <xsl:with-param name="theVariableID" select="'Table of Contents'"/>
                      </xsl:call-template>
                    </fo:bookmark-title>
                  </fo:bookmark>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:for-each select="/*/*[contains(@class, ' topic/topic ')] |
                /*/ot-placeholder:glossarylist |
                /*/ot-placeholder:tablelist |
                /*/ot-placeholder:figurelist">
                <xsl:variable name="topicType">
                  <xsl:call-template name="determineTopicType"/>
                </xsl:variable>
                <xsl:if test="not($topicType = 'topicNotices')">
                  <xsl:apply-templates select="." mode="bookmark"/>
                </xsl:if>
              </xsl:for-each>
              <xsl:if test="//opentopic-index:index.groups//opentopic-index:index.entry">
                <xsl:choose>
                  <xsl:when test="($ditaVersion &gt;= 1.1) and $map//*[contains(@class,' bookmap/indexlist ')][@href]"/>
                  <xsl:when test="($ditaVersion &gt;= 1.1) and ($map//*[contains(@class,' bookmap/indexlist ')]
                    or /*[contains(@class,' map/map ')][not(contains(@class,' bookmap/bookmap '))])">
                    <fo:bookmark internal-destination="{$id.index}">
                      <fo:bookmark-title>
                        <xsl:call-template name="insertVariable">
                          <xsl:with-param name="theVariableID" select="'Index'"/>
                        </xsl:call-template>
                      </fo:bookmark-title>
                    </fo:bookmark>
                  </xsl:when>
                  <xsl:when test="$ditaVersion &gt;= 1.1"/>
                  <xsl:otherwise>
                    <fo:bookmark internal-destination="{$id.index}">
                      <fo:bookmark-title>
                        <xsl:call-template name="insertVariable">
                          <xsl:with-param name="theVariableID" select="'Index'"/>
                        </xsl:call-template>
                      </fo:bookmark-title>
                    </fo:bookmark>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:if>
            </fo:bookmark>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:if test="exists($bookmarks)">
        <fo:bookmark-tree>
          <xsl:copy-of select="$bookmarks"/>
        </fo:bookmark-tree>
      </xsl:if>
    </xsl:template>   
</xsl:stylesheet>


The template was copied from:
DITA-OT/plugins/org.dita.pdf2/xsl/fo/bookmarks.xsl.

The modifications are marked with start patch and end patch comments.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
josecotes
Posts: 19

Re: Book title in bookmarks as first top level element

Sun Nov 22, 2015 11:55 pm

Thanks a lot! Worked like a charm.
cjhukill
Posts: 11

Re: Book title in bookmarks as first top level element

Wed Mar 30, 2016 11:02 pm

radu_pisoi wrote:Hi,

I assume that you want to change the bookmarks' structure for the DITA-OT PDF output.

DITA Open Toolkit PDF output can be customized in several ways:
* creating a DITA Open Toolkit plugin which adds extensions to the PDF plugin.
* creating a customization directory and using it from the PDF transformation scenario.

You can find more details in our user manual:
https://www.oxygenxml.com/doc/versions/ ... ation.html

For your request, you can follow the next procedure. This customization is based on the 'Custom directory' method. I've tested with DITA-OT 1.8.5.
* Copy the entire directory: DITA_OT_DIR\plugins\org.dita.pdf2\Customization to another location (for instance, C:\Customization).
* Rename C:\Customization\catalog.xml.orig to: C:\Customization\catalog.xml.
* Open the catalog.xml in Oxygen XML Editor and uncomment this line:

Code: Select all

  <uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/>   

* Rename C:\Customization\fo\xsl\custom.xsl.orig to: C:\Customization\fo\xsl\custom.xsl
* Modify the custom.xsl file by adding an import to bookmarks.xsl

Code: Select all

<xsl:import href="bookmarks.xsl"/>

* Create the bookmarks.xsl with the follow content:

Code: Select all

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:exsl="http://exslt.org/common"
                xmlns:opentopic="http://www.idiominc.com/opentopic"
                xmlns:opentopic-index="http://www.idiominc.com/opentopic/index"
                xmlns:exslf="http://exslt.org/functions"
                xmlns:opentopic-func="http://www.idiominc.com/opentopic/exsl/function"
                xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder"
                extension-element-prefixes="exsl"
                exclude-result-prefixes="opentopic-index opentopic exslf opentopic-func ot-placeholder"
                version="2.0">

    <xsl:template name="createBookmarks">
      <xsl:variable name="bookmarks" as="element()*">
        <xsl:choose>
          <xsl:when test="$retain-bookmap-order">
            <xsl:apply-templates select="/" mode="bookmark"/>
          </xsl:when>
          <xsl:otherwise>
           
            <!--
              start patch
              Generate the 'fo:bookmark' for the book title
            -->
            <fo:bookmark>
              <xsl:attribute name="internal-destination">
                <xsl:call-template name="generate-toc-id"/>
              </xsl:attribute>
             
              <xsl:variable name="bookmapTitle" select="//*[contains(@class, 'bookmap/mainbooktitle')]"/>
              <fo:bookmark-title>
                <xsl:value-of select="normalize-space($bookmapTitle)"/>
              </fo:bookmark-title>
             
              <!--
                end patch
              -->
              <xsl:for-each select="/*/*[contains(@class, ' topic/topic ')]">
                <xsl:variable name="topicType">
                  <xsl:call-template name="determineTopicType"/>
                </xsl:variable>
                <xsl:if test="$topicType = 'topicNotices'">
                  <xsl:apply-templates select="." mode="bookmark"/>
                </xsl:if>
              </xsl:for-each>
              <xsl:choose>
                <xsl:when test="($ditaVersion &gt;= 1.1) and $map//*[contains(@class,' bookmap/toc ')][@href]"/>
                <xsl:when test="($ditaVersion &gt;= 1.1) and ($map//*[contains(@class,' bookmap/toc ')]
                  or /*[contains(@class,' map/map ')][not(contains(@class,' bookmap/bookmap '))])">
                  <fo:bookmark internal-destination="{$id.toc}">
                    <fo:bookmark-title>
                      <xsl:call-template name="insertVariable">
                        <xsl:with-param name="theVariableID" select="'Table of Contents'"/>
                      </xsl:call-template>
                    </fo:bookmark-title>
                  </fo:bookmark>
                </xsl:when>
                <xsl:when test="$ditaVersion &gt;= 1.1"/>
                <xsl:otherwise>
                  <fo:bookmark internal-destination="{$id.toc}">
                    <fo:bookmark-title>
                      <xsl:call-template name="insertVariable">
                        <xsl:with-param name="theVariableID" select="'Table of Contents'"/>
                      </xsl:call-template>
                    </fo:bookmark-title>
                  </fo:bookmark>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:for-each select="/*/*[contains(@class, ' topic/topic ')] |
                /*/ot-placeholder:glossarylist |
                /*/ot-placeholder:tablelist |
                /*/ot-placeholder:figurelist">
                <xsl:variable name="topicType">
                  <xsl:call-template name="determineTopicType"/>
                </xsl:variable>
                <xsl:if test="not($topicType = 'topicNotices')">
                  <xsl:apply-templates select="." mode="bookmark"/>
                </xsl:if>
              </xsl:for-each>
              <xsl:if test="//opentopic-index:index.groups//opentopic-index:index.entry">
                <xsl:choose>
                  <xsl:when test="($ditaVersion &gt;= 1.1) and $map//*[contains(@class,' bookmap/indexlist ')][@href]"/>
                  <xsl:when test="($ditaVersion &gt;= 1.1) and ($map//*[contains(@class,' bookmap/indexlist ')]
                    or /*[contains(@class,' map/map ')][not(contains(@class,' bookmap/bookmap '))])">
                    <fo:bookmark internal-destination="{$id.index}">
                      <fo:bookmark-title>
                        <xsl:call-template name="insertVariable">
                          <xsl:with-param name="theVariableID" select="'Index'"/>
                        </xsl:call-template>
                      </fo:bookmark-title>
                    </fo:bookmark>
                  </xsl:when>
                  <xsl:when test="$ditaVersion &gt;= 1.1"/>
                  <xsl:otherwise>
                    <fo:bookmark internal-destination="{$id.index}">
                      <fo:bookmark-title>
                        <xsl:call-template name="insertVariable">
                          <xsl:with-param name="theVariableID" select="'Index'"/>
                        </xsl:call-template>
                      </fo:bookmark-title>
                    </fo:bookmark>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:if>
            </fo:bookmark>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:if test="exists($bookmarks)">
        <fo:bookmark-tree>
          <xsl:copy-of select="$bookmarks"/>
        </fo:bookmark-tree>
      </xsl:if>
    </xsl:template>   
</xsl:stylesheet>


The template was copied from:
DITA-OT/plugins/org.dita.pdf2/xsl/fo/bookmarks.xsl.

The modifications are marked with start patch and end patch comments.




I am using oXygen 14.2 and trying to resolve my issue of undefined 'fo:bookmark' and was reading this post. I tried the steps above, but was unable to get to the customization portion. Can you help me with that part?
radu_pisoi
Posts: 302
Location: Craiova

Re: Book title in bookmarks as first top level element

Thu Mar 31, 2016 11:06 am

Hi,

cjhukill wrote:
I am using oXygen 14.2 and trying to resolve my issue of undefined 'fo:bookmark' and was reading this post. I tried the steps above, but was unable to get to the customization portion. Can you help me with that part?


Unfortunately, oXygen 14.2 is in End Of Support state regarding to the End of Life (EOL) Policy Statement. The End of Support state means the technical support for that product version is no longer available.

However, I'm not sure if the PDF bookmarks customization described in this post is related with the problem that you described.

So, could you try to install the oXygen 17.1 with a trial license and check if your problem was fixed? If not, could you give us more details about your problem?
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
rahulhr1985
Posts: 3

Re: Book title in bookmarks as first top level element

Thu Sep 08, 2016 9:34 pm

How to make this book title from rendering right-to-left using writing-mode?
Radu
Posts: 5096

Re: Book title in bookmarks as first top level element

Fri Sep 09, 2016 8:56 am

Hi,

I'm sorry but I do not understand, could you provide more details, maybe a screenshot? Are you publishing to PDF using Arabic? Are you using Apache FOP for rendering the PDF (the default engine bundled with Oxygen) or a commercial PDF engine like XEP or Antenna House?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
rahulhr1985
Posts: 3

Re: Book title in bookmarks as first top level element

Fri Sep 09, 2016 10:32 am

Hi,

Thank you for the quick reply. I have Arabic language PDF. In bookmark except booktitle all other topic title are rendering right to left. I am not able to see any writing-mode variable in bookmark-custom.xsl. Could you please help how can i render booktitle from right to left in bookmark?


Thanks
Rahul
rahulhr1985
Posts: 3

Re: Book title in bookmarks as first top level element

Fri Sep 09, 2016 10:35 am

Hi,

I am using Antenna house

Thanks
Rahul
Radu
Posts: 5096

Re: Book title in bookmarks as first top level element

Fri Sep 09, 2016 11:33 am

Hi Rahul,

From what I tested with the default DITA OT PDF publishing the book title does not seem to appear at all in the Bookmarks view.
Are you publishing using the default PDF publishing or did you install the Antenna House special PDF publishing plugins?
https://www.antennahouse.com/antenna1/dita-pdf5-plugin/
Do you have a PDF XSLT customization which adds the book title to the bookmarks? If so, it might depend on what the customization does.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
rgmetap
Posts: 12
Location: Pune , India

Re: Book title in bookmarks as first top level element

Wed Mar 01, 2017 2:11 pm

Hi Sir,

I need to pick <title> from ditamap and want to show it in header of body pages only in pdf . How can I do that?

Code: Select all

<map title="INSTRUCTIONS">
 <title>WELCOME</title>
 <topicref href="Concepts/c_message.dita"/>


I want to pick WELCOME
Rohit Ghosh
Jr. Software Developer
Radu
Posts: 5096

Re: Book title in bookmarks as first top level element

Thu Mar 02, 2017 10:15 am

Hi,

You could probably try to create a PDF customization folder and override the template which customizes the header from the base XSLT stylesheet:

https://www.oxygenxml.com/doc/versions/18.1/ug-editor/topics/dita_pdf_header_footer_customization-x-predefined3.html

You can use an XPath to find the title of the current map.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
rgmetap
Posts: 12
Location: Pune , India

Re: Book title in bookmarks as first top level element

Tue Mar 07, 2017 9:45 am

Hi Sir,

I need to pick the title value from front-matter by using xsl:marker and retrieve marker . I am unable to use it. Can you show some example for marker picking values ?
Rohit Ghosh
Jr. Software Developer
Radu
Posts: 5096

Re: Book title in bookmarks as first top level element

Tue Mar 07, 2017 10:06 am

Hi,

Maybe you should register and ask around on the Yahoo Groups DITA Users List.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 0 guests