fop.xsl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?xml version='1.0' encoding="utf-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4. xmlns:fox="http://xml.apache.org/fop/extensions"
  5. version='1.0'>
  6. <!-- ********************************************************************
  7. $Id: fop.xsl 7531 2007-10-17 18:06:49Z dcramer $
  8. ********************************************************************
  9. (c) Stephane Bline Peregrine Systems 2001
  10. Driver file to allow pdf bookmarking (based on fop implementation).
  11. ******************************************************************** -->
  12. <!--
  13. In PDF bookmarks can't be used characters with code>255. This version of file
  14. translates characters with code>255 back to ASCII.
  15. Pavel Zampach (zampach@volny.cz)
  16. -->
  17. <xsl:variable name="a-dia" select=
  18. "'&#257;&#259;&#261;&#263;&#265;&#267;&#269;&#271;&#273;&#275;&#277;&#279;&#281;&#283;&#339;&#285;&#287;&#289;&#291;&#293;&#295;&#297;&#299;&#301;&#303;&#305;&#309;&#311;&#314;&#316;&#318;&#320;&#322;&#324;&#326;&#328;&#331;&#333;&#335;&#337;&#341;&#343;&#345;&#347;&#349;&#351;&#353;&#355;&#357;&#359;&#361;&#363;&#365;&#367;&#369;&#371;&#373;&#375;&#378;&#380;&#382;&#256;&#258;&#260;&#262;&#264;&#266;&#268;&#270;&#272;&#274;&#276;&#278;&#280;&#282;&#338;&#284;&#286;&#288;&#290;&#292;&#294;&#296;&#298;&#300;&#302;&#304;&#308;&#310;&#313;&#315;&#317;&#319;&#321;&#323;&#325;&#327;&#330;&#332;&#334;&#336;&#340;&#342;&#344;&#346;&#348;&#350;&#352;&#354;&#356;&#358;&#360;&#362;&#364;&#366;&#368;&#370;&#372;&#374;&#376;&#377;&#379;&#381;'"/>
  19. <xsl:variable name="a-asc" select=
  20. "'aaaccccddeeeeeegggghhiiiiijklllllnnnnooorrrsssstttuuuuuuwyzzzAAACCCCDDEEEEEEGGGGHHIIIIIJKLLLLLNNNNOOORRRSSSSTTTUUUUUUWYYZZZ'"/>
  21. <xsl:template match="*" mode="fop.outline">
  22. <xsl:variable name="id">
  23. <xsl:value-of select="(@id|@xml:id)[1]"/>
  24. </xsl:variable>
  25. <xsl:if test="$id != ''">
  26. <fox:destination internal-destination="{$id}"/>
  27. </xsl:if>
  28. <xsl:apply-templates select="*" mode="fop.outline"/>
  29. </xsl:template>
  30. <xsl:template match="set|book|part|reference|preface|chapter|appendix|article
  31. |glossary|bibliography|index|setindex
  32. |refentry
  33. |sect1|sect2|sect3|sect4|sect5|section"
  34. mode="fop.outline">
  35. <xsl:variable name="id">
  36. <xsl:call-template name="object.id"/>
  37. </xsl:variable>
  38. <xsl:variable name="bookmark-label">
  39. <xsl:apply-templates select="." mode="object.title.markup"/>
  40. </xsl:variable>
  41. <!-- Put the root element bookmark at the same level as its children -->
  42. <!-- If the object is a set or book, generate a bookmark for the toc -->
  43. <xsl:choose>
  44. <xsl:when test="self::index and $generate.index = 0"/>
  45. <xsl:when test="parent::*">
  46. <fox:outline internal-destination="{$id}">
  47. <fox:label>
  48. <xsl:value-of select="normalize-space(translate($bookmark-label, $a-dia, $a-asc))"/>
  49. </fox:label>
  50. <xsl:apply-templates select="*" mode="fop.outline"/>
  51. </fox:outline>
  52. </xsl:when>
  53. <xsl:otherwise>
  54. <fox:outline internal-destination="{$id}">
  55. <fox:label>
  56. <xsl:value-of select="normalize-space(translate($bookmark-label, $a-dia, $a-asc))"/>
  57. </fox:label>
  58. </fox:outline>
  59. <xsl:variable name="toc.params">
  60. <xsl:call-template name="find.path.params">
  61. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  62. </xsl:call-template>
  63. </xsl:variable>
  64. <xsl:if test="contains($toc.params, 'toc')
  65. and (book|part|reference|preface|chapter|appendix|article
  66. |glossary|bibliography|index|setindex
  67. |refentry
  68. |sect1|sect2|sect3|sect4|sect5|section)">
  69. <fox:outline internal-destination="toc...{$id}">
  70. <fox:label>
  71. <xsl:call-template name="gentext">
  72. <xsl:with-param name="key" select="'TableofContents'"/>
  73. </xsl:call-template>
  74. </fox:label>
  75. </fox:outline>
  76. </xsl:if>
  77. <xsl:apply-templates select="*" mode="fop.outline"/>
  78. </xsl:otherwise>
  79. </xsl:choose>
  80. <fox:destination internal-destination="{$id}"/>
  81. </xsl:template>
  82. </xsl:stylesheet>