Imported Upstream version 1.77.1
[platform/upstream/docbook-xsl.git] / fo / xep.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
4                 xmlns:rx="http://www.renderx.com/XSL/Extensions"
5                 version='1.0'>
6
7 <!-- ********************************************************************
8      $Id: xep.xsl 9293 2012-04-19 18:42:11Z bobstayton $
9      ********************************************************************
10      (c) Stephane Bline Peregrine Systems 2001
11      Implementation of xep extensions:
12        * Pdf bookmarks (based on the XEP 2.5 implementation)
13        * Document information (XEP 2.5 meta information extensions)
14      ******************************************************************** -->
15
16 <!-- FIXME: Norm, I changed things so that the top-level element (book or set)
17      does not appear in the TOC. Is this the right thing? -->
18
19 <xsl:template name="xep-document-information">
20   <rx:meta-info>
21     <xsl:variable name="authors" 
22                   select="(//author|//editor|//corpauthor|//authorgroup)[1]"/>
23     <xsl:if test="$authors">
24       <xsl:variable name="author">
25         <xsl:choose>
26           <xsl:when test="$authors[self::authorgroup]">
27             <xsl:call-template name="person.name.list">
28               <xsl:with-param name="person.list" 
29                         select="$authors/*[self::author|self::corpauthor|
30                                self::othercredit|self::editor]"/>
31             </xsl:call-template>
32           </xsl:when>
33           <xsl:when test="$authors[self::corpauthor]">
34             <xsl:value-of select="$authors"/>
35           </xsl:when>
36           <xsl:when test="$authors[orgname]">
37             <xsl:value-of select="$authors/orgname"/>
38           </xsl:when>
39           <xsl:otherwise>
40             <xsl:call-template name="person.name">
41               <xsl:with-param name="node" select="$authors"/>
42             </xsl:call-template>
43           </xsl:otherwise>
44         </xsl:choose>
45       </xsl:variable>
46       <xsl:element name="rx:meta-field">
47         <xsl:attribute name="name">author</xsl:attribute>
48         <xsl:attribute name="value">
49           <xsl:value-of select="normalize-space($author)"/>
50         </xsl:attribute>
51       </xsl:element>
52     </xsl:if>
53
54     <xsl:variable name="title">
55       <xsl:apply-templates select="/*[1]" mode="label.markup"/>
56       <xsl:apply-templates select="/*[1]" mode="title.markup"/>
57     </xsl:variable>
58
59     <xsl:element name="rx:meta-field">
60       <xsl:attribute name="name">creator</xsl:attribute>
61       <xsl:attribute name="value">
62         <xsl:text>DocBook </xsl:text>
63         <xsl:value-of select="$DistroTitle"/>
64         <xsl:text> V</xsl:text>
65         <xsl:value-of select="$VERSION"/>
66       </xsl:attribute>
67     </xsl:element>
68
69     <xsl:element name="rx:meta-field">
70       <xsl:attribute name="name">title</xsl:attribute>
71       <xsl:attribute name="value">
72         <xsl:value-of select="normalize-space($title)"/>
73       </xsl:attribute>
74     </xsl:element>
75
76     <xsl:if test="//keyword">
77       <xsl:element name="rx:meta-field">
78         <xsl:attribute name="name">keywords</xsl:attribute>
79         <xsl:attribute name="value">
80           <xsl:for-each select="//keyword">
81             <xsl:value-of select="normalize-space(.)"/>
82             <xsl:if test="position() != last()">
83               <xsl:text>, </xsl:text>
84             </xsl:if>
85           </xsl:for-each>
86         </xsl:attribute>
87       </xsl:element>
88     </xsl:if>
89
90     <xsl:if test="//subjectterm">
91       <xsl:element name="rx:meta-field">
92         <xsl:attribute name="name">subject</xsl:attribute>
93         <xsl:attribute name="value">
94           <xsl:for-each select="//subjectterm">
95             <xsl:value-of select="normalize-space(.)"/>
96             <xsl:if test="position() != last()">
97               <xsl:text>, </xsl:text>
98             </xsl:if>
99           </xsl:for-each>
100         </xsl:attribute>
101       </xsl:element>
102     </xsl:if>
103   </rx:meta-info>
104 </xsl:template>
105
106 <!-- ********************************************************************
107      Pdf bookmarks
108      ******************************************************************** -->
109
110 <xsl:template match="*" mode="xep.outline">
111   <xsl:apply-templates select="*" mode="xep.outline"/>
112 </xsl:template>
113
114 <xsl:template match="set|book|part|reference|preface|chapter|appendix|article
115                      |glossary|bibliography|index|setindex|topic
116                      |refentry|refsynopsisdiv
117                      |refsect1|refsect2|refsect3|refsection
118                      |sect1|sect2|sect3|sect4|sect5|section"
119               mode="xep.outline">
120   <xsl:variable name="id">
121     <xsl:call-template name="object.id"/>
122   </xsl:variable>
123   <xsl:variable name="bookmark-label">
124     <xsl:apply-templates select="." mode="object.title.markup"/>
125   </xsl:variable>
126
127   <!-- Put the root element bookmark at the same level as its children -->
128   <!-- If the object is a set or book, generate a bookmark for the toc -->
129   <xsl:choose>
130     <xsl:when test="self::index and $generate.index = 0"/>      
131     <xsl:when test="parent::*">
132       <rx:bookmark internal-destination="{$id}">
133         <rx:bookmark-label>
134           <xsl:value-of select="normalize-space($bookmark-label)"/>
135         </rx:bookmark-label>
136         <xsl:apply-templates select="*" mode="xep.outline"/>
137       </rx:bookmark>
138     </xsl:when>
139     <xsl:otherwise>
140       <xsl:if test="$bookmark-label != ''">
141         <rx:bookmark internal-destination="{$id}">
142           <rx:bookmark-label>
143             <xsl:value-of select="normalize-space($bookmark-label)"/>
144           </rx:bookmark-label>
145         </rx:bookmark>
146       </xsl:if>
147
148       <xsl:variable name="toc.params">
149         <xsl:call-template name="find.path.params">
150           <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
151         </xsl:call-template>
152       </xsl:variable>
153       <xsl:if test="contains($toc.params, 'toc')
154                     and set|book|part|reference|section|sect1|refentry
155                         |article|topic|bibliography|glossary|chapter
156                         |appendix">
157         <rx:bookmark internal-destination="toc...{$id}">
158           <rx:bookmark-label>
159             <xsl:call-template name="gentext">
160               <xsl:with-param name="key" select="'TableofContents'"/>
161             </xsl:call-template>
162           </rx:bookmark-label>
163         </rx:bookmark>
164       </xsl:if>
165       <xsl:apply-templates select="*" mode="xep.outline"/>
166     </xsl:otherwise>
167   </xsl:choose>
168 </xsl:template>
169
170 <xsl:template name="xep-pis">
171   <xsl:if test="$crop.marks != 0">
172     <xsl:processing-instruction name="xep-pdf-crop-mark-width"><xsl:value-of select="$crop.mark.width"/></xsl:processing-instruction>
173     <xsl:processing-instruction name="xep-pdf-crop-offset"><xsl:value-of select="$crop.mark.offset"/></xsl:processing-instruction>
174     <xsl:processing-instruction name="xep-pdf-bleed"><xsl:value-of select="$crop.mark.bleed"/></xsl:processing-instruction>
175   </xsl:if>
176
177   <xsl:call-template name="user-xep-pis"/>
178 </xsl:template>
179
180 <!-- Placeholder for user defined PIs -->
181 <xsl:template name="user-xep-pis"/>
182
183 </xsl:stylesheet>