assemble.xsl 25 KB

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