| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<xsl:stylesheet |
| 3 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 4 |
xmlns:d="http://docbook.org/ns/docbook" |
| 5 |
xmlns:exsl="http://exslt.org/common" |
| 6 |
xmlns:xlink="http://www.w3.org/1999/xlink" |
| 7 |
xmlns="http://docbook.org/ns/docbook" |
| 8 |
exclude-result-prefixes="exsl d xlink d" |
| 9 |
version="1.0"> |
| 10 |
|
| 11 |
<xsl:preserve-space elements="*"/> |
| 12 |
<xsl:strip-space elements="d:assembly d:structure d:module d:resources d:resource"/> |
| 13 |
|
| 14 |
<xsl:key name="id" match="*" use="@id|@xml:id"/> |
| 15 |
|
| 16 |
|
| 17 |
<xsl:param name="docbook.version">5.0</xsl:param> |
| 18 |
<xsl:param name="root.default.renderas">book</xsl:param> |
| 19 |
<xsl:param name="topic.default.renderas">section</xsl:param> |
| 20 |
|
| 21 |
<xsl:param name="output.type" select="''"/> |
| 22 |
<xsl:param name="output.format" select="''"/> |
| 23 |
<!-- May be used to select one structure among several to process --> |
| 24 |
<xsl:param name="structure.id" select="''"/> |
| 25 |
|
| 26 |
|
| 27 |
<!-- default mode is to copy all content nodes --> |
| 28 |
<xsl:template match="node()|@*" priority="-5" mode="copycontent"> |
| 29 |
<xsl:param name="omittitles"/> |
| 30 |
<xsl:copy> |
| 31 |
<xsl:apply-templates select="@*" mode="copycontent"/> |
| 32 |
<xsl:apply-templates mode="copycontent"> |
| 33 |
<xsl:with-param name="omittitles" select="$omittitles"/> |
| 34 |
</xsl:apply-templates> |
| 35 |
</xsl:copy> |
| 36 |
</xsl:template> |
| 37 |
|
| 38 |
<xsl:template match="processing-instruction('oxygen')"/> |
| 39 |
|
| 40 |
<!-- skip assembly info elements --> |
| 41 |
<xsl:template match="d:info"/> |
| 42 |
|
| 43 |
<!-- including for structure info element --> |
| 44 |
<xsl:template match="d:structure/d:info"/> |
| 45 |
|
| 46 |
<!-- handle omittitles, but only top level title of resource --> |
| 47 |
<xsl:template match="/*/d:title |
| 48 |
| /*/d:info/d:title |
| 49 |
| /*/d:subtitle |
| 50 |
| /*/d:info/d:subtitle |
| 51 |
| /*/d:titleabbrev |
| 52 |
| /*/d:info/d:titleabbrev" |
| 53 |
mode="copycontent"> |
| 54 |
<xsl:param name="omittitles"/> |
| 55 |
|
| 56 |
<xsl:choose> |
| 57 |
<xsl:when test="$omittitles = 'yes' or $omittitles = 'true' or $omittitles = '1'"> |
| 58 |
<!-- omit it --> |
| 59 |
</xsl:when> |
| 60 |
<xsl:otherwise> |
| 61 |
<xsl:copy> |
| 62 |
<xsl:apply-templates select="@*" mode="copycontent"/> |
| 63 |
<xsl:apply-templates mode="copycontent"/> |
| 64 |
</xsl:copy> |
| 65 |
</xsl:otherwise> |
| 66 |
</xsl:choose> |
| 67 |
</xsl:template> |
| 68 |
|
| 69 |
<!-- handled in a mode --> |
| 70 |
<xsl:template match="d:resources"/> |
| 71 |
<xsl:template match="d:output|d:filterin|d:filterout|d:merge|d:revhistory"/> |
| 72 |
<xsl:template match="d:output|d:filterin|d:filterout|d:merge|d:revhistory" |
| 73 |
mode="copycontent"/> |
| 74 |
|
| 75 |
<xsl:template match="d:assembly"> |
| 76 |
<xsl:choose> |
| 77 |
<xsl:when test="$structure.id != ''"> |
| 78 |
<xsl:variable name="id.structure" select="key('id', $structure.id)"/> |
| 79 |
<xsl:choose> |
| 80 |
<xsl:when test="count($id.structure) = 0"> |
| 81 |
<xsl:message terminate="yes"> |
| 82 |
<xsl:text>ERROR: structure.id param set to '</xsl:text> |
| 83 |
<xsl:value-of select="$structure.id"/> |
| 84 |
<xsl:text>' but no element with that xml:id exists in assembly.</xsl:text> |
| 85 |
</xsl:message> |
| 86 |
</xsl:when> |
| 87 |
<xsl:when test="local-name($id.structure) != 'structure'"> |
| 88 |
<xsl:message terminate="yes"> |
| 89 |
<xsl:text>ERROR: structure.id param set to '</xsl:text> |
| 90 |
<xsl:value-of select="$structure.id"/> |
| 91 |
<xsl:text>' but no structure with that xml:id exists in assembly.</xsl:text> |
| 92 |
</xsl:message> |
| 93 |
</xsl:when> |
| 94 |
<xsl:otherwise> |
| 95 |
<xsl:apply-templates select="key('id', $structure.id)"/> |
| 96 |
</xsl:otherwise> |
| 97 |
</xsl:choose> |
| 98 |
</xsl:when> |
| 99 |
<xsl:when test="$output.type != '' and not(d:structure[@type = $output.type])"> |
| 100 |
<xsl:message terminate="yes"> |
| 101 |
<xsl:text>ERROR: output.type param set to '</xsl:text> |
| 102 |
<xsl:value-of select="$output.type"/> |
| 103 |
<xsl:text> but no structure element has that type attribute. Exiting.</xsl:text> |
| 104 |
</xsl:message> |
| 105 |
</xsl:when> |
| 106 |
<xsl:when test="$output.type != '' and d:structure[@type = $output.type]"> |
| 107 |
<xsl:apply-templates select="d:structure[@type = $output.type][1]"/> |
| 108 |
</xsl:when> |
| 109 |
<xsl:otherwise> |
| 110 |
<!-- otherwise process the first structure --> |
| 111 |
<xsl:apply-templates select="d:structure[1]"/> |
| 112 |
</xsl:otherwise> |
| 113 |
</xsl:choose> |
| 114 |
</xsl:template> |
| 115 |
|
| 116 |
<xsl:template match="d:structure[not(@resourceref)]"> |
| 117 |
|
| 118 |
<xsl:variable name="output.root.element"> |
| 119 |
<xsl:apply-templates select="." mode="compute.element.name"/> |
| 120 |
</xsl:variable> |
| 121 |
|
| 122 |
<xsl:element name="{$output.root.element}" namespace="http://docbook.org/ns/docbook"> |
| 123 |
<xsl:attribute name="version"> |
| 124 |
<xsl:value-of select="$docbook.version"/> |
| 125 |
</xsl:attribute> |
| 126 |
<xsl:copy-of select="@xml:id"/> |
| 127 |
|
| 128 |
<!-- use the merge element if present --> |
| 129 |
<xsl:call-template name="merge.info"> |
| 130 |
<xsl:with-param name="merge.element" select="d:merge"/> |
| 131 |
</xsl:call-template> |
| 132 |
|
| 133 |
<xsl:apply-templates> |
| 134 |
<xsl:with-param name="parent" select="$output.root.element"/> |
| 135 |
</xsl:apply-templates> |
| 136 |
|
| 137 |
</xsl:element> |
| 138 |
</xsl:template> |
| 139 |
|
| 140 |
<xsl:template match="d:glossary|d:bibliography|d:index|d:toc"> |
| 141 |
<xsl:param name="parent" select="''"/> |
| 142 |
<xsl:apply-templates select="." mode="copycontent"/> |
| 143 |
</xsl:template> |
| 144 |
|
| 145 |
<xsl:template match="d:title|d:titleabbrev|d:subtitle"> |
| 146 |
<xsl:param name="parent" select="''"/> |
| 147 |
<xsl:apply-templates select="." mode="copycontent"/> |
| 148 |
</xsl:template> |
| 149 |
|
| 150 |
<!-- module without a resourceref creates an element --> |
| 151 |
<xsl:template match="d:module[not(@resourceref)]"> |
| 152 |
<xsl:param name="parent" select="''"/> |
| 153 |
|
| 154 |
<xsl:variable name="module" select="."/> |
| 155 |
|
| 156 |
<xsl:variable name="element.name"> |
| 157 |
<xsl:apply-templates select="." mode="compute.element.name"/> |
| 158 |
</xsl:variable> |
| 159 |
|
| 160 |
<xsl:element name="{$element.name}" namespace="http://docbook.org/ns/docbook"> |
| 161 |
<xsl:choose> |
| 162 |
<!-- Use the module's xml:id if it has one --> |
| 163 |
<xsl:when test="@xml:id"> |
| 164 |
<xsl:attribute name="xml:id"> |
| 165 |
<xsl:value-of select="@xml:id"/> |
| 166 |
</xsl:attribute> |
| 167 |
</xsl:when> |
| 168 |
</xsl:choose> |
| 169 |
|
| 170 |
<xsl:call-template name="merge.info"> |
| 171 |
<xsl:with-param name="merge.element" select="$module/d:merge"/> |
| 172 |
</xsl:call-template> |
| 173 |
|
| 174 |
<xsl:apply-templates> |
| 175 |
<xsl:with-param name="parent" select="$element.name"/> |
| 176 |
</xsl:apply-templates> |
| 177 |
|
| 178 |
</xsl:element> |
| 179 |
</xsl:template> |
| 180 |
|
| 181 |
<xsl:template name="compute.renderas"> |
| 182 |
<xsl:variable name="output.value"> |
| 183 |
<xsl:call-template name="compute.output.value"> |
| 184 |
<xsl:with-param name="property">renderas</xsl:with-param> |
| 185 |
</xsl:call-template> |
| 186 |
</xsl:variable> |
| 187 |
|
| 188 |
<xsl:value-of select="$output.value"/> |
| 189 |
|
| 190 |
</xsl:template> |
| 191 |
|
| 192 |
<!-- This utility template is passed a value for output format |
| 193 |
and the name of a property and computes the value |
| 194 |
of the property from output children of context element --> |
| 195 |
<xsl:template name="compute.output.value"> |
| 196 |
<xsl:param name="property" select="''"/> |
| 197 |
|
| 198 |
<xsl:variable name="default.format" |
| 199 |
select="ancestor::d:structure/@defaultformat"/> |
| 200 |
|
| 201 |
<xsl:variable name="property.value"> |
| 202 |
<xsl:choose> |
| 203 |
<!-- if a child output element has a format that matches the param value |
| 204 |
and it has that property --> |
| 205 |
<!-- The format attribute can be multivalued --> |
| 206 |
<xsl:when test="$output.format != '' and |
| 207 |
d:output[contains(concat(' ', normalize-space(@format), ' '), |
| 208 |
$output.format)] |
| 209 |
[@*[local-name() = $property]]"> |
| 210 |
<xsl:value-of |
| 211 |
select="d:output[contains(concat(' ', normalize-space(@format), ' '), |
| 212 |
$output.format)] |
| 213 |
[@*[local-name() = $property]][1] |
| 214 |
/@*[local-name() = $property]"/> |
| 215 |
</xsl:when> |
| 216 |
<!-- try with the structure's @defaultformat --> |
| 217 |
<xsl:when test="$default.format != '' and |
| 218 |
d:output[contains(concat(' ', normalize-space(@format), ' '), |
| 219 |
$default.format)] |
| 220 |
[@*[local-name() = $property]]"> |
| 221 |
<xsl:value-of |
| 222 |
select="d:output[contains(concat(' ', normalize-space(@format), ' '), |
| 223 |
$default.format)] |
| 224 |
[@*[local-name() = $property]][1] |
| 225 |
/@*[local-name() = $property]"/> |
| 226 |
</xsl:when> |
| 227 |
<!-- try the first output with the property--> |
| 228 |
<xsl:when test="d:output[@*[local-name() = $property]]"> |
| 229 |
<xsl:value-of |
| 230 |
select="d:output[@*[local-name() = $property]][1] |
| 231 |
/@*[local-name() = $property]"/> |
| 232 |
</xsl:when> |
| 233 |
<!-- and try the module element itself --> |
| 234 |
<xsl:when test="@*[local-name() = $property]"> |
| 235 |
<xsl:value-of |
| 236 |
select="@*[local-name() = $property]"/> |
| 237 |
</xsl:when> |
| 238 |
</xsl:choose> |
| 239 |
</xsl:variable> |
| 240 |
|
| 241 |
<xsl:value-of select="$property.value"/> |
| 242 |
</xsl:template> |
| 243 |
|
| 244 |
<xsl:template match="d:module[not(@resourceref)]" mode="compute.element.name"> |
| 245 |
|
| 246 |
<xsl:variable name="renderas"> |
| 247 |
<xsl:call-template name="compute.renderas"/> |
| 248 |
</xsl:variable> |
| 249 |
|
| 250 |
<xsl:choose> |
| 251 |
<xsl:when test="string-length($renderas) != 0"> |
| 252 |
<xsl:value-of select="$renderas"/> |
| 253 |
</xsl:when> |
| 254 |
<xsl:otherwise> |
| 255 |
<xsl:message terminate="yes"> |
| 256 |
<xsl:text>ERROR: cannot determine output element name for </xsl:text> |
| 257 |
<xsl:text>module with no @resourceref and no @renderas. Exiting.</xsl:text> |
| 258 |
</xsl:message> |
| 259 |
</xsl:otherwise> |
| 260 |
</xsl:choose> |
| 261 |
</xsl:template> |
| 262 |
|
| 263 |
<xsl:template match="d:module[@resourceref]" mode="compute.element.name"> |
| 264 |
<xsl:param name="ref.name" select="''"/> |
| 265 |
|
| 266 |
<xsl:variable name="renderas"> |
| 267 |
<xsl:call-template name="compute.renderas"/> |
| 268 |
</xsl:variable> |
| 269 |
|
| 270 |
<xsl:choose> |
| 271 |
<xsl:when test="string-length($renderas) != 0"> |
| 272 |
<xsl:value-of select="$renderas"/> |
| 273 |
</xsl:when> |
| 274 |
<xsl:when test="$ref.name = 'topic' and |
| 275 |
string-length($topic.default.renderas) != 0"> |
| 276 |
<xsl:value-of select="$topic.default.renderas"/> |
| 277 |
</xsl:when> |
| 278 |
<xsl:when test="string-length($ref.name) != 0"> |
| 279 |
<xsl:value-of select="$ref.name"/> |
| 280 |
</xsl:when> |
| 281 |
<xsl:otherwise> |
| 282 |
<xsl:message terminate="yes"> |
| 283 |
<xsl:text>ERROR: cannot determine output element name for </xsl:text> |
| 284 |
<xsl:text>@resourceref="</xsl:text> |
| 285 |
<xsl:value-of select="@resourceref"/> |
| 286 |
<xsl:text>". Exiting.</xsl:text> |
| 287 |
</xsl:message> |
| 288 |
</xsl:otherwise> |
| 289 |
</xsl:choose> |
| 290 |
</xsl:template> |
| 291 |
|
| 292 |
<xsl:template match="d:structure" mode="compute.element.name"> |
| 293 |
<xsl:param name="ref.name" select="''"/> |
| 294 |
|
| 295 |
<xsl:variable name="renderas"> |
| 296 |
<xsl:call-template name="compute.renderas"/> |
| 297 |
</xsl:variable> |
| 298 |
|
| 299 |
<xsl:choose> |
| 300 |
<xsl:when test="string-length($renderas) != 0"> |
| 301 |
<xsl:value-of select="$renderas"/> |
| 302 |
</xsl:when> |
| 303 |
<xsl:when test="string-length($ref.name) != 0"> |
| 304 |
<xsl:value-of select="$ref.name"/> |
| 305 |
</xsl:when> |
| 306 |
<xsl:when test="string-length($root.default.renderas) != 0"> |
| 307 |
<xsl:value-of select="$root.default.renderas"/> |
| 308 |
</xsl:when> |
| 309 |
<xsl:otherwise> |
| 310 |
<xsl:message terminate="yes"> |
| 311 |
<xsl:text>ERROR: cannot determine output element name for </xsl:text> |
| 312 |
<xsl:text>structure with no @renderas and no $root.default.renderas. </xsl:text> |
| 313 |
<xsl:text>Exiting.</xsl:text> |
| 314 |
</xsl:message> |
| 315 |
</xsl:otherwise> |
| 316 |
</xsl:choose> |
| 317 |
</xsl:template> |
| 318 |
|
| 319 |
<xsl:template match="d:module[@resourceref] | d:structure[@resourceref]"> |
| 320 |
<xsl:param name="parent" select="''"/> |
| 321 |
|
| 322 |
<xsl:variable name="module" select="."/> |
| 323 |
<xsl:variable name="resourceref" select="@resourceref"/> |
| 324 |
<xsl:variable name="resource" select="key('id', $resourceref)"/> |
| 325 |
|
| 326 |
<xsl:choose> |
| 327 |
<xsl:when test="not($resource)"> |
| 328 |
<xsl:message terminate="yes"> |
| 329 |
<xsl:text>ERROR: no xml:id matches @resourceref = '</xsl:text> |
| 330 |
<xsl:value-of select="$resourceref"/> |
| 331 |
<xsl:text>'.</xsl:text> |
| 332 |
</xsl:message> |
| 333 |
</xsl:when> |
| 334 |
<xsl:when test="not($resource/self::d:resource)"> |
| 335 |
<xsl:message terminate="yes"> |
| 336 |
<xsl:text>ERROR: xml:id matching @resourceref = '</xsl:text> |
| 337 |
<xsl:value-of select="$resourceref"/> |
| 338 |
<xsl:text> is not a resource element'.</xsl:text> |
| 339 |
</xsl:message> |
| 340 |
</xsl:when> |
| 341 |
</xsl:choose> |
| 342 |
|
| 343 |
<xsl:variable name="href.att" select="$resource/@fileref | $resource/@href"/> |
| 344 |
|
| 345 |
<xsl:variable name="fragment.id"> |
| 346 |
<xsl:if test="contains($href.att, '#')"> |
| 347 |
<xsl:value-of select="substring-after($href.att, '#')"/> |
| 348 |
</xsl:if> |
| 349 |
</xsl:variable> |
| 350 |
|
| 351 |
<xsl:variable name="filename"> |
| 352 |
<xsl:choose> |
| 353 |
<xsl:when test="string-length($fragment.id) != 0"> |
| 354 |
<xsl:value-of select="substring-before($href.att, '#')"/> |
| 355 |
</xsl:when> |
| 356 |
<xsl:otherwise> |
| 357 |
<xsl:value-of select="$href.att"/> |
| 358 |
</xsl:otherwise> |
| 359 |
</xsl:choose> |
| 360 |
</xsl:variable> |
| 361 |
|
| 362 |
<xsl:variable name="fileref"> |
| 363 |
<xsl:choose> |
| 364 |
<xsl:when test="$resource/ancestor::d:resources/@xml:base"> |
| 365 |
<xsl:value-of |
| 366 |
select="concat($resource/ancestor::d:resources[@xml:base][1]/@xml:base, |
| 367 |
'/', $filename)"/> |
| 368 |
</xsl:when> |
| 369 |
<xsl:otherwise> |
| 370 |
<xsl:value-of select="$filename"/> |
| 371 |
</xsl:otherwise> |
| 372 |
</xsl:choose> |
| 373 |
</xsl:variable> |
| 374 |
|
| 375 |
<xsl:choose> |
| 376 |
<xsl:when test="string-length($fileref) = 0"> |
| 377 |
<!-- A resource without @fileref gets its content copied --> |
| 378 |
<xsl:apply-templates select="$resource/node()" mode="copycontent"/> |
| 379 |
</xsl:when> |
| 380 |
<xsl:otherwise> |
| 381 |
|
| 382 |
<xsl:variable name="ref.file.content" select="document($fileref,/)"/> |
| 383 |
|
| 384 |
<!-- selects root or fragmeht depending on if $fragment is blank --> |
| 385 |
<xsl:variable name="ref.content" |
| 386 |
select="$ref.file.content/*[1][$fragment.id = ''] | |
| 387 |
$ref.file.content/*[1][$fragment.id != '']/ |
| 388 |
descendant-or-self::*[@xml:id = $fragment.id]"/> |
| 389 |
|
| 390 |
<xsl:if test="count($ref.content) = 0"> |
| 391 |
<xsl:message terminate="yes"> |
| 392 |
<xsl:text>ERROR: @fileref = '</xsl:text> |
| 393 |
<xsl:value-of select="$fileref"/> |
| 394 |
<xsl:text>' has no content or is unresolved.</xsl:text> |
| 395 |
</xsl:message> |
| 396 |
</xsl:if> |
| 397 |
|
| 398 |
<xsl:variable name="element.name"> |
| 399 |
<xsl:apply-templates select="." mode="compute.element.name"> |
| 400 |
<xsl:with-param name="ref.name" select="local-name($ref.content)"/> |
| 401 |
</xsl:apply-templates> |
| 402 |
</xsl:variable> |
| 403 |
|
| 404 |
<xsl:variable name="omittitles.property"> |
| 405 |
<xsl:call-template name="compute.output.value"> |
| 406 |
<xsl:with-param name="property">omittitles</xsl:with-param> |
| 407 |
</xsl:call-template> |
| 408 |
</xsl:variable> |
| 409 |
|
| 410 |
<xsl:variable name="contentonly.property"> |
| 411 |
<xsl:call-template name="compute.output.value"> |
| 412 |
<xsl:with-param name="property">contentonly</xsl:with-param> |
| 413 |
</xsl:call-template> |
| 414 |
</xsl:variable> |
| 415 |
|
| 416 |
<xsl:choose> |
| 417 |
<xsl:when test="$contentonly.property = 'true' or |
| 418 |
$contentonly.property = 'yes' or |
| 419 |
$contentonly.property = '1'"> |
| 420 |
<xsl:apply-templates select="$ref.content/node()" mode="copycontent"> |
| 421 |
<xsl:with-param name="omittitles" select="$omittitles.property"/> |
| 422 |
</xsl:apply-templates> |
| 423 |
</xsl:when> |
| 424 |
<!-- use xsl:copy if using the ref element itself to get its namespaces --> |
| 425 |
<xsl:when test="$element.name = local-name($ref.content)"> |
| 426 |
<!-- must use for-each to set context node for xsl:copy --> |
| 427 |
<xsl:for-each select="$ref.content"> |
| 428 |
<xsl:copy> |
| 429 |
<xsl:copy-of select="@*[not(name() = 'xml:id')]"/> |
| 430 |
<xsl:choose> |
| 431 |
<!-- Use the module's xml:id if it has one --> |
| 432 |
<xsl:when test="$module/@xml:id"> |
| 433 |
<xsl:attribute name="xml:id"> |
| 434 |
<xsl:value-of select="$module/@xml:id"/> |
| 435 |
</xsl:attribute> |
| 436 |
</xsl:when> |
| 437 |
<!-- otherwise use the resource's id --> |
| 438 |
<xsl:otherwise> |
| 439 |
<xsl:copy-of select="@xml:id"/> |
| 440 |
</xsl:otherwise> |
| 441 |
</xsl:choose> |
| 442 |
|
| 443 |
<xsl:call-template name="merge.info"> |
| 444 |
<xsl:with-param name="merge.element" select="$module/d:merge"/> |
| 445 |
<xsl:with-param name="ref.content" select="$ref.content"/> |
| 446 |
<xsl:with-param name="omittitles" select="$omittitles.property"/> |
| 447 |
</xsl:call-template> |
| 448 |
|
| 449 |
<!-- copy through all but titles, which moved to info --> |
| 450 |
<xsl:apply-templates select="node() |
| 451 |
[not(local-name() = 'title') and |
| 452 |
not(local-name() = 'subtitle') and |
| 453 |
not(local-name() = 'info') and |
| 454 |
not(local-name() = 'titleabbrev')]" mode="copycontent"/> |
| 455 |
|
| 456 |
<xsl:apply-templates select="$module/node()"> |
| 457 |
<xsl:with-param name="parent" select="$element.name"/> |
| 458 |
</xsl:apply-templates> |
| 459 |
</xsl:copy> |
| 460 |
</xsl:for-each> |
| 461 |
</xsl:when> |
| 462 |
<xsl:otherwise> |
| 463 |
<!-- create the element instead of copying it --> |
| 464 |
<xsl:element name="{$element.name}" namespace="http://docbook.org/ns/docbook"> |
| 465 |
<xsl:copy-of select="$ref.content/@*[not(name() = 'xml:id')]"/> |
| 466 |
<xsl:choose> |
| 467 |
<!-- Use the module's xml:id if it has one --> |
| 468 |
<xsl:when test="@xml:id"> |
| 469 |
<xsl:attribute name="xml:id"> |
| 470 |
<xsl:value-of select="@xml:id"/> |
| 471 |
</xsl:attribute> |
| 472 |
</xsl:when> |
| 473 |
<!-- otherwise use the resource's id --> |
| 474 |
<xsl:when test="$ref.content/@xml:id"> |
| 475 |
<xsl:attribute name="xml:id"> |
| 476 |
<xsl:value-of select="$ref.content/@xml:id"/> |
| 477 |
</xsl:attribute> |
| 478 |
</xsl:when> |
| 479 |
</xsl:choose> |
| 480 |
|
| 481 |
<xsl:call-template name="merge.info"> |
| 482 |
<xsl:with-param name="merge.element" select="d:merge"/> |
| 483 |
<xsl:with-param name="ref.content" select="$ref.content"/> |
| 484 |
<xsl:with-param name="omittitles" select="$omittitles.property"/> |
| 485 |
</xsl:call-template> |
| 486 |
|
| 487 |
<!-- copy through all but titles, which moved to info --> |
| 488 |
<xsl:apply-templates select="$ref.content/node() |
| 489 |
[not(local-name() = 'title') and |
| 490 |
not(local-name() = 'subtitle') and |
| 491 |
not(local-name() = 'info') and |
| 492 |
not(local-name() = 'titleabbrev')]" mode="copycontent"/> |
| 493 |
|
| 494 |
<xsl:apply-templates> |
| 495 |
<xsl:with-param name="parent" select="$element.name"/> |
| 496 |
</xsl:apply-templates> |
| 497 |
</xsl:element> |
| 498 |
</xsl:otherwise> |
| 499 |
</xsl:choose> |
| 500 |
</xsl:otherwise> |
| 501 |
</xsl:choose> |
| 502 |
</xsl:template> |
| 503 |
|
| 504 |
<xsl:template name="merge.info"> |
| 505 |
<xsl:param name="merge.element" select="NOTANODE"/> |
| 506 |
<xsl:param name="ref.content" select="NOTANODE"/> |
| 507 |
<xsl:param name="omittitles"/> |
| 508 |
|
| 509 |
<!-- a merge element may use resourceref as well as literal content --> |
| 510 |
<!-- any literal content overrides the merge resourceref content --> |
| 511 |
<xsl:variable name="merge.ref.content"> |
| 512 |
<xsl:if test="$merge.element/@resourceref"> |
| 513 |
<xsl:variable name="resourceref" select="$merge.element/@resourceref"/> |
| 514 |
<xsl:variable name="resource" select="key('id', $resourceref)"/> |
| 515 |
|
| 516 |
<xsl:choose> |
| 517 |
<xsl:when test="not($resource)"> |
| 518 |
<xsl:message terminate="yes"> |
| 519 |
<xsl:text>ERROR: no xml:id matches @resourceref = '</xsl:text> |
| 520 |
<xsl:value-of select="$resourceref"/> |
| 521 |
<xsl:text>'.</xsl:text> |
| 522 |
</xsl:message> |
| 523 |
</xsl:when> |
| 524 |
<xsl:when test="not($resource/self::d:resource)"> |
| 525 |
<xsl:message terminate="yes"> |
| 526 |
<xsl:text>ERROR: xml:id matching @resourceref = '</xsl:text> |
| 527 |
<xsl:value-of select="$resourceref"/> |
| 528 |
<xsl:text> is not a resource element'.</xsl:text> |
| 529 |
</xsl:message> |
| 530 |
</xsl:when> |
| 531 |
</xsl:choose> |
| 532 |
|
| 533 |
<xsl:variable name="href.att" select="$resource/@fileref | $resource/@href"/> |
| 534 |
|
| 535 |
<xsl:variable name="fileref"> |
| 536 |
<xsl:choose> |
| 537 |
<xsl:when test="$resource/ancestor::d:resources/@xml:base"> |
| 538 |
<xsl:value-of |
| 539 |
select="concat($resource/ancestor::d:resources[@xml:base][1]/@xml:base, |
| 540 |
'/', $href.att)"/> |
| 541 |
</xsl:when> |
| 542 |
<xsl:otherwise> |
| 543 |
<xsl:value-of select="$href.att"/> |
| 544 |
</xsl:otherwise> |
| 545 |
</xsl:choose> |
| 546 |
</xsl:variable> |
| 547 |
|
| 548 |
<xsl:if test="string-length($fileref) != 0"> |
| 549 |
<xsl:copy-of select="document($fileref,/)"/> |
| 550 |
</xsl:if> |
| 551 |
</xsl:if> |
| 552 |
</xsl:variable> |
| 553 |
|
| 554 |
<xsl:variable name="merge.ref.info" |
| 555 |
select="exsl:node-set($merge.ref.content)//d:info[1]"/> |
| 556 |
|
| 557 |
<xsl:if test="$merge.element/@resourceref and not($merge.ref.info)"> |
| 558 |
<xsl:message terminate="yes"> |
| 559 |
<xsl:text>ERROR: merge element with resourceref '</xsl:text> |
| 560 |
<xsl:value-of select="$merge.element/@resourceref"/> |
| 561 |
<xsl:text>' must point to something with an info element.'</xsl:text> |
| 562 |
</xsl:message> |
| 563 |
</xsl:if> |
| 564 |
|
| 565 |
<xsl:variable name="omittitles.boolean"> |
| 566 |
<xsl:choose> |
| 567 |
<xsl:when test="$omittitles = 'yes' or $omittitles = 'true' or $omittitles = '1'"> |
| 568 |
<xsl:value-of select="1"/> |
| 569 |
</xsl:when> |
| 570 |
<xsl:otherwise> |
| 571 |
<xsl:value-of select="0"/> |
| 572 |
</xsl:otherwise> |
| 573 |
</xsl:choose> |
| 574 |
</xsl:variable> |
| 575 |
<!-- output info if there is any --> |
| 576 |
<xsl:if test="$merge.element/node() or |
| 577 |
$merge.ref.info/node() or |
| 578 |
$ref.content/d:info/node() or |
| 579 |
$ref.content/d:title[$omittitles.boolean = 0] or |
| 580 |
$ref.content/d:subtitle[$omittitles.boolean = 0] or |
| 581 |
$ref.content/d:titleabbrev[$omittitles.boolean = 0]"> |
| 582 |
|
| 583 |
<xsl:variable name="ref.info" select="$ref.content/d:info"/> |
| 584 |
<xsl:variable name="ref.title" select="$ref.content/d:title"/> |
| 585 |
<xsl:variable name="ref.subtitle" select="$ref.content/d:subtitle"/> |
| 586 |
<xsl:variable name="ref.titleabbrev" select="$ref.content/d:titleabbrev"/> |
| 587 |
<xsl:variable name="ref.info.title" select="$ref.content/d:info/d:title"/> |
| 588 |
<xsl:variable name="ref.info.subtitle" select="$ref.content/d:info/d:subtitle"/> |
| 589 |
<xsl:variable name="ref.info.titleabbrev" select="$ref.content/d:info/d:titleabbrev"/> |
| 590 |
|
| 591 |
<info> |
| 592 |
<!-- First copy through any merge attributes and elements and comments --> |
| 593 |
<xsl:copy-of select="$merge.element/@*[not(local-name(.) = 'resourceref')]"/> |
| 594 |
|
| 595 |
<!-- And copy any resource info attributes not in merge--> |
| 596 |
<xsl:for-each select="$ref.info/@*"> |
| 597 |
<xsl:variable name="resource.att" select="local-name(.)"/> |
| 598 |
<xsl:choose> |
| 599 |
<xsl:when test="$merge.element/@*[local-name(.) = $resource.att]"> |
| 600 |
<!-- do nothing because overridden --> |
| 601 |
</xsl:when> |
| 602 |
<xsl:otherwise> |
| 603 |
<!-- copy through if not overridden --> |
| 604 |
<xsl:copy-of select="."/> |
| 605 |
</xsl:otherwise> |
| 606 |
</xsl:choose> |
| 607 |
</xsl:for-each> |
| 608 |
|
| 609 |
<!-- Copy through the merge children as they have highest priority --> |
| 610 |
<xsl:copy-of select="$merge.element/node()"/> |
| 611 |
|
| 612 |
<!-- and copy through those merge resource elements not in merge element --> |
| 613 |
<xsl:for-each select="$merge.ref.info/node()"> |
| 614 |
<xsl:variable name="resource.node" select="local-name(.)"/> |
| 615 |
<xsl:choose> |
| 616 |
<xsl:when test="$merge.element/node()[local-name(.) = $resource.node]"> |
| 617 |
<!-- do nothing because overridden --> |
| 618 |
</xsl:when> |
| 619 |
<xsl:otherwise> |
| 620 |
<!-- copy through --> |
| 621 |
<xsl:copy-of select="."/> |
| 622 |
</xsl:otherwise> |
| 623 |
</xsl:choose> |
| 624 |
</xsl:for-each> |
| 625 |
|
| 626 |
<!-- And copy any module's resource info node not in merge or merge.ref --> |
| 627 |
<xsl:for-each select="$ref.info/node() | |
| 628 |
$ref.title[$omittitles.boolean = 0] | |
| 629 |
$ref.subtitle[$omittitles.boolean = 0] | |
| 630 |
$ref.titleabbrev[$omittitles.boolean = 0] | |
| 631 |
$ref.info.title[$omittitles.boolean = 0] | |
| 632 |
$ref.info.subtitle[$omittitles.boolean = 0] | |
| 633 |
$ref.info.titleabbrev[$omittitles.boolean = 0]"> |
| 634 |
<xsl:variable name="resource.node" select="local-name(.)"/> |
| 635 |
<xsl:choose> |
| 636 |
<xsl:when test="$merge.element/node()[local-name(.) = $resource.node]"> |
| 637 |
<!-- do nothing because overridden --> |
| 638 |
</xsl:when> |
| 639 |
<xsl:when test="$merge.ref.info/node()[local-name(.) = $resource.node]"> |
| 640 |
<!-- do nothing because overridden --> |
| 641 |
</xsl:when> |
| 642 |
<xsl:otherwise> |
| 643 |
<!-- copy through --> |
| 644 |
<xsl:copy-of select="."/> |
| 645 |
</xsl:otherwise> |
| 646 |
</xsl:choose> |
| 647 |
</xsl:for-each> |
| 648 |
|
| 649 |
</info> |
| 650 |
</xsl:if> |
| 651 |
</xsl:template> |
| 652 |
|
| 653 |
<xsl:template match="d:relationships"> |
| 654 |
<xsl:message> |
| 655 |
<xsl:text>WARNING: the <relationships> element is not currently </xsl:text> |
| 656 |
<xsl:text>supported by this stylesheet.</xsl:text> |
| 657 |
</xsl:message> |
| 658 |
</xsl:template> |
| 659 |
|
| 660 |
<xsl:template match="d:transforms"> |
| 661 |
<xsl:message> |
| 662 |
<xsl:text>WARNING: the <transforms> element is not currently </xsl:text> |
| 663 |
<xsl:text>supported by this stylesheet.</xsl:text> |
| 664 |
</xsl:message> |
| 665 |
</xsl:template> |
| 666 |
|
| 667 |
<xsl:template match="d:filterin"> |
| 668 |
<xsl:message> |
| 669 |
<xsl:text>WARNING: the <filterin> element is not currently </xsl:text> |
| 670 |
<xsl:text>supported by this stylesheet.</xsl:text> |
| 671 |
</xsl:message> |
| 672 |
</xsl:template> |
| 673 |
|
| 674 |
<xsl:template match="d:filterout"> |
| 675 |
<xsl:message> |
| 676 |
<xsl:text>WARNING: the <filterin> element is not currently </xsl:text> |
| 677 |
<xsl:text>supported by this stylesheet.</xsl:text> |
| 678 |
</xsl:message> |
| 679 |
</xsl:template> |
| 680 |
|
| 681 |
</xsl:stylesheet> |