1<?xml version="1.0" encoding="utf-8"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns="http://www.w3.org/1999/xhtml"
4                version='1.0'>
5
6<!-- Performance-optimized versions of some upstream templates from xhtml/
7     directory -->
8
9<!-- from xhtml/autoidx.xsl -->
10
11<xsl:template match="indexterm" mode="reference">
12  <xsl:param name="scope" select="."/>
13  <xsl:param name="role" select="''"/>
14  <xsl:param name="type" select="''"/>
15  <xsl:param name="position"/>
16  <xsl:param name="separator" select="''"/>
17
18  <xsl:variable name="term.separator">
19    <xsl:call-template name="index.separator">
20      <xsl:with-param name="key" select="'index.term.separator'"/>
21    </xsl:call-template>
22  </xsl:variable>
23
24  <xsl:variable name="number.separator">
25    <xsl:call-template name="index.separator">
26      <xsl:with-param name="key" select="'index.number.separator'"/>
27    </xsl:call-template>
28  </xsl:variable>
29
30  <xsl:variable name="range.separator">
31    <xsl:call-template name="index.separator">
32      <xsl:with-param name="key" select="'index.range.separator'"/>
33    </xsl:call-template>
34  </xsl:variable>
35
36  <xsl:choose>
37    <xsl:when test="$separator != ''">
38      <xsl:value-of select="$separator"/>
39    </xsl:when>
40    <xsl:when test="$position = 1">
41      <xsl:value-of select="$term.separator"/>
42    </xsl:when>
43    <xsl:otherwise>
44      <xsl:value-of select="$number.separator"/>
45    </xsl:otherwise>
46  </xsl:choose>
47
48  <xsl:choose>
49    <xsl:when test="@zone and string(@zone)">
50      <xsl:call-template name="reference">
51        <xsl:with-param name="zones" select="normalize-space(@zone)"/>
52        <xsl:with-param name="position" select="position()"/>
53        <xsl:with-param name="scope" select="$scope"/>
54        <xsl:with-param name="role" select="$role"/>
55        <xsl:with-param name="type" select="$type"/>
56      </xsl:call-template>
57    </xsl:when>
58    <xsl:otherwise>
59      <a>
60        <xsl:apply-templates select="." mode="class.attribute"/>
61        <xsl:variable name="title">
62          <xsl:choose>
63            <xsl:when test="$index.prefer.titleabbrev != 0">
64              <xsl:apply-templates select="(ancestor-or-self::set|ancestor-or-self::book|ancestor-or-self::part|ancestor-or-self::reference|ancestor-or-self::partintro|ancestor-or-self::chapter|ancestor-or-self::appendix|ancestor-or-self::preface|ancestor-or-self::article|ancestor-or-self::section|ancestor-or-self::sect1|ancestor-or-self::sect2|ancestor-or-self::sect3|ancestor-or-self::sect4|ancestor-or-self::sect5|ancestor-or-self::refentry|ancestor-or-self::refsect1|ancestor-or-self::refsect2|ancestor-or-self::refsect3|ancestor-or-self::simplesect|ancestor-or-self::bibliography|ancestor-or-self::glossary|ancestor-or-self::index|ancestor-or-self::webpage|ancestor-or-self::topic)[last()]" mode="titleabbrev.markup"/>
65            </xsl:when>
66            <xsl:otherwise>
67              <xsl:apply-templates select="(ancestor-or-self::set|ancestor-or-self::book|ancestor-or-self::part|ancestor-or-self::reference|ancestor-or-self::partintro|ancestor-or-self::chapter|ancestor-or-self::appendix|ancestor-or-self::preface|ancestor-or-self::article|ancestor-or-self::section|ancestor-or-self::sect1|ancestor-or-self::sect2|ancestor-or-self::sect3|ancestor-or-self::sect4|ancestor-or-self::sect5|ancestor-or-self::refentry|ancestor-or-self::refsect1|ancestor-or-self::refsect2|ancestor-or-self::refsect3|ancestor-or-self::simplesect|ancestor-or-self::bibliography|ancestor-or-self::glossary|ancestor-or-self::index|ancestor-or-self::webpage|ancestor-or-self::topic)[last()]" mode="title.markup"/>
68            </xsl:otherwise>
69          </xsl:choose>
70        </xsl:variable>
71
72        <xsl:attribute name="href">
73          <xsl:choose>
74            <xsl:when test="$index.links.to.section = 1">
75              <xsl:call-template name="href.target">
76                <xsl:with-param name="object" select="(ancestor-or-self::set|ancestor-or-self::book|ancestor-or-self::part|ancestor-or-self::reference|ancestor-or-self::partintro|ancestor-or-self::chapter|ancestor-or-self::appendix|ancestor-or-self::preface|ancestor-or-self::article|ancestor-or-self::section|ancestor-or-self::sect1|ancestor-or-self::sect2|ancestor-or-self::sect3|ancestor-or-self::sect4|ancestor-or-self::sect5|ancestor-or-self::refentry|ancestor-or-self::refsect1|ancestor-or-self::refsect2|ancestor-or-self::refsect3|ancestor-or-self::simplesect|ancestor-or-self::bibliography|ancestor-or-self::glossary|ancestor-or-self::index|ancestor-or-self::webpage|ancestor-or-self::topic)[last()]"/>
77                <!-- Optimization for pgsql-docs: We only have an index as a
78                     child of book, so look that up directly instead of
79                     scanning the entire node tree.  Also, don't look for
80                     setindex. -->
81                <!-- <xsl:with-param name="context" select="(//index[count(ancestor::node()|$scope) = count(ancestor::node()) and ($role = @role or $type = @type or (string-length($role) = 0 and string-length($type) = 0))] | //setindex[count(ancestor::node()|$scope) = count(ancestor::node()) and ($role = @role or $type = @type or (string-length($role) = 0 and string-length($type) = 0))])[1]"/> -->
82                <xsl:with-param name="context" select="(/book/index[count(ancestor::node()|$scope) = count(ancestor::node()) and ($role = @role or $type = @type or (string-length($role) = 0 and string-length($type) = 0))])[1]"/>
83              </xsl:call-template>
84            </xsl:when>
85            <xsl:otherwise>
86              <xsl:call-template name="href.target">
87                <xsl:with-param name="object" select="."/>
88                <xsl:with-param name="context" select="(//index[count(ancestor::node()|$scope) = count(ancestor::node()) and ($role = @role or $type = @type or (string-length($role) = 0 and string-length($type) = 0))] | //setindex[count(ancestor::node()|$scope) = count(ancestor::node()) and ($role = @role or $type = @type or (string-length($role) = 0 and string-length($type) = 0))])[1]"/>
89              </xsl:call-template>
90            </xsl:otherwise>
91          </xsl:choose>
92
93        </xsl:attribute>
94
95        <xsl:value-of select="$title"/> <!-- text only -->
96      </a>
97
98      <xsl:variable name="id" select="(@id|@xml:id)[1]"/>
99      <xsl:if test="key('endofrange', $id)[count(ancestor::node()|$scope) = count(ancestor::node()) and ($role = @role or $type = @type or (string-length($role) = 0 and string-length($type) = 0))]">
100        <xsl:apply-templates select="key('endofrange', $id)[count(ancestor::node()|$scope) = count(ancestor::node()) and ($role = @role or $type = @type or (string-length($role) = 0 and string-length($type) = 0))][last()]" mode="reference">
101          <xsl:with-param name="position" select="position()"/>
102          <xsl:with-param name="scope" select="$scope"/>
103          <xsl:with-param name="role" select="$role"/>
104          <xsl:with-param name="type" select="$type"/>
105          <xsl:with-param name="separator" select="$range.separator"/>
106        </xsl:apply-templates>
107      </xsl:if>
108    </xsl:otherwise>
109  </xsl:choose>
110</xsl:template>
111
112<xsl:template name="reference">
113  <xsl:param name="scope" select="."/>
114  <xsl:param name="role" select="''"/>
115  <xsl:param name="type" select="''"/>
116  <xsl:param name="zones"/>
117
118  <xsl:choose>
119    <xsl:when test="contains($zones, ' ')">
120      <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
121      <xsl:variable name="target" select="key('sections', $zone)"/>
122
123      <a>
124        <xsl:apply-templates select="." mode="class.attribute"/>
125<!--    Optimization for pgsql-docs: this call adds nothing but fails with docbook-xsl 1.76 -->
126<!--    <xsl:call-template name="id.attribute"/> -->
127        <xsl:attribute name="href">
128          <xsl:call-template name="href.target">
129            <xsl:with-param name="object" select="$target[1]"/>
130            <xsl:with-param name="context" select="//index[count(ancestor::node()|$scope) = count(ancestor::node()) and ($role = @role or $type = @type or (string-length($role) = 0 and string-length($type) = 0))][1]"/>
131          </xsl:call-template>
132        </xsl:attribute>
133        <xsl:apply-templates select="$target[1]" mode="index-title-content"/>
134      </a>
135      <xsl:text>, </xsl:text>
136      <xsl:call-template name="reference">
137        <xsl:with-param name="zones" select="substring-after($zones, ' ')"/>
138        <xsl:with-param name="position" select="position()"/>
139        <xsl:with-param name="scope" select="$scope"/>
140        <xsl:with-param name="role" select="$role"/>
141        <xsl:with-param name="type" select="$type"/>
142      </xsl:call-template>
143    </xsl:when>
144    <xsl:otherwise>
145      <xsl:variable name="zone" select="$zones"/>
146      <xsl:variable name="target" select="key('sections', $zone)"/>
147
148      <a>
149        <xsl:apply-templates select="." mode="class.attribute"/>
150<!--    Optimization for pgsql-docs: this call adds nothing but fails with docbook-xsl 1.76 -->
151<!--    <xsl:call-template name="id.attribute"/> -->
152        <xsl:attribute name="href">
153          <xsl:call-template name="href.target">
154            <xsl:with-param name="object" select="$target[1]"/>
155            <!-- Optimization for pgsql-docs: Only look for index under book
156                 instead of searching the whole node tree. -->
157            <!-- <xsl:with-param name="context" select="//index[count(ancestor::node()|$scope) = count(ancestor::node()) and ($role = @role or $type = @type or (string-length($role) = 0 and string-length($type) = 0))][1]"/> -->
158            <xsl:with-param name="context" select="/book/index[count(ancestor::node()|$scope) = count(ancestor::node()) and ($role = @role or $type = @type or (string-length($role) = 0 and string-length($type) = 0))][1]"/>
159          </xsl:call-template>
160        </xsl:attribute>
161        <xsl:apply-templates select="$target[1]" mode="index-title-content"/>
162      </a>
163    </xsl:otherwise>
164  </xsl:choose>
165</xsl:template>
166
167
168<!-- from xhtml/chunk-common.xsl -->
169
170<xsl:template name="chunk-all-sections">
171  <xsl:param name="content">
172    <xsl:apply-imports/>
173  </xsl:param>
174
175  <!-- Optimization for pgsql-docs: Since we set a fixed $chunk.section.depth,
176       we can do away with a bunch of complicated XPath searches for the
177       previous and next sections at various levels. -->
178
179  <xsl:if test="$chunk.section.depth != 1">
180    <xsl:message terminate="yes">
181      <xsl:text>Error: If you change $chunk.section.depth, then you must update the performance-optimized chunk-all-sections-template.</xsl:text>
182    </xsl:message>
183  </xsl:if>
184
185  <xsl:variable name="prev"
186    select="(preceding::book[1]
187             |preceding::preface[1]
188             |preceding::chapter[1]
189             |preceding::appendix[1]
190             |preceding::part[1]
191             |preceding::reference[1]
192             |preceding::refentry[1]
193             |preceding::colophon[1]
194             |preceding::article[1]
195             |preceding::topic[1]
196             |preceding::bibliography[parent::article or parent::book or parent::part][1]
197             |preceding::glossary[parent::article or parent::book or parent::part][1]
198             |preceding::index[$generate.index != 0]
199                               [parent::article or parent::book or parent::part][1]
200             |preceding::setindex[$generate.index != 0][1]
201             |ancestor::set
202             |ancestor::book[1]
203             |ancestor::preface[1]
204             |ancestor::chapter[1]
205             |ancestor::appendix[1]
206             |ancestor::part[1]
207             |ancestor::reference[1]
208             |ancestor::article[1]
209             |ancestor::topic[1]
210             |preceding::sect1[1]
211             |ancestor::sect1[1])[last()]"/>
212
213  <xsl:variable name="next"
214    select="(following::book[1]
215             |following::preface[1]
216             |following::chapter[1]
217             |following::appendix[1]
218             |following::part[1]
219             |following::reference[1]
220             |following::refentry[1]
221             |following::colophon[1]
222             |following::bibliography[parent::article or parent::book or parent::part][1]
223             |following::glossary[parent::article or parent::book or parent::part][1]
224             |following::index[$generate.index != 0]
225                               [parent::article or parent::book][1]
226             |following::article[1]
227             |following::topic[1]
228             |following::setindex[$generate.index != 0][1]
229             |descendant::book[1]
230             |descendant::preface[1]
231             |descendant::chapter[1]
232             |descendant::appendix[1]
233             |descendant::article[1]
234             |descendant::topic[1]
235             |descendant::bibliography[parent::article or parent::book][1]
236             |descendant::glossary[parent::article or parent::book or parent::part][1]
237             |descendant::index[$generate.index != 0]
238                                [parent::article or parent::book][1]
239             |descendant::colophon[1]
240             |descendant::setindex[$generate.index != 0][1]
241             |descendant::part[1]
242             |descendant::reference[1]
243             |descendant::refentry[1]
244             |following::sect1[1]
245             |descendant::sect1[1])[1]"/>
246
247  <xsl:call-template name="process-chunk">
248    <xsl:with-param name="prev" select="$prev"/>
249    <xsl:with-param name="next" select="$next"/>
250    <xsl:with-param name="content" select="$content"/>
251  </xsl:call-template>
252</xsl:template>
253
254<xsl:template name="href.target">
255  <xsl:param name="context" select="."/>
256  <xsl:param name="object" select="."/>
257  <xsl:param name="toc-context" select="."/>
258  <!-- Optimization for pgsql-docs: Remove support for dbhtml processing
259       instruction here -->
260  <xsl:variable name="href.to.uri">
261    <xsl:call-template name="href.target.uri">
262      <xsl:with-param name="object" select="$object"/>
263    </xsl:call-template>
264  </xsl:variable>
265  <xsl:variable name="href.from.uri">
266    <xsl:choose>
267      <xsl:when test="not($toc-context = .)">
268        <xsl:call-template name="href.target.uri">
269          <xsl:with-param name="object" select="$toc-context"/>
270        </xsl:call-template>
271      </xsl:when>
272      <xsl:otherwise>
273        <xsl:call-template name="href.target.uri">
274          <xsl:with-param name="object" select="$context"/>
275        </xsl:call-template>
276      </xsl:otherwise>
277    </xsl:choose>
278  </xsl:variable>
279  <xsl:variable name="href.to">
280    <xsl:value-of select="$href.to.uri"/>
281  </xsl:variable>
282  <xsl:variable name="href.from">
283    <xsl:call-template name="trim.common.uri.paths">
284      <xsl:with-param name="uriA" select="$href.to.uri"/>
285      <xsl:with-param name="uriB" select="$href.from.uri"/>
286      <xsl:with-param name="return" select="'B'"/>
287    </xsl:call-template>
288  </xsl:variable>
289  <xsl:variable name="depth">
290    <xsl:call-template name="count.uri.path.depth">
291      <xsl:with-param name="filename" select="$href.from"/>
292    </xsl:call-template>
293  </xsl:variable>
294  <xsl:variable name="href">
295    <xsl:call-template name="copy-string">
296      <xsl:with-param name="string" select="'../'"/>
297      <xsl:with-param name="count" select="$depth"/>
298    </xsl:call-template>
299    <xsl:value-of select="$href.to"/>
300  </xsl:variable>
301  <xsl:value-of select="$href"/>
302</xsl:template>
303
304<xsl:template name="html.head">
305  <xsl:param name="prev" select="/foo"/>
306  <xsl:param name="next" select="/foo"/>
307
308  <!-- Optimization for pgsql-docs: Cut out a bunch of things we don't need
309       here, including an expensive //legalnotice search. -->
310
311  <head>
312    <xsl:call-template name="system.head.content"/>
313    <xsl:call-template name="head.content"/>
314
315    <xsl:if test="$prev">
316      <link rel="prev">
317        <xsl:attribute name="href">
318          <xsl:call-template name="href.target">
319            <xsl:with-param name="object" select="$prev"/>
320          </xsl:call-template>
321        </xsl:attribute>
322        <xsl:attribute name="title">
323          <xsl:apply-templates select="$prev" mode="object.title.markup.textonly"/>
324        </xsl:attribute>
325      </link>
326    </xsl:if>
327
328    <xsl:if test="$next">
329      <link rel="next">
330        <xsl:attribute name="href">
331          <xsl:call-template name="href.target">
332            <xsl:with-param name="object" select="$next"/>
333          </xsl:call-template>
334        </xsl:attribute>
335        <xsl:attribute name="title">
336          <xsl:apply-templates select="$next" mode="object.title.markup.textonly"/>
337        </xsl:attribute>
338      </link>
339    </xsl:if>
340
341    <xsl:call-template name="user.head.content"/>
342  </head>
343</xsl:template>
344
345</xsl:stylesheet>
346