Debian Codegraph @

xslt/docbook/html/db2html-xref.xsl

raw
1 <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
2 <!--
3 This program is free software; you can redistribute it and/or modify it under
4 the terms of the GNU Lesser General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12
13 You should have received a copy of the GNU Lesser General Public License
14 along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/>.
15 -->
16
17 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
18 xmlns:db="http://docbook.org/ns/docbook"
19 xmlns:xl="http://www.w3.org/1999/xlink"
20 xmlns="http://www.w3.org/1999/xhtml"
21 exclude-result-prefixes="db xl"
22 version="1.0">
23
24 <!--!!==========================================================================
25 DocBook to HTML - Links and Cross References
26
27 REMARK: Describe this module
28 -->
29
30
31 <!--**==========================================================================
32 db2html.anchor
33 Generates an anchor point for an element
34
35 [xsl:params]
36 $node: The element to generate an anchor for
37 $name: The text to use for the `name` attribute
38
39 REMARK: Describe this template
40 -->
41 <xsl:template name="db2html.anchor" match="anchor | db:anchor">
42 <xsl:param name="node" select="."/>
43 <xsl:param name="name" select="$node/@id | $node/@xml:id"/>
44 <xsl:if test="$name"><a name="{$name}"/></xsl:if>
45 </xsl:template>
46
47
48 <!--**==========================================================================
49 db2html.link
50 Generates a hyperlink from a `link` element
51
52 [xsl:params]
53 $linkend: The id of the element being linked to
54 $target: The element being linked to
55
56 REMARK: Describe this template
57 -->
58 <xsl:template name="db2html.link" match="link">
59 <xsl:param name="linkend" select="@linkend"/>
60 <xsl:param name="target" select="key('db.id.key', $linkend)"/>
61 <a>
62 <xsl:call-template name="html.class.attr">
63 <xsl:with-param name="class" select="'link'"/>
64 </xsl:call-template>
65 <xsl:attribute name="href">
66 <xsl:call-template name="db.xref.target">
67 <xsl:with-param name="linkend" select="$linkend"/>
68 </xsl:call-template>
69 </xsl:attribute>
70 <xsl:attribute name="title">
71 <xsl:call-template name="db.xref.tooltip">
72 <xsl:with-param name="linkend" select="$linkend"/>
73 <xsl:with-param name="target" select="$target"/>
74 </xsl:call-template>
75 </xsl:attribute>
76 <xsl:choose>
77 <xsl:when test="normalize-space(.) != ''">
78 <xsl:apply-templates/>
79 </xsl:when>
80 <xsl:when test="@endterm">
81 <xsl:apply-templates select="key('db.id.key', @endterm)/node()"/>
82 </xsl:when>
83 </xsl:choose>
84 </a>
85 </xsl:template>
86
87
88 <!--**==========================================================================
89 db2html.ulink
90 Generates a hyperlink from a `ulink` element
91
92 [xsl:params]
93 $url: The URL to link to
94 $content: Optional content to use for the text of the link
95
96 REMARK: Describe this template
97 -->
98 <xsl:template name="db2html.ulink" match="ulink">
99 <xsl:param name="url" select="@url"/>
100 <xsl:param name="content" select="false()"/>
101 <a href="{$url}">
102 <xsl:call-template name="html.class.attr">
103 <xsl:with-param name="class" select="'ulink'"/>
104 </xsl:call-template>
105 <xsl:attribute name="title">
106 <xsl:call-template name="db.ulink.tooltip"/>
107 </xsl:attribute>
108 <xsl:choose>
109 <!--
110 Other templates, such as db2html.xlink (from ubiquitously linked
111 inlines) may pass us $content as a result tree fragment. If $content
112 is empty, it may still be evaluated as true, which isn't what we want.
113 -->
114 <xsl:when test="$content and string-length($content) != 0">
115 <xsl:copy-of select="$content"/>
116 </xsl:when>
117 <xsl:when test="string-length(normalize-space(node())) != 0">
118 <xsl:apply-templates/>
119 </xsl:when>
120 <xsl:otherwise>
121 <xsl:value-of select="$url"/>
122 </xsl:otherwise>
123 </xsl:choose>
124 </a>
125 </xsl:template>
126
127
128 <!--**==========================================================================
129 db2html.xlink
130 Generates a hyperlink from a DocBook 5 `link` element
131
132 [xsl:params]
133 $node: The node in question
134 $linkend: The ID of the element to link to
135 $url: The URL to link to
136 $content: Optional content to use for the text of the link
137
138 Note that this template is also called for inline elements that use DocBook 5's ubiquitous linking.
139 -->
140 <xsl:template name="db2html.xlink" match="db:link">
141 <xsl:param name="node" select="."/>
142 <xsl:param name="linkend" select="$node/@linkend"/>
143 <xsl:param name="url" select="$node/@xl:href"/>
144 <xsl:param name="content" select="false()"/>
145
146 <xsl:choose>
147 <xsl:when test="$url">
148 <xsl:call-template name="db2html.ulink">
149 <xsl:with-param name="url" select="$url"/>
150 <xsl:with-param name="content" select="$content"/>
151 </xsl:call-template>
152 </xsl:when>
153 <xsl:when test="$linkend">
154 <xsl:call-template name="db2html.link">
155 <xsl:with-param name="linkend" select="$linkend"/>
156 </xsl:call-template>
157 </xsl:when>
158 </xsl:choose>
159 </xsl:template>
160
161
162 <!--**==========================================================================
163 db2html.xref
164 Generates a hyperlink from an `xref` element
165
166 [xsl:params]
167 $linkend: The id of the element being linked to
168 $target: The element being linked to
169 $endterm: The id of an element whose contents will be used for the link text
170 $xrefstyle: The style of cross reference text to use
171 $content: Optional content to use for the text of the link
172
173 REMARK: Describe this template
174 -->
175 <xsl:template name="db2html.xref" match="xref | db:xref">
176 <xsl:param name="linkend" select="@linkend"/>
177 <xsl:param name="target" select="key('db.id.key', $linkend)"/>
178 <xsl:param name="endterm" select="@endterm"/>
179 <xsl:param name="xrefstyle" select="@xrefstyle"/>
180 <xsl:param name="content" select="false()"/>
181 <a>
182 <xsl:call-template name="html.class.attr">
183 <xsl:with-param name="class" select="'xref'"/>
184 </xsl:call-template>
185 <xsl:attribute name="href">
186 <xsl:call-template name="db.xref.target">
187 <xsl:with-param name="linkend" select="$linkend"/>
188 <xsl:with-param name="target" select="$target"/>
189 </xsl:call-template>
190 </xsl:attribute>
191 <xsl:attribute name="title">
192 <xsl:call-template name="db.xref.tooltip">
193 <xsl:with-param name="linkend" select="$linkend"/>
194 <xsl:with-param name="target" select="$target"/>
195 </xsl:call-template>
196 </xsl:attribute>
197 <xsl:choose>
198 <xsl:when test="$content">
199 <xsl:copy-of select="$content"/>
200 </xsl:when>
201 <xsl:when test="$endterm">
202 <xsl:apply-templates select="key('db.id.key', $endterm)/node()"/>
203 </xsl:when>
204 <xsl:otherwise>
205 <xsl:call-template name="db.xref.content">
206 <xsl:with-param name="linkend" select="$linkend"/>
207 <xsl:with-param name="target" select="$target"/>
208 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
209 </xsl:call-template>
210 </xsl:otherwise>
211 </xsl:choose>
212 </a>
213 </xsl:template>
214
215 </xsl:stylesheet>