Debian Codegraph @

demo/legacypdf/xslfo/dita2fo-links.xsl

raw symbols SCIP
1 <?xml version='1.0'?>
2 <!-- This file is part of the DITA Open Toolkit project hosted on
3 Sourceforge.net. See the accompanying license.txt file for
4 applicable licenses.-->
5 <!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->
6
7 <!DOCTYPE xsl:transform [
8 <!-- entities for use in the generated output (must produce correctly in FO) -->
9 <!ENTITY bullet "&#x2022;"><!--check these two for better assignments -->
10 ]>
11 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12 xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
13 <!--==== related-links content subset ====-->
14 <xsl:template match="*[contains(@class,' topic/related-links ')]">
15 <xsl:if test="$output-related-links='yes'">
16 <fo:block>
17 <fo:block font-weight="bold">
18 <xsl:text>Related Links</xsl:text>
19 </fo:block>
20 <fo:block>
21 <xsl:attribute name="start-indent">
22 <xsl:value-of select="$basic-start-indent"/>
23 </xsl:attribute>
24 <xsl:apply-templates/>
25 </fo:block>
26 </fo:block>
27 </xsl:if>
28 </xsl:template>
29 <xsl:template
30 match="*[contains(@class,' topic/linklist ')]/*[contains(@class,' topic/title ')]">
31 <fo:block font-weight="bold">
32 <xsl:apply-templates/>
33 </fo:block>
34 </xsl:template>
35 <xsl:template match="*[contains(@class,' topic/linklist ')]">
36 <fo:block>
37 <xsl:apply-templates/>
38 </fo:block>
39 </xsl:template>
40 <xsl:template match="*[contains(@class,' topic/linkpool ')]">
41 <fo:block>
42 <xsl:apply-templates/>
43 </fo:block>
44 </xsl:template>
45 <xsl:template match="*[contains(@class,' topic/linktext ')]">
46 <fo:inline>
47 <xsl:apply-templates/>
48 </fo:inline>
49 </xsl:template>
50 <!-- rule for when the link is still not pointing at anything -->
51 <xsl:template match="*[contains(@class,' topic/link ')][@href = '']">
52 <fo:block color="red"
53 start-indent="{$basic-start-indent}">
54 <xsl:text>&bullet; </xsl:text>
55 <xsl:apply-templates/>
56 </fo:block>
57 </xsl:template>
58 <!-- if there is an href, make it look like a link and remove prompt -->
59 <xsl:template match="*[contains(@class,' topic/link ')][not(@href = '')]">
60 <xsl:choose>
61 <xsl:when test="not(@scope='external') and (@format='dita' or @format='DITA' or not(@format))">
62 <fo:block color="blue" text-decoration="underline"
63 start-indent="{$basic-start-indent}">
64 <xsl:text>&bullet; </xsl:text>
65 <fo:basic-link>
66 <xsl:attribute name="internal-destination">
67 <xsl:call-template name="href"/>
68 </xsl:attribute>
69 <xsl:apply-templates select="*[contains(@class,' topic/linktext ')]|text()"/>
70 <!--use linktext as linktext if it exists, otherwise use href as linktext-->
71 <xsl:choose>
72 <xsl:when test="*[contains(@class, ' topic/linktext ')]">
73 <xsl:apply-templates select="*[contains(@class, ' topic/linktext ')]"/>
74 </xsl:when>
75 <xsl:otherwise>
76 <!--use href text-->
77 <xsl:value-of select="@href"/>
78 </xsl:otherwise>
79 </xsl:choose>
80 </fo:basic-link>
81 </fo:block>
82 </xsl:when>
83 <xsl:otherwise>
84 <fo:block color="blue" text-decoration="underline"
85 start-indent="{$basic-start-indent}">
86 <xsl:text>&bullet; </xsl:text>
87 <fo:basic-link>
88 <xsl:attribute name="external-destination">
89 <xsl:value-of select="@href"/>
90 </xsl:attribute>
91 <!--use linktext as linktext if it exists, otherwise use href as linktext-->
92 <xsl:choose>
93 <xsl:when test="*[contains(@class, ' topic/linktext ')]">
94 <xsl:apply-templates select="*[contains(@class, ' topic/linktext ')]"/>
95 </xsl:when>
96 <xsl:otherwise>
97 <!-- use href text -->
98 <xsl:value-of select="@href"/>
99 </xsl:otherwise>
100 </xsl:choose>
101 </fo:basic-link>
102 </fo:block>
103 </xsl:otherwise>
104 </xsl:choose>
105 </xsl:template>
106 <!-- =============== end of related links markup ================= -->
107 <!-- =============== xref section (these occur in body) ================= -->
108 <!-- rule for when the xref is still not pointing at anything -->
109 <xsl:template match="*[contains(@class,' topic/xref ')][@href = '']">
110 <fo:inline color="red">
111 <fo:inline font-weight="bold">[xref to: <xsl:value-of
112 select="@href"/>]</fo:inline>
113 <xsl:apply-templates/>
114 </fo:inline>
115 </xsl:template>
116 <!-- if the xref element contains an href attribute, then create a hyperlink -->
117 <xsl:template match="*[contains(@class,' topic/xref ')][not(@href='')]">
118 <xsl:choose>
119 <!-- If the format attribute is dita, or is unspecified, then interpret the href as a topic -->
120 <!-- Create an internal hyperlink to the topic -->
121 <xsl:when test="not(@scope='external') and (@format='dita' or @format='DITA' or not(@format))">
122 <fo:inline color="blue">
123 <fo:basic-link>
124 <!-- Set the destination to the id attribute of the topic referred to by the href -->
125 <xsl:attribute name="internal-destination">
126 <xsl:call-template name="href"/>
127 </xsl:attribute>
128 <!--use content as linktext if it exists, otherwise use href as linktext-->
129 <xsl:choose>
130 <!--use xref content-->
131 <xsl:when test="text()">
132 <xsl:apply-templates select="text()"/>
133 </xsl:when>
134 <!--use href text-->
135 <xsl:otherwise>
136 <xsl:value-of select="@href"/>
137 </xsl:otherwise>
138 </xsl:choose>
139 </fo:basic-link>
140 </fo:inline>
141 <fo:inline>
142 <xsl:variable name="href-id">
143 <xsl:call-template name="href"/>
144 </xsl:variable>
145 <xsl:text> on page </xsl:text><fo:page-number-citation ref-id="{$href-id}"/>
146 </fo:inline>
147 </xsl:when>
148 <xsl:otherwise>
149 <fo:inline color="blue">
150 <fo:basic-link>
151 <xsl:attribute name="external-destination">
152 <xsl:value-of select="@href"/>
153 </xsl:attribute>
154 <!--use content as linktext if it exists, otherwise use href as linktext-->
155 <xsl:choose>
156 <!--use xref content-->
157 <xsl:when test="text()">
158 <xsl:apply-templates select="text()"/>
159 </xsl:when>
160 <!--use href text-->
161 <xsl:otherwise>
162 <xsl:value-of select="@href"/>
163 </xsl:otherwise>
164 </xsl:choose>
165 </fo:basic-link>
166 </fo:inline>
167 </xsl:otherwise>
168 </xsl:choose>
169
170 </xsl:template>
171
172 <xsl:template name="href">
173 <xsl:choose>
174 <!-- If the href contains a # character, then the topic file name is the preceding substring -->
175 <xsl:when test="starts-with(@href,'#')">
176 <xsl:choose>
177 <xsl:when test="contains(substring-after(@href,'#'),'/')">
178 <xsl:value-of
179 select="substring-before(substring-after(@href,'#'),'/')"/>
180 </xsl:when>
181 <xsl:otherwise>
182 <xsl:value-of select="substring-after(@href,'#')"/>
183 </xsl:otherwise>
184 </xsl:choose>
185 </xsl:when>
186 <xsl:when test="contains(@href,'#')">
187 <xsl:value-of select="document(substring-before(@href,'#'),/)//descendant::*[contains(@class,' topic/topic ')][1]/@id"/>
188 </xsl:when>
189 <xsl:otherwise>
190 <xsl:value-of select="document(@href,/)/descendant::*[contains(@class,' topic/topic ')][1]/@id"/>
191 </xsl:otherwise>
192 </xsl:choose>
193 </xsl:template>
194 <!-- =================== end of related links and xrefs ====================== -->
195 </xsl:stylesheet>