Imported Upstream version 1.79.2
[platform/upstream/docbook-xsl-stylesheets.git] / fo / fop1.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet exclude-result-prefixes="d"
3                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4                 xmlns:d="http://docbook.org/ns/docbook"
5                 xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
6                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
7                 version='1.0'>
8
9 <!-- ********************************************************************
10
11      This file is part of the XSL DocBook Stylesheet distribution.
12      See ../README or http://cdn.docbook.org/release/xsl/current/ for
13      copyright and other information.
14
15      ******************************************************************** -->
16
17
18 <!-- ==================================================================== -->
19
20 <xsl:template match="*" mode="fop1.outline">
21   <xsl:apply-templates select="*" mode="fop1.outline"/>
22 </xsl:template>
23
24 <xsl:template match="d:set|d:book|d:part|d:reference|
25                      d:preface|d:chapter|d:appendix|d:article|d:topic
26                      |d:glossary|d:bibliography|d:index|d:setindex
27                      |d:refentry|d:refsynopsisdiv
28                      |d:refsect1|d:refsect2|d:refsect3|d:refsection
29                      |d:sect1|d:sect2|d:sect3|d:sect4|d:sect5|d:section"
30               mode="fop1.outline">
31
32   <xsl:variable name="id">
33     <xsl:call-template name="object.id"/>
34   </xsl:variable>
35   <xsl:variable name="bookmark-label">
36     <xsl:apply-templates select="." mode="object.title.markup"/>
37   </xsl:variable>
38
39   <!-- Put the root element bookmark at the same level as its children -->
40   <!-- If the object is a set or book, generate a bookmark for the toc -->
41
42   <xsl:choose>
43     <xsl:when test="self::d:index and $generate.index = 0"/>
44     <xsl:when test="parent::*">
45       <fo:bookmark internal-destination="{$id}">
46         <xsl:attribute name="starting-state">
47           <xsl:value-of select="$bookmarks.state"/>
48         </xsl:attribute>
49         <fo:bookmark-title>
50           <xsl:value-of select="normalize-space($bookmark-label)"/>
51         </fo:bookmark-title>
52         <xsl:apply-templates select="*" mode="fop1.outline"/>
53       </fo:bookmark>
54     </xsl:when>
55     <xsl:otherwise>
56       <fo:bookmark internal-destination="{$id}">
57         <xsl:attribute name="starting-state">
58           <xsl:value-of select="$bookmarks.state"/>
59         </xsl:attribute>
60         <fo:bookmark-title>
61           <xsl:value-of select="normalize-space($bookmark-label)"/>
62         </fo:bookmark-title>
63       </fo:bookmark>
64
65       <xsl:variable name="toc.params">
66         <xsl:call-template name="find.path.params">
67           <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
68         </xsl:call-template>
69       </xsl:variable>
70
71       <xsl:if test="contains($toc.params, 'toc')
72                     and (d:book|d:part|d:reference|d:preface|d:chapter|d:appendix|d:article|d:topic
73                          |d:glossary|d:bibliography|d:index|d:setindex
74                          |d:refentry|d:refsynopsisdiv
75                          |d:refsect1|d:refsect2|d:refsect3|d:refsection
76                          |d:sect1|d:sect2|d:sect3|d:sect4|d:sect5|d:section)">
77         <fo:bookmark internal-destination="toc...{$id}">
78           <fo:bookmark-title>
79             <xsl:call-template name="gentext">
80               <xsl:with-param name="key" select="'TableofContents'"/>
81             </xsl:call-template>
82           </fo:bookmark-title>
83         </fo:bookmark>
84       </xsl:if>
85       <xsl:apply-templates select="*" mode="fop1.outline"/>
86     </xsl:otherwise>
87   </xsl:choose>
88 <!--
89   <fo:bookmark internal-destination="{$id}"/>
90 -->
91 </xsl:template>
92
93 <xsl:template match="*" mode="fop1.foxdest">
94   <xsl:variable name="id">
95     <xsl:value-of select="(@id|@xml:id)[1]"/>
96   </xsl:variable>
97   <xsl:choose>
98     <xsl:when test="self::d:index and $generate.index = 0"/>
99     <!-- ID on the footnote is not passed to the output FO -->
100     <xsl:when test="not(self::d:footnote) and $id != ''">
101       <fox:destination internal-destination="{$id}"/>
102       <xsl:apply-templates select="*" mode="fop1.foxdest"/>
103     </xsl:when>
104     <xsl:otherwise>
105       <xsl:apply-templates select="*" mode="fop1.foxdest"/>
106     </xsl:otherwise>
107   </xsl:choose>
108 </xsl:template>
109
110 <!-- Metadata support ("Document Properties" in Adobe Reader) -->
111 <xsl:template name="fop1-document-information">
112   <xsl:variable name="authors" select="(//d:author|//d:editor|//d:corpauthor|//d:authorgroup)[1]"/>
113
114   <xsl:variable name="title">
115     <xsl:apply-templates select="/*[1]" mode="label.markup"/>
116     <xsl:apply-templates select="/*[1]" mode="title.markup"/>
117     <xsl:variable name="subtitle">
118       <xsl:apply-templates select="/*[1]" mode="subtitle.markup">
119         <xsl:with-param name="verbose" select="0"/>
120       </xsl:apply-templates>
121     </xsl:variable>
122     <xsl:if test="$subtitle !=''">
123       <xsl:text> - </xsl:text>
124       <xsl:value-of select="$subtitle"/>
125     </xsl:if>
126   </xsl:variable>
127
128   <fo:declarations>
129     <x:xmpmeta xmlns:x="adobe:ns:meta/">
130       <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
131         <rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
132           <!-- Dublin Core properties go here -->
133
134           <!-- Title -->
135           <dc:title><xsl:value-of select="normalize-space($title)"/></dc:title>
136
137           <!-- Author -->
138           <xsl:if test="$authors">
139             <xsl:variable name="author">
140               <xsl:choose>
141                 <xsl:when test="$authors[self::d:authorgroup]">
142                   <xsl:call-template name="person.name.list">
143                     <xsl:with-param name="person.list" 
144                        select="$authors/*[self::d:author|self::d:corpauthor|
145                                      self::d:othercredit|self::d:editor]"/>
146                   </xsl:call-template>
147                 </xsl:when>
148                 <xsl:when test="$authors[self::d:corpauthor]">
149                   <xsl:value-of select="$authors"/>
150                 </xsl:when>
151                 <xsl:when test="$authors[d:orgname]">
152                   <xsl:value-of select="$authors/d:orgname"/>
153                 </xsl:when>
154                 <xsl:otherwise>
155                   <xsl:call-template name="person.name">
156                     <xsl:with-param name="node" select="$authors"/>
157                   </xsl:call-template>
158                 </xsl:otherwise>
159               </xsl:choose>
160             </xsl:variable>
161
162             <dc:creator><xsl:value-of select="normalize-space($author)"/></dc:creator>
163           </xsl:if>
164
165           <!-- Subject -->
166           <xsl:if test="//d:subjectterm">
167             <dc:description>
168               <xsl:for-each select="//d:subjectterm">
169                 <xsl:value-of select="normalize-space(.)"/>
170                 <xsl:if test="position() != last()">
171                   <xsl:text>, </xsl:text>
172                 </xsl:if>
173               </xsl:for-each>
174             </dc:description>
175           </xsl:if>
176         </rdf:Description>
177
178         <rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
179           <!-- PDF properties go here -->
180
181           <!-- Keywords -->
182           <xsl:if test="//d:keyword">
183             <pdf:Keywords>
184               <xsl:for-each select="//d:keyword">
185                 <xsl:value-of select="normalize-space(.)"/>
186                 <xsl:if test="position() != last()">
187                   <xsl:text>, </xsl:text>
188                 </xsl:if>
189               </xsl:for-each>
190             </pdf:Keywords>
191           </xsl:if>
192         </rdf:Description>
193
194         <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
195           <!-- XMP properties go here -->
196
197           <!-- Creator Tool -->
198           <xmp:CreatorTool>DocBook XSL Stylesheets with Apache FOP</xmp:CreatorTool>
199         </rdf:Description>
200
201       </rdf:RDF>
202     </x:xmpmeta>
203   </fo:declarations>
204 </xsl:template>
205
206 </xsl:stylesheet>