xml - Creating dynamic bookmarks -


i have xml chapters can @ level in xml:

<?xml>   <chapter>     <long-name>chapter 1</long-name> <!-- 1-->     <chapter>       <long-name>chapter a</long-name> <!-- 1.1 -->        <chapter>          <long-name>chapter b</long-name> <!-- 1.1.1 -->        </chapter>     </chapter>     <chapter>          <long-name>chapter c</long-name> <!-- 1.2-->     </chapter>   </chapter>   <chapter>          <long-name>chapter 2</long-name> <!-- 2 -->          <chapter>             <long-name>chapter d</long-name> <!-- 2.1-->          </chapter>          <chapter>             <long-name>chapter e</long-name> <!-- 2.2-->          </chapter>   </chapter> </xml>  1. chapter 1    1.1 chapter      1.1.1 chapter b    1.2 chapter c    2.chapter 2     2.1 chapter d     2.2 chapter e 

i want create bookmark tree in pdf output. cannot working below code.

<fo:bookmark-tree>             <fo:bookmark internal-destination="toc"                 starting-state="show">                 <fo:bookmark-title> details </fo:bookmark-title>                 <xsl:for-each select="//chapter">                     <fo:bookmark internal-destination="chapter/long-name"                         starting-state="show">                         <fo:bookmark-title>                             <xsl:number format="1.1" count="chapter" level="multiple" />                             <xsl:value-of select="long-name" />                                                      </fo:bookmark-title>                     </fo:bookmark>                 </xsl:for-each>             </fo:bookmark>          </fo:bookmark-tree> 

with above xslt, chapters getting created under 'details' node @ same level.

required xslt output:

<fo:bookmark internal-destination="chapter/long-name" starting-state="show">      <fo:bookmark-title>1 chapter 1</fo:bookmark-title>          <fo:bookmark internal-destination="chapter/long-name" starting-state="show">             <fo:bookmark-title>1.1 chapter a</fo:bookmark-title>                  <fo:bookmark internal-destination="chapter/long-name" starting-state="show">                     <fo:bookmark-title>1.1.1 chapter b</fo:bookmark-title>                 </fo:bookmark>          </fo:bookmark>         <fo:bookmark internal-destination="chapter/long-name" starting-state="show">             <fo:bookmark-title>1.2 chapter c</fo:bookmark-title>         </fo:bookmark>     </fo:bookmark>         <fo:bookmark internal-destination="chapter/long-name" starting-state="show">      <fo:bookmark-title>2 chapter 2</fo:bookmark-title>       <fo:bookmark internal-destination="chapter/long-name" starting-state="show">         <fo:bookmark-title>2.1 chapter d</fo:bookmark-title>     </fo:bookmark>      <fo:bookmark internal-destination="chapter/long-name" starting-state="show">         <fo:bookmark-title>2.2 chapter e</fo:bookmark-title>     </fo:bookmark>   </fo:bookmark> 

please help.

you should delete count="chapter" in xsl:number. try stylesheet

<xsl:stylesheet version="1.0"      xmlns:xsl="http://www.w3.org/1999/xsl/transform"     xmlns:fo="http://www.w3.org/1999/xsl/format">     <xsl:output indent="yes"/>     <xsl:strip-space elements="*"/>   <xsl:template match="/">     <fo:bookmark-tree>         <fo:bookmark internal-destination="toc"             starting-state="show">             <xsl:apply-templates select="xml/chapter"/>         </fo:bookmark>     </fo:bookmark-tree> </xsl:template>  <xsl:template match="chapter">     <fo:bookmark internal-destination="chapter/long-name"         starting-state="show">         <fo:bookmark-title>             <xsl:number format="1.1 " level="multiple" />             <xsl:value-of select="long-name" />                                      </fo:bookmark-title>         <xsl:apply-templates/>     </fo:bookmark> </xsl:template>  <xsl:template match="long-name"/>  </xsl:stylesheet> 

it outputs:

<?xml version="1.0" encoding="utf-8"?> <fo:bookmark-tree xmlns:fo="http://www.w3.org/1999/xsl/format">    <fo:bookmark internal-destination="toc" starting-state="show">       <fo:bookmark internal-destination="chapter/long-name" starting-state="show">          <fo:bookmark-title>1 chapter 1</fo:bookmark-title>          <fo:bookmark internal-destination="chapter/long-name" starting-state="show">             <fo:bookmark-title>1.1 chapter a</fo:bookmark-title>             <fo:bookmark internal-destination="chapter/long-name" starting-state="show">                <fo:bookmark-title>1.1.1 chapter b</fo:bookmark-title>             </fo:bookmark>          </fo:bookmark>          <fo:bookmark internal-destination="chapter/long-name" starting-state="show">             <fo:bookmark-title>1.2 chapter c</fo:bookmark-title>          </fo:bookmark>       </fo:bookmark>       <fo:bookmark internal-destination="chapter/long-name" starting-state="show">          <fo:bookmark-title>2 chapter 2</fo:bookmark-title>          <fo:bookmark internal-destination="chapter/long-name" starting-state="show">             <fo:bookmark-title>2.1 chapter d</fo:bookmark-title>          </fo:bookmark>          <fo:bookmark internal-destination="chapter/long-name" starting-state="show">             <fo:bookmark-title>2.2 chapter e</fo:bookmark-title>          </fo:bookmark>       </fo:bookmark>    </fo:bookmark> </fo:bookmark-tree> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -