| 1 |
<?xml version="1.0"?> |
| 2 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 3 |
version="1.0"> |
| 4 |
|
| 5 |
<xsl:param name="website.database.document" |
| 6 |
select="'website.database.xml'"/> |
| 7 |
|
| 8 |
<xsl:template match="olink"> |
| 9 |
<xsl:choose> |
| 10 |
<xsl:when test="@targetdoc != '' or @targetptr != ''"> |
| 11 |
<xsl:apply-imports/> |
| 12 |
</xsl:when> |
| 13 |
<xsl:otherwise> |
| 14 |
<xsl:call-template name="olink-entity"/> |
| 15 |
</xsl:otherwise> |
| 16 |
</xsl:choose> |
| 17 |
</xsl:template> |
| 18 |
|
| 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]"/> |
| 26 |
|
| 27 |
<xsl:variable name="dir"> |
| 28 |
<xsl:choose> |
| 29 |
<xsl:when test="starts-with($tocentry/@dir, '/')"> |
| 30 |
<xsl:value-of select="substring($tocentry/@dir, 2)"/> |
| 31 |
</xsl:when> |
| 32 |
<xsl:otherwise> |
| 33 |
<xsl:value-of select="$tocentry/@dir"/> |
| 34 |
</xsl:otherwise> |
| 35 |
</xsl:choose> |
| 36 |
</xsl:variable> |
| 37 |
|
| 38 |
<!-- debug |
| 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> |
| 41 |
--> |
| 42 |
|
| 43 |
<xsl:choose> |
| 44 |
<xsl:when test="@type = 'embed'"> |
| 45 |
<xsl:apply-templates select="$xmlfile"/> |
| 46 |
</xsl:when> |
| 47 |
<xsl:otherwise> |
| 48 |
<!-- @type = 'replace' or @type = 'new' --> |
| 49 |
<a> |
| 50 |
<xsl:if test="@id"> |
| 51 |
<xsl:attribute name="name"> |
| 52 |
<xsl:value-of select="@id"/> |
| 53 |
</xsl:attribute> |
| 54 |
</xsl:if> |
| 55 |
|
| 56 |
<!-- debug |
| 57 |
<xsl:message> |
| 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"/> |
| 70 |
</xsl:if> |
| 71 |
</xsl:message> |
| 72 |
--> |
| 73 |
|
| 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"/> |
| 82 |
</xsl:if> |
| 83 |
</xsl:attribute> |
| 84 |
|
| 85 |
<xsl:if test="@type = 'new'"> |
| 86 |
<xsl:attribute name="target">_blank</xsl:attribute> |
| 87 |
</xsl:if> |
| 88 |
|
| 89 |
<xsl:choose> |
| 90 |
<xsl:when test="count(node()) = 0"> |
| 91 |
<xsl:apply-templates select="$webpage/head/title"/> |
| 92 |
</xsl:when> |
| 93 |
<xsl:otherwise> |
| 94 |
<xsl:apply-templates/> |
| 95 |
</xsl:otherwise> |
| 96 |
</xsl:choose> |
| 97 |
</a> |
| 98 |
</xsl:otherwise> |
| 99 |
</xsl:choose> |
| 100 |
</xsl:template> |
| 101 |
|
| 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="''"/> |
| 107 |
|
| 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,/)"/> |
| 117 |
</xsl:call-template> |
| 118 |
</xsl:if> |
| 119 |
</xsl:variable> |
| 120 |
|
| 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,/)"/> |
| 130 |
</xsl:call-template> |
| 131 |
</xsl:if> |
| 132 |
</xsl:variable> |
| 133 |
|
| 134 |
<xsl:choose> |
| 135 |
<xsl:when test="$website.olink.key != ''"> |
| 136 |
<xsl:value-of select="$website.database.document"/> |
| 137 |
</xsl:when> |
| 138 |
<xsl:when test="$offsite.olink.key != ''"> |
| 139 |
<xsl:value-of select="$target.database.document"/> |
| 140 |
</xsl:when> |
| 141 |
<xsl:otherwise> |
| 142 |
<!-- Return a bogus string and let the olink template deal with it |
| 143 |
<xsl:text>NOMATCHINANYDATABASEDOCUMENT</xsl:text> |
| 144 |
--> |
| 145 |
</xsl:otherwise> |
| 146 |
</xsl:choose> |
| 147 |
</xsl:template> |
| 148 |
|
| 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"/> |
| 153 |
|
| 154 |
<xsl:if test="$olink.key != ''"> |
| 155 |
|
| 156 |
<xsl:variable name="targetdoc"> |
| 157 |
<xsl:value-of select="substring-before($olink.key, '/')"/> |
| 158 |
</xsl:variable> |
| 159 |
|
| 160 |
<xsl:variable name="targetptr"> |
| 161 |
<xsl:value-of select="substring-before(substring-after($olink.key, '/'),'/')"/> |
| 162 |
</xsl:variable> |
| 163 |
|
| 164 |
<xsl:variable name="target.href" > |
| 165 |
<xsl:for-each select="$target.database" > |
| 166 |
<xsl:value-of select="key('targetptr-key', $olink.key)/@href" /> |
| 167 |
</xsl:for-each> |
| 168 |
</xsl:variable> |
| 169 |
|
| 170 |
<xsl:variable name="target.dir" > |
| 171 |
<xsl:for-each select="$target.database" > |
| 172 |
<xsl:value-of select="key('targetdoc-key', $targetdoc)/@dir" /> |
| 173 |
</xsl:for-each> |
| 174 |
</xsl:variable> |
| 175 |
|
| 176 |
<xsl:variable name="target.element" > |
| 177 |
<xsl:for-each select="$target.database" > |
| 178 |
<xsl:value-of select="key('targetptr-key', $olink.key)/@element" /> |
| 179 |
</xsl:for-each> |
| 180 |
</xsl:variable> |
| 181 |
|
| 182 |
<!-- Does the target database use a sitemap? --> |
| 183 |
<xsl:variable name="use.sitemap"> |
| 184 |
<xsl:choose> |
| 185 |
<xsl:when test="$target.database//sitemap">1</xsl:when> |
| 186 |
<xsl:otherwise>0</xsl:otherwise> |
| 187 |
</xsl:choose> |
| 188 |
</xsl:variable> |
| 189 |
|
| 190 |
|
| 191 |
<!-- Get the baseuri for this targetptr --> |
| 192 |
<xsl:variable name="baseuri" > |
| 193 |
<xsl:choose> |
| 194 |
<!-- Does the database use a sitemap? --> |
| 195 |
<xsl:when test="$use.sitemap != 0" > |
| 196 |
<xsl:choose> |
| 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" /> |
| 204 |
</xsl:for-each> |
| 205 |
</xsl:variable> |
| 206 |
<xsl:choose> |
| 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"/> |
| 213 |
</xsl:call-template> |
| 214 |
</xsl:for-each> |
| 215 |
</xsl:when> |
| 216 |
<xsl:otherwise> |
| 217 |
<xsl:call-template name="olink.error"> |
| 218 |
<xsl:with-param name="message"> |
| 219 |
<xsl:text>cannot compute relative </xsl:text> |
| 220 |
<xsl:text>sitemap path because $current.docid '</xsl:text> |
| 221 |
<xsl:value-of select="$current.docid"/> |
| 222 |
<xsl:text>' not found in target database.</xsl:text> |
| 223 |
</xsl:with-param> |
| 224 |
</xsl:call-template> |
| 225 |
</xsl:otherwise> |
| 226 |
</xsl:choose> |
| 227 |
</xsl:when> |
| 228 |
<xsl:otherwise> |
| 229 |
<xsl:call-template name="olink.error"> |
| 230 |
<xsl:with-param name="message"> |
| 231 |
<xsl:text>cannot compute relative </xsl:text> |
| 232 |
<xsl:text>sitemap path without $current.docid parameter</xsl:text> |
| 233 |
</xsl:with-param> |
| 234 |
</xsl:call-template> |
| 235 |
</xsl:otherwise> |
| 236 |
</xsl:choose> |
| 237 |
<!-- In either case, add baseuri from its document entry--> |
| 238 |
<xsl:variable name="docbaseuri"> |
| 239 |
<xsl:for-each select="$target.database" > |
| 240 |
<xsl:value-of select="key('targetdoc-key', $targetdoc)/@baseuri" /> |
| 241 |
</xsl:for-each> |
| 242 |
</xsl:variable> |
| 243 |
<xsl:if test="$docbaseuri != ''" > |
| 244 |
<xsl:value-of select="$docbaseuri"/> |
| 245 |
</xsl:if> |
| 246 |
</xsl:when> |
| 247 |
<!-- No database sitemap in use --> |
| 248 |
<xsl:otherwise> |
| 249 |
<!-- compute a root-relative path if current page has a @dir --> |
| 250 |
<xsl:variable name="root-rel"> |
| 251 |
<xsl:call-template name="root-rel-path"/> |
| 252 |
</xsl:variable> |
| 253 |
<xsl:if test="$root-rel != ''"> |
| 254 |
<xsl:value-of select="$root-rel"/> |
| 255 |
</xsl:if> |
| 256 |
<!-- Add the target's @dir to the path --> |
| 257 |
<xsl:if test="$target.dir != ''"> |
| 258 |
<xsl:value-of select="$target.dir"/> |
| 259 |
</xsl:if> |
| 260 |
<!-- Just use any baseuri from its document entry --> |
| 261 |
<xsl:variable name="docbaseuri"> |
| 262 |
<xsl:for-each select="$target.database" > |
| 263 |
<xsl:value-of select="key('targetdoc-key', |
| 264 |
$targetdoc)/@baseuri" /> |
| 265 |
</xsl:for-each> |
| 266 |
</xsl:variable> |
| 267 |
<xsl:if test="$docbaseuri != ''" > |
| 268 |
<xsl:value-of select="$docbaseuri"/> |
| 269 |
</xsl:if> |
| 270 |
</xsl:otherwise> |
| 271 |
</xsl:choose> |
| 272 |
</xsl:variable> |
| 273 |
|
| 274 |
<!-- Form the href information --> |
| 275 |
<xsl:if test="$baseuri != ''"> |
| 276 |
<xsl:value-of select="$baseuri"/> |
| 277 |
<xsl:if test="substring($target.href,1,1) != '#'"> |
| 278 |
<!--xsl:text>/</xsl:text--> |
| 279 |
</xsl:if> |
| 280 |
</xsl:if> |
| 281 |
<xsl:choose> |
| 282 |
<xsl:when test="$target.element = 'webpage' and |
| 283 |
$targetdoc = $targetptr"> |
| 284 |
<!-- Don't output #id because not needed --> |
| 285 |
</xsl:when> |
| 286 |
<!-- optionally turn off frag for PDF references --> |
| 287 |
<xsl:when test="not($insert.olink.pdf.frag = 0 and |
| 288 |
translate(substring($baseuri, string-length($baseuri) - 3), |
| 289 |
'PDF', 'pdf') = '.pdf' |
| 290 |
and starts-with($target.href, '#') )"> |
| 291 |
<xsl:value-of select="$target.href"/> |
| 292 |
</xsl:when> |
| 293 |
<xsl:otherwise> |
| 294 |
<xsl:value-of select="$target.href"/> |
| 295 |
</xsl:otherwise> |
| 296 |
</xsl:choose> |
| 297 |
</xsl:if> |
| 298 |
</xsl:template> |
| 299 |
|
| 300 |
|
| 301 |
</xsl:stylesheet> |