2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 <xsl:param name="website.database.document"
6 select="'website.database.xml'"/>
8 <xsl:template match="olink">
10 <xsl:when test="@targetdoc != '' or @targetptr != ''">
14 <xsl:call-template name="olink-entity"/>
19 <xsl:template name="olink-entity">
20 <xsl:variable name="xmlfile"
21 select="document(unparsed-entity-uri(@targetdocent),$autolayout)"/>
22 <xsl:variable name="webpage"
23 select="$xmlfile/webpage"/>
24 <xsl:variable name="tocentry"
25 select="$autolayout//*[$webpage/@id=@id]"/>
27 <xsl:variable name="dir">
29 <xsl:when test="starts-with($tocentry/@dir, '/')">
30 <xsl:value-of select="substring($tocentry/@dir, 2)"/>
33 <xsl:value-of select="$tocentry/@dir"/>
39 <xsl:message>Olink for <xsl:value-of select="unparsed-entity-uri(@targetdocent)"/></xsl:message>
40 <xsl:message>Page id <xsl:value-of select="$webpage/@id"/></xsl:message>
44 <xsl:when test="@type = 'embed'">
45 <xsl:apply-templates select="$xmlfile"/>
48 <!-- @type = 'replace' or @type = 'new' -->
51 <xsl:attribute name="name">
52 <xsl:value-of select="@id"/>
58 <xsl:text>href: </xsl:text>
59 <xsl:call-template name="root-rel-path"/>
60 <xsl:text>::</xsl:text>
61 <xsl:value-of select="$dir"/>
62 <xsl:text>::</xsl:text>
63 <xsl:value-of select="$filename-prefix"/>
64 <xsl:text>::</xsl:text>
65 <xsl:value-of select="$tocentry/@filename"/>
66 <xsl:text>::</xsl:text>
67 <xsl:if test="@localinfo">
68 <xsl:text>#</xsl:text>
69 <xsl:value-of select="@localinfo"/>
74 <xsl:attribute name="href">
75 <xsl:call-template name="root-rel-path"/>
76 <xsl:value-of select="$dir"/>
77 <xsl:value-of select="$filename-prefix"/>
78 <xsl:value-of select="$tocentry/@filename"/>
79 <xsl:if test="@localinfo">
80 <xsl:text>#</xsl:text>
81 <xsl:value-of select="@localinfo"/>
85 <xsl:if test="@type = 'new'">
86 <xsl:attribute name="target">_blank</xsl:attribute>
90 <xsl:when test="count(node()) = 0">
91 <xsl:apply-templates select="$webpage/head/title"/>
94 <xsl:apply-templates/>
102 <!-- Customize the selection to use both website and offsite databases -->
103 <xsl:template name="select.target.database">
104 <xsl:param name="targetdoc.att" select="''"/>
105 <xsl:param name="targetptr.att" select="''"/>
106 <xsl:param name="olink.lang" select="''"/>
108 <!-- Is the target in the website database? -->
109 <xsl:variable name="website.olink.key">
110 <xsl:if test="$website.database.document != ''">
111 <xsl:call-template name="select.olink.key">
112 <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
113 <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
114 <xsl:with-param name="olink.lang" select="$olink.lang"/>
115 <xsl:with-param name="target.database"
116 select="document($website.database.document,/)"/>
121 <!-- Is the target in the offsite database? -->
122 <xsl:variable name="offsite.olink.key">
123 <xsl:if test="$target.database.document != ''">
124 <xsl:call-template name="select.olink.key">
125 <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
126 <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
127 <xsl:with-param name="olink.lang" select="$olink.lang"/>
128 <xsl:with-param name="target.database"
129 select="document($target.database.document,/)"/>
135 <xsl:when test="$website.olink.key != ''">
136 <xsl:value-of select="$website.database.document"/>
138 <xsl:when test="$offsite.olink.key != ''">
139 <xsl:value-of select="$target.database.document"/>
142 <!-- Return a bogus string and let the olink template deal with it
143 <xsl:text>NOMATCHINANYDATABASEDOCUMENT</xsl:text>
149 <!-- Customize this template to use Website root-relative -->
150 <xsl:template name="make.olink.href">
151 <xsl:param name="olink.key" select="''"/>
152 <xsl:param name="target.database"/>
154 <xsl:if test="$olink.key != ''">
156 <xsl:variable name="targetdoc">
157 <xsl:value-of select="substring-before($olink.key, '/')"/>
160 <xsl:variable name="targetptr">
161 <xsl:value-of select="substring-before(substring-after($olink.key, '/'),'/')"/>
164 <xsl:variable name="target.href" >
165 <xsl:for-each select="$target.database" >
166 <xsl:value-of select="key('targetptr-key', $olink.key)/@href" />
170 <xsl:variable name="target.dir" >
171 <xsl:for-each select="$target.database" >
172 <xsl:value-of select="key('targetdoc-key', $targetdoc)/@dir" />
176 <xsl:variable name="target.element" >
177 <xsl:for-each select="$target.database" >
178 <xsl:value-of select="key('targetptr-key', $olink.key)/@element" />
182 <!-- Does the target database use a sitemap? -->
183 <xsl:variable name="use.sitemap">
185 <xsl:when test="$target.database//sitemap">1</xsl:when>
186 <xsl:otherwise>0</xsl:otherwise>
191 <!-- Get the baseuri for this targetptr -->
192 <xsl:variable name="baseuri" >
194 <!-- Does the database use a sitemap? -->
195 <xsl:when test="$use.sitemap != 0" >
197 <!-- Was current.docid parameter set? -->
198 <xsl:when test="$current.docid != ''">
199 <!-- Was it found in the database? -->
200 <xsl:variable name="currentdoc.key" >
201 <xsl:for-each select="$target.database" >
202 <xsl:value-of select="key('targetdoc-key',
203 $current.docid)/@targetdoc" />
207 <xsl:when test="$currentdoc.key != ''">
208 <xsl:for-each select="$target.database" >
209 <xsl:call-template name="targetpath" >
210 <xsl:with-param name="dirnode"
211 select="key('targetdoc-key', $current.docid)/parent::dir"/>
212 <xsl:with-param name="targetdoc" select="$targetdoc"/>
218 <xsl:text>Olink error: cannot compute relative </xsl:text>
219 <xsl:text>sitemap path because $current.docid '</xsl:text>
220 <xsl:value-of select="$current.docid"/>
221 <xsl:text>' not found in target database.</xsl:text>
228 <xsl:text>Olink warning: cannot compute relative </xsl:text>
229 <xsl:text>sitemap path without $current.docid parameter</xsl:text>
233 <!-- In either case, add baseuri from its document entry-->
234 <xsl:variable name="docbaseuri">
235 <xsl:for-each select="$target.database" >
236 <xsl:value-of select="key('targetdoc-key', $targetdoc)/@baseuri" />
239 <xsl:if test="$docbaseuri != ''" >
240 <xsl:value-of select="$docbaseuri"/>
243 <!-- No database sitemap in use -->
245 <!-- compute a root-relative path if current page has a @dir -->
246 <xsl:variable name="root-rel">
247 <xsl:call-template name="root-rel-path"/>
249 <xsl:if test="$root-rel != ''">
250 <xsl:value-of select="$root-rel"/>
252 <!-- Add the target's @dir to the path -->
253 <xsl:if test="$target.dir != ''">
254 <xsl:value-of select="$target.dir"/>
256 <!-- Just use any baseuri from its document entry -->
257 <xsl:variable name="docbaseuri">
258 <xsl:for-each select="$target.database" >
259 <xsl:value-of select="key('targetdoc-key',
260 $targetdoc)/@baseuri" />
263 <xsl:if test="$docbaseuri != ''" >
264 <xsl:value-of select="$docbaseuri"/>
270 <!-- Form the href information -->
271 <xsl:if test="$baseuri != ''">
272 <xsl:value-of select="$baseuri"/>
273 <xsl:if test="substring($target.href,1,1) != '#'">
274 <!--xsl:text>/</xsl:text-->
278 <xsl:when test="$target.element = 'webpage' and
279 $targetdoc = $targetptr">
280 <!-- Don't output #id because not needed -->
282 <!-- optionally turn off frag for PDF references -->
283 <xsl:when test="not($insert.olink.pdf.frag = 0 and
284 translate(substring($baseuri, string-length($baseuri) - 3),
285 'PDF', 'pdf') = '.pdf'
286 and starts-with($target.href, '#') )">
287 <xsl:value-of select="$target.href"/>
290 <xsl:value-of select="$target.href"/>