#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Help: Facing problem in setting pdf bookmark using XSL


    Hello,

    I am facing a problem in the arrangement of Bookmarks in the output PDF transformed from XML(input)+XSL.

    Level 1 Heading (<heading>) and Level 2 Heading (<heading1>) are defined in XSL in the following manner:

    -----------------------------------------------------------
    <xsl:template match="heading" mode="first">
    <fo:block border="0.5pt solid blue" id="{generate-id(.)}" font-weight="bold" display-align="center" text-align="center" color="white" background-color="rgb(0,0,255)" break-before="page">
    <!-- xsl:apply-templates/-->


    <xsl:number level="any" from="datasheet" count="heading"/>
    <xsl:text>. </xsl:text>

    <fo:marker marker-class-name="heading">
    <xsl:value-of select="."/>
    </fo:marker>
    <xsl:apply-templates/>
    </fo:block>
    <fo:block color="white">break</fo:block>
    </xsl:template>
    -----------------------------------------------------------
    <xsl:template match="heading1" mode="first">
    <fo:block border="0.5pt solid blue" id="{generate-id(.)}" font-weight="bold" display-align="center" text-align="center" color="white" background-color="rgb(0,0,255)" break-before="page">
    <!-- xsl:apply-templates/-->


    <xsl:number level="any" from="datasheet" count="heading"/>
    <xsl:text>. </xsl:text>

    <fo:marker marker-class-name="heading">
    <xsl:value-of select="."/>
    </fo:marker>
    <xsl:apply-templates/>
    </fo:block>
    <fo:block color="white">break</fo:block>
    </xsl:template>
    -----------------------------------------------------------
    The bookmark tree has been defined in the following way:

    <!-- PDF bookmark tree starts -->
    <fo:bookmark-tree>
    <fo:bookmark internal-destination="top">
    <fo:bookmark-title>
    <xsl:value-of select="@cutname"/>
    </fo:bookmark-title>

    <xsl:for-each select="//section/heading">
    <fo:bookmark internal-destination="{generate-id(.)}">
    <fo:bookmark-title>
    <xsl:value-of select="heading"/>
    <xsl:apply-templates mode="first"/>
    </fo:bookmark-title>

    <xsl:for-each select="//section/heading1"> <fo:bookmark internal-destination="{generate-id(.)}">
    <fo:bookmark-title>
    <xsl:value-of select="heading1"/>
    <xsl:apply-templates mode="first"/>
    </fo:bookmark-title>
    </fo:bookmark>


    </xsl:for-each>

    </fo:bookmark>
    <xsl:apply-templates mode="first"/>

    </xsl:for-each>
    </fo:bookmark>

    </fo:bookmark-tree>

    <!-- PDF bookmark tree ends -->
    ------------------------------------------------------------

    The output obtained in the PDF bookmarks region is:

    Level1 Heading
    Level1 Heading
    Level1 Heading
    Level1 Heading
    (+)Level1 Heading
    Level2Heading
    Level2Heading
    Level2Heading
    Level2Heading
    Level2Heading


    The above output is not heirarchial. The desired output should be according to the occurence of the tags <heading> (Level1 Heading) and <heading1> (Level2 Heading) in the XML code.

    XML code skeleton:
    ----------------------------------------------------------
    <section>
    <heading>blah</heading>
    <heading1>blah</heading1>
    <heading1>blah</heading1>
    </section>

    <section>
    <heading>blah</heading>
    </section>

    <section>
    <heading>blah</heading>
    </section>

    <section>
    <heading>blah</heading>
    <heading1>blah</heading1>
    <heading1>blah</heading1>
    <heading1>blah</heading1>
    </section>
    ------------------------------------------------------------
    The desired Bookmark output for the above XML skeleton should be the following:


    (+)Level1 Heading
    Level2Heading
    Level2Heading
    Level1 Heading
    Level1 Heading
    (+)Level1 Heading
    Level2Heading
    Level2Heading
    Level2Heading


    Please suggest the modifications required in the XSL code.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,069
    Rep Power
    9398
    You need a for-each on the sections with inner loops on any heading or heading1 (or heading before heading1 if you know they will always be in that order).
    Compared to what you have right now which for-eaches on every heading and then every heading1 in the document.

IMN logo majestic logo threadwatch logo seochat tools logo