topic-maker-chunk.xsl 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:exsl="http://exslt.org/common"
  3. xmlns:xlink="http://www.w3.org/1999/xlink"
  4. xmlns="http://docbook.org/ns/docbook"
  5. version="1.0"
  6. exclude-result-prefixes="exsl">
  7. <!-- ********************************************************************
  8. $Id: topic-maker-chunk.xsl,v 1.7 2012-04-16 00:29:35 bobs Exp $
  9. ********************************************************************
  10. -->
  11. <xsl:import href="topic-maker.xsl"/>
  12. <xsl:import href="../xhtml/chunk-common.xsl"/>
  13. <xsl:include href="../xhtml/chunk-code.xsl"/>
  14. <xsl:param name="root.id.suffix">-info</xsl:param>
  15. <xsl:param name="root.as.resourceref" select="1"/>
  16. <xsl:template match="/" priority="1">
  17. <xsl:apply-templates select="/" mode="process.root"/>
  18. <xsl:call-template name="make.assembly"/>
  19. </xsl:template>
  20. <xsl:template name="chunk-element-content">
  21. <xsl:param name="content">
  22. <xsl:apply-imports/>
  23. </xsl:param>
  24. <xsl:copy-of select="$content"/>
  25. </xsl:template>
  26. <xsl:template name="make.assembly">
  27. <xsl:variable name="content">
  28. <assembly xmlns:xlink="http://www.w3.org/1999/xlink">
  29. <xsl:call-template name="make.resources"/>
  30. <xsl:call-template name="make.structure"/>
  31. </assembly>
  32. </xsl:variable>
  33. <xsl:variable name="filename">
  34. <xsl:if test="$manifest.in.base.dir != 0">
  35. <xsl:value-of select="$base.dir"/>
  36. </xsl:if>
  37. <xsl:value-of select="$assembly.filename"/>
  38. </xsl:variable>
  39. <xsl:call-template name="write.chunk">
  40. <xsl:with-param name="content" select="$content"/>
  41. <xsl:with-param name="filename" select="$filename"/>
  42. <xsl:with-param name="indent">yes</xsl:with-param>
  43. </xsl:call-template>
  44. </xsl:template>
  45. <xsl:template name="make.structure">
  46. <xsl:param name="root" select="/*[1]"/>
  47. <xsl:param name="root.resourceref">
  48. <xsl:call-template name="object.id">
  49. <xsl:with-param name="object" select="$root"/>
  50. </xsl:call-template>
  51. </xsl:param>
  52. <xsl:choose>
  53. <xsl:when test="$root.as.resourceref = 0">
  54. <structure>
  55. <xsl:attribute name="type">
  56. <xsl:value-of select="local-name($root)"/>
  57. </xsl:attribute>
  58. <xsl:attribute name="xml:id">
  59. <xsl:value-of select="$root.resourceref"/>
  60. </xsl:attribute>
  61. <xsl:copy-of select="($root/title | $root/info/title)[1]"/>
  62. <!-- Put the title and info stuff in a content-only module -->
  63. <module resourceref="{$root.resourceref}{$root.id.suffix}" contentonly="true"/>
  64. <xsl:apply-templates select="$root/*" mode="module.list"/>
  65. </structure>
  66. </xsl:when>
  67. <xsl:otherwise>
  68. <structure>
  69. <xsl:attribute name="resourceref">
  70. <xsl:value-of select="$root.resourceref"/>
  71. </xsl:attribute>
  72. <output renderas="{local-name($root)}"/>
  73. <xsl:apply-templates select="$root/*" mode="module.list"/>
  74. </structure>
  75. </xsl:otherwise>
  76. </xsl:choose>
  77. </xsl:template>
  78. <xsl:template match="*" mode="module.list">
  79. <xsl:variable name="is.chunk">
  80. <xsl:call-template name="chunk">
  81. <xsl:with-param name="node" select="."/>
  82. </xsl:call-template>
  83. </xsl:variable>
  84. <!-- generate an output element for renderas? -->
  85. <xsl:variable name="src.element" select="concat(' ', local-name(.), ' ')"/>
  86. <xsl:variable name="is.topic">
  87. <xsl:choose>
  88. <xsl:when test="contains($topic.list, $src.element)">1</xsl:when>
  89. <xsl:otherwise>0</xsl:otherwise>
  90. </xsl:choose>
  91. </xsl:variable>
  92. <xsl:if test="$is.chunk = 1">
  93. <module>
  94. <xsl:attribute name="resourceref">
  95. <xsl:call-template name="object.id"/>
  96. </xsl:attribute>
  97. <xsl:if test="$is.topic = 1">
  98. <output renderas="{local-name()}"/>
  99. </xsl:if>
  100. <xsl:apply-templates select="*" mode="module.list"/>
  101. </module>
  102. </xsl:if>
  103. </xsl:template>
  104. <xsl:template name="make.resources">
  105. <resources>
  106. <!-- Add xml:base from $base.dir if manifest not in base.dir -->
  107. <xsl:if test="string-length($base.dir) != 0 and
  108. $manifest.in.base.dir = 0">
  109. <xsl:attribute name="xml:base">
  110. <!-- strip off trailing slash for xml:base -->
  111. <xsl:choose>
  112. <xsl:when test="substring($base.dir, string-length($base.dir),1) = '/'">
  113. <xsl:value-of select="substring($base.dir, 1, string-length($base.dir) -1)"/>
  114. </xsl:when>
  115. <xsl:otherwise>
  116. <xsl:value-of select="$base.dir"/>
  117. </xsl:otherwise>
  118. </xsl:choose>
  119. </xsl:attribute>
  120. </xsl:if>
  121. <xsl:apply-templates select="/*[1]" mode="resource.list"/>
  122. </resources>
  123. </xsl:template>
  124. <xsl:template match="*" mode="resource.list">
  125. <xsl:variable name="is.chunk">
  126. <xsl:call-template name="chunk">
  127. <xsl:with-param name="node" select="."/>
  128. </xsl:call-template>
  129. </xsl:variable>
  130. <xsl:if test="$is.chunk = 1">
  131. <resource>
  132. <xsl:attribute name="fileref">
  133. <!--
  134. <xsl:if test="$manifest.in.base.dir = 0">
  135. <xsl:value-of select="$base.dir"/>
  136. </xsl:if>
  137. -->
  138. <xsl:apply-templates select="." mode="chunk-filename"/>
  139. </xsl:attribute>
  140. <xsl:attribute name="xml:id">
  141. <xsl:call-template name="object.id"/>
  142. </xsl:attribute>
  143. <xsl:variable name="title">
  144. <xsl:apply-templates select="." mode="title.markup"/>
  145. </xsl:variable>
  146. <xsl:if test="string-length($title) != 0">
  147. <description>
  148. <xsl:value-of select="$title"/>
  149. </description>
  150. </xsl:if>
  151. </resource>
  152. </xsl:if>
  153. <xsl:apply-templates select="*" mode="resource.list"/>
  154. </xsl:template>
  155. <!-- special case for root id on structure element -->
  156. <xsl:template match="/*" mode="resource.list">
  157. <xsl:param name="root.resourceref">
  158. <xsl:call-template name="object.id">
  159. <xsl:with-param name="object" select="."/>
  160. </xsl:call-template>
  161. </xsl:param>
  162. <resource>
  163. <xsl:attribute name="fileref">
  164. <xsl:apply-templates select="." mode="chunk-filename"/>
  165. </xsl:attribute>
  166. <xsl:attribute name="xml:id">
  167. <xsl:choose>
  168. <xsl:when test="$root.as.resourceref = 0">
  169. <xsl:value-of select="concat($root.resourceref,$root.id.suffix)"/>
  170. </xsl:when>
  171. <xsl:otherwise>
  172. <xsl:value-of select="$root.resourceref"/>
  173. </xsl:otherwise>
  174. </xsl:choose>
  175. </xsl:attribute>
  176. </resource>
  177. <xsl:apply-templates select="*" mode="resource.list"/>
  178. </xsl:template>
  179. <!-- This one must be here because of the template in chunk-code.xsl -->
  180. <xsl:template match="@fileref" priority="1">
  181. <xsl:copy-of select="."/>
  182. </xsl:template>
  183. </xsl:stylesheet>