hdita2dita-common.xsl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4. xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"
  5. xmlns:x="https://github.com/jelovirt/dita-ot-markdown"
  6. exclude-result-prefixes="xs x"
  7. xpath-default-namespace="http://www.w3.org/1999/xhtml"
  8. version="2.0">
  9. <!-- Topic -->
  10. <xsl:template match="html">
  11. <xsl:choose>
  12. <xsl:when test="count(body/article) gt 1">
  13. <dita>
  14. <xsl:attribute name="ditaarch:DITAArchVersion">1.3</xsl:attribute>
  15. <xsl:apply-templates select="@* | node()"/>
  16. </dita>
  17. </xsl:when>
  18. <xsl:otherwise>
  19. <xsl:apply-templates select="body"/>
  20. </xsl:otherwise>
  21. </xsl:choose>
  22. </xsl:template>
  23. <xsl:template match="head"/>
  24. <xsl:template match="body">
  25. <xsl:apply-templates select="*"/>
  26. </xsl:template>
  27. <xsl:template match="article">
  28. <xsl:variable name="name" select="(:if (@data-hd-class) then @data-hd-class else :)'topic'"/>
  29. <xsl:element name="{$name}">
  30. <xsl:apply-templates select="." mode="class"/>
  31. <xsl:apply-templates select="." mode="topic"/>
  32. <xsl:attribute name="ditaarch:DITAArchVersion">1.3</xsl:attribute>
  33. <xsl:apply-templates select="ancestor::*/@xml:lang"/>
  34. <xsl:apply-templates select="@*"/>
  35. <xsl:variable name="h" select="(h1, h2, h3, h4, h5, h6)[1]" as="element()?"/>
  36. <xsl:choose>
  37. <xsl:when test="@id">
  38. <xsl:apply-templates select="@id"/>
  39. </xsl:when>
  40. <xsl:otherwise>
  41. <xsl:sequence select="x:get-id(.)"/>
  42. </xsl:otherwise>
  43. </xsl:choose>
  44. <xsl:apply-templates select="$h"/>
  45. <xsl:variable name="contents" select="* except ($h, article)" as="element()*"/>
  46. <xsl:variable name="shortdesc" select="$contents[1]/self::p" as="element()?"/>
  47. <xsl:if test="$shortdesc">
  48. <shortdesc class="- topic/shortdesc ">
  49. <xsl:apply-templates select="$shortdesc/node()"/>
  50. </shortdesc>
  51. </xsl:if>
  52. <!--xsl:if test="$contents except $shortdesc"-->
  53. <body class="- topic/body ">
  54. <xsl:apply-templates select="$contents except $shortdesc"/>
  55. </body>
  56. <!--/xsl:if-->
  57. <xsl:apply-templates select="article"/>
  58. </xsl:element>
  59. </xsl:template>
  60. <xsl:function name="x:get-id" as="attribute()?">
  61. <xsl:param name="topic" as="element()"/>
  62. <xsl:variable name="title" select="($topic/h1 | $topic/h2 | $topic/h3 | $topic/h4 | $topic/h5 | $topic/h6)[1]" as="element()?"/>
  63. <xsl:if test="$title">
  64. <xsl:attribute name="id" select="translate(normalize-space(lower-case($title)), ' .', '-')"/>
  65. </xsl:if>
  66. </xsl:function>
  67. <xsl:template match="article" mode="class">
  68. <xsl:attribute name="class">
  69. <xsl:text>- topic/topic </xsl:text>
  70. <!--
  71. <xsl:if test="@data-hd-class">
  72. <xsl:value-of select="concat(@data-hd-class, '/', @data-hd-class, ' ')"/>
  73. </xsl:if>
  74. -->
  75. </xsl:attribute>
  76. </xsl:template>
  77. <!--
  78. <xsl:template match="article[@data-hd-class = 'concept']" mode="class">
  79. <xsl:attribute name="class">- topic/topic concept/concept </xsl:attribute>
  80. </xsl:template>
  81. <xsl:template match="article[@data-hd-class = 'task']" mode="class">
  82. <xsl:attribute name="class">- topic/topic task/task </xsl:attribute>
  83. </xsl:template>
  84. <xsl:template match="article[@data-hd-class = 'reference']" mode="class">
  85. <xsl:attribute name="class">- topic/topic reference/reference </xsl:attribute>
  86. </xsl:template>
  87. -->
  88. <xsl:template match="article" mode="topic">
  89. <xsl:attribute name="domains">(topic abbrev-d) a(props deliveryTarget) (topic equation-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic mathml-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic svg-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d)</xsl:attribute>
  90. </xsl:template>
  91. <!--
  92. <xsl:template match="article[@data-hd-class = 'concept']" mode="topic">
  93. <xsl:attribute name="domains">(topic abbrev-d) a(props deliveryTarget) (topic equation-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic mathml-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic svg-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d)</xsl:attribute>
  94. </xsl:template>
  95. <xsl:template match="article[@data-hd-class = 'task']" mode="topic">
  96. <xsl:attribute name="domains">(topic concept) (topic abbrev-d) a(props deliveryTarget) (topic equation-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic mathml-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic svg-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d)</xsl:attribute>
  97. </xsl:template>
  98. <xsl:template match="article[@data-hd-class = 'reference']" mode="topic">
  99. <xsl:attribute name="domains">(topic reference) (topic abbrev-d) a(props deliveryTarget) (topic equation-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic mathml-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic svg-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d)</xsl:attribute>
  100. </xsl:template>
  101. -->
  102. <xsl:template match="section">
  103. <xsl:variable name="name" select="(:if (@data-hd-class = 'topic/example') then 'example' else :)'section'"/>
  104. <xsl:element name="{$name}">
  105. <xsl:apply-templates select="." mode="class"/>
  106. <xsl:apply-templates select="@*"/>
  107. <xsl:if test="empty(@id)">
  108. <xsl:sequence select="x:get-id(.)"/>
  109. </xsl:if>
  110. <xsl:apply-templates select="*"/>
  111. </xsl:element>
  112. </xsl:template>
  113. <xsl:template match="section" mode="class">
  114. <xsl:attribute name="class">
  115. <!--
  116. <xsl:choose>
  117. <xsl:when test="@data-hd-class = 'topic/example'">
  118. <xsl:text>- topic/example </xsl:text>
  119. </xsl:when>
  120. <xsl:when test="contains(@data-hd-class, '/')">
  121. <xsl:text>- topic/section </xsl:text>
  122. <xsl:value-of select="concat(@data-hd-class, '/', @data-hd-class)"/>
  123. <xsl:text> </xsl:text>
  124. </xsl:when>
  125. <xsl:otherwise>
  126. -->
  127. <xsl:text>- topic/section </xsl:text>
  128. <!--
  129. </xsl:otherwise>
  130. </xsl:choose>
  131. -->
  132. </xsl:attribute>
  133. </xsl:template>
  134. <xsl:template match="h1 | h2 | h3 | h4 | h5 | h6">
  135. <title>
  136. <xsl:apply-templates select="." mode="class"/>
  137. <xsl:apply-templates select="@* except @id | node()"/>
  138. </title>
  139. </xsl:template>
  140. <xsl:template match="h1 | h2 | h3 | h4 | h5 | h6" mode="class">
  141. <xsl:attribute name="class">- topic/title </xsl:attribute>
  142. </xsl:template>
  143. <xsl:template match="dl">
  144. <xsl:element name="{name()}">
  145. <xsl:apply-templates select="." mode="class"/>
  146. <xsl:apply-templates select="@*"/>
  147. <xsl:for-each-group select="*" group-starting-with="dt[empty(preceding-sibling::*[1]/self::dt)]">
  148. <dlentry class="- topic/dlentry ">
  149. <xsl:apply-templates select="current-group()"/>
  150. </dlentry>
  151. </xsl:for-each-group>
  152. </xsl:element>
  153. </xsl:template>
  154. <xsl:template match="dd">
  155. <dd>
  156. <xsl:apply-templates select="." mode="class"/>
  157. <xsl:apply-templates select="@*"/>
  158. <xsl:variable name="first-block" select="(*[x:is-html-block(.)])[1]" as="element()?"/>
  159. <xsl:choose>
  160. <xsl:when test="empty($first-block)">
  161. <p class="- topic/p ">
  162. <xsl:apply-templates select="node()"/>
  163. </p>
  164. </xsl:when>
  165. <xsl:when test="exists($first-block) and $first-block/preceding-sibling::node()[not(self::text()[not(normalize-space(.))])]">
  166. <p class="- topic/p ">
  167. <xsl:apply-templates select="$first-block/preceding-sibling::node()"/>
  168. </p>
  169. <xsl:apply-templates select="$first-block | $first-block/following-sibling::node()"/>
  170. </xsl:when>
  171. <xsl:otherwise>
  172. <xsl:apply-templates select="node()"/>
  173. </xsl:otherwise>
  174. </xsl:choose>
  175. </dd>
  176. </xsl:template>
  177. <xsl:function name="x:is-html-block" as="xs:boolean">
  178. <xsl:param name="node" as="node()?"/>
  179. <xsl:sequence select="exists(
  180. $node/self::address |
  181. $node/self::article |
  182. $node/self::aside |
  183. $node/self::blockquote |
  184. $node/self::canvas |
  185. $node/self::dd |
  186. $node/self::div |
  187. $node/self::dl |
  188. $node/self::dt |
  189. $node/self::fieldset |
  190. $node/self::figcaption |
  191. $node/self::figure |
  192. $node/self::figcaption |
  193. $node/self::footer |
  194. $node/self::form |
  195. $node/self::h1 |
  196. $node/self::h2 |
  197. $node/self::h3 |
  198. $node/self::h4 |
  199. $node/self::h5 |
  200. $node/self::h6 |
  201. $node/self::header |
  202. $node/self::hgroup |
  203. $node/self::hr |
  204. $node/self::li |
  205. $node/self::main |
  206. $node/self::nav |
  207. $node/self::noscript |
  208. $node/self::ol |
  209. $node/self::output |
  210. $node/self::p |
  211. $node/self::pre |
  212. $node/self::section |
  213. $node/self::table |
  214. $node/self::tfoot |
  215. $node/self::ul |
  216. $node/self::video
  217. )"/>
  218. </xsl:function>
  219. <xsl:template match="@xml:lang">
  220. <xsl:attribute name="lang" select="."/>
  221. </xsl:template>
  222. <xsl:template match="figure">
  223. <fig>
  224. <xsl:apply-templates select="." mode="class"/>
  225. <xsl:apply-templates select="@*"/>
  226. <xsl:apply-templates select="figcaption"/>
  227. <xsl:apply-templates select="node() except figcaption"/>
  228. </fig>
  229. </xsl:template>
  230. <xsl:template match="figure" mode="class">
  231. <xsl:attribute name="class">- topic/fig </xsl:attribute>
  232. </xsl:template>
  233. <xsl:template match="pre">
  234. <pre>
  235. <xsl:apply-templates select="." mode="class"/>
  236. <xsl:attribute name="xml:space">preserve</xsl:attribute>
  237. <xsl:apply-templates select="@* | node()"/>
  238. </pre>
  239. </xsl:template>
  240. <xsl:template match="pre" mode="class">
  241. <xsl:attribute name="class">- topic/pre </xsl:attribute>
  242. </xsl:template>
  243. <xsl:template match="pre[code]">
  244. <codeblock>
  245. <xsl:apply-templates select="." mode="class"/>
  246. <xsl:attribute name="xml:space">preserve</xsl:attribute>
  247. <xsl:apply-templates select="@* | code/node()"/>
  248. </codeblock>
  249. </xsl:template>
  250. <xsl:template match="pre[code]" mode="class">
  251. <xsl:attribute name="class">+ topic/pre pr-d/codeblock </xsl:attribute>
  252. </xsl:template>
  253. <xsl:template match="img">
  254. <image>
  255. <xsl:apply-templates select="." mode="class"/>
  256. <xsl:apply-templates select="@* except @alt"/>
  257. <xsl:apply-templates select="." mode="image-placement"/>
  258. <xsl:if test="@alt">
  259. <alt class="- topic/alt ">
  260. <xsl:value-of select="@alt"/>
  261. </alt>
  262. </xsl:if>
  263. </image>
  264. </xsl:template>
  265. <xsl:template match="article/img | section/img" mode="image-placement">
  266. <xsl:attribute name="placement">break</xsl:attribute>
  267. </xsl:template>
  268. <xsl:template match="node()" mode="image-placement" priority="-10"/>
  269. <xsl:template match="img" mode="class">
  270. <xsl:attribute name="class">- topic/image </xsl:attribute>
  271. </xsl:template>
  272. <xsl:template match="img/@src">
  273. <xsl:attribute name="href" select="."/>
  274. </xsl:template>
  275. <xsl:template match="table">
  276. <xsl:variable name="cols" as="xs:integer" select="max(descendant::tr/count(*))"/>
  277. <table>
  278. <xsl:apply-templates select="." mode="class"/>
  279. <xsl:apply-templates select="@* | caption"/>
  280. <tgroup class="- topic/tgroup " cols="{$cols}">
  281. <xsl:for-each select="1 to $cols">
  282. <colspec class="- topic/colspec " colname="col{.}"/>
  283. </xsl:for-each>
  284. <xsl:choose>
  285. <xsl:when test="tr[1][th and empty(td)]">
  286. <thead class="- topic/thead ">
  287. <xsl:apply-templates select="tr[1]"/>
  288. </thead>
  289. <tbody class="- topic/tbody ">
  290. <xsl:apply-templates select="tr[position() ne 1]"/>
  291. </tbody>
  292. </xsl:when>
  293. <xsl:when test="tr">
  294. <tbody class="- topic/tbody ">
  295. <xsl:apply-templates select="tr"/>
  296. </tbody>
  297. </xsl:when>
  298. <xsl:otherwise>
  299. <xsl:apply-templates select="thead | tbody"/>
  300. </xsl:otherwise>
  301. </xsl:choose>
  302. </tgroup>
  303. </table>
  304. </xsl:template>
  305. <xsl:template match="table/caption | figcaption">
  306. <title>
  307. <xsl:apply-templates select="." mode="class"/>
  308. <xsl:apply-templates select="@* | node()"/>
  309. </title>
  310. </xsl:template>
  311. <xsl:template match="table/caption | figcaption" mode="class">
  312. <xsl:attribute name="class">- topic/title </xsl:attribute>
  313. </xsl:template>
  314. <xsl:template match="tr">
  315. <row>
  316. <xsl:apply-templates select="." mode="class"/>
  317. <xsl:apply-templates select="@* | node()"/>
  318. </row>
  319. </xsl:template>
  320. <xsl:template match="tr" mode="class">
  321. <xsl:attribute name="class">- topic/row </xsl:attribute>
  322. </xsl:template>
  323. <xsl:template match="td | th">
  324. <entry>
  325. <xsl:apply-templates select="." mode="class"/>
  326. <xsl:apply-templates select="@* | node()"/>
  327. </entry>
  328. </xsl:template>
  329. <xsl:template match="td | th" mode="class">
  330. <xsl:attribute name="class">- topic/entry </xsl:attribute>
  331. </xsl:template>
  332. <xsl:template match="@rowspan">
  333. <xsl:attribute name="morerows" select="xs:integer(.) - 1"/>
  334. </xsl:template>
  335. <!--
  336. <xsl:template match="*[@data-hd-class = 'topic/example']" mode="class">
  337. <xsl:attribute name="class">- topic/example </xsl:attribute>
  338. </xsl:template>
  339. -->
  340. <xsl:template match="br">
  341. <xsl:processing-instruction name="linebreak"/>
  342. </xsl:template>
  343. <xsl:template match="b | strong" mode="class">
  344. <xsl:attribute name="class">+ topic/ph hi-d/b </xsl:attribute>
  345. </xsl:template>
  346. <xsl:template match="i | em" mode="class">
  347. <xsl:attribute name="class">+ topic/ph hi-d/i </xsl:attribute>
  348. </xsl:template>
  349. <xsl:template match="u" mode="class">
  350. <xsl:attribute name="class">+ topic/ph hi-d/u </xsl:attribute>
  351. </xsl:template>
  352. <xsl:template match="span">
  353. <ph>
  354. <xsl:apply-templates select="." mode="class"/>
  355. <xsl:apply-templates select="@* | node()"/>
  356. </ph>
  357. </xsl:template>
  358. <xsl:template match="span" mode="class">
  359. <xsl:attribute name="class">- topic/ph </xsl:attribute>
  360. </xsl:template>
  361. <xsl:template match="@data-keyref">
  362. <xsl:attribute name="keyref" select="."/>
  363. </xsl:template>
  364. <xsl:template match="strong">
  365. <b>
  366. <xsl:apply-templates select="." mode="class"/>
  367. <xsl:apply-templates select="@* | node()"/>
  368. </b>
  369. </xsl:template>
  370. <xsl:template match="em">
  371. <i>
  372. <xsl:apply-templates select="." mode="class"/>
  373. <xsl:apply-templates select="@* | node()"/>
  374. </i>
  375. </xsl:template>
  376. <xsl:template match="sup">
  377. <sup>
  378. <xsl:apply-templates select="." mode="class"/>
  379. <xsl:apply-templates select="@* | node()"/>
  380. </sup>
  381. </xsl:template>
  382. <xsl:template match="sup" mode="class">
  383. <xsl:attribute name="class">+ topic/ph hi-d/sup </xsl:attribute>
  384. </xsl:template>
  385. <xsl:template match="sub">
  386. <sub>
  387. <xsl:apply-templates select="." mode="class"/>
  388. <xsl:apply-templates select="@* | node()"/>
  389. </sub>
  390. </xsl:template>
  391. <xsl:template match="sub" mode="class">
  392. <xsl:attribute name="class">+ topic/ph hi-d/sub </xsl:attribute>
  393. </xsl:template>
  394. <xsl:template match="a">
  395. <xsl:variable name="href" select="lower-case(if (contains(@href, '#')) then substring-before(@href, '#') else @href)"/>
  396. <xref>
  397. <xsl:apply-templates select="." mode="class"/>
  398. <xsl:if test="@data-keyref">
  399. <xsl:attribute name="keyref" select="@data-keyref"/>
  400. </xsl:if>
  401. <xsl:choose>
  402. <xsl:when test="starts-with(@href, 'mailto')">
  403. <xsl:attribute name="format">email</xsl:attribute>
  404. <xsl:attribute name="scope">external</xsl:attribute>
  405. </xsl:when>
  406. <xsl:when test="@type">
  407. <xsl:attribute name="format" select="@type"/>
  408. </xsl:when>
  409. <xsl:when test="ends-with($href, '.md')">
  410. <xsl:attribute name="format">markdown</xsl:attribute>
  411. </xsl:when>
  412. <xsl:when test="ends-with($href, '.dita') or ends-with($href, '.xml')"/>
  413. <xsl:when test="@href">
  414. <xsl:attribute name="format">
  415. <xsl:variable name="path" select="if (contains($href, '://'))
  416. then tokenize(substring-after($href, '://'), '/')[position() gt 1]
  417. else tokenize($href, '/')"/>
  418. <xsl:variable name="file" select="$path[position() eq last()]"/>
  419. <xsl:value-of select="if (matches($file, '^.+\.(\w+?)$'))
  420. then replace($file, '^.+\.(\w+?)$', '$1')
  421. else 'html'"/>
  422. </xsl:attribute>
  423. </xsl:when>
  424. </xsl:choose>
  425. <xsl:if test="matches(@href, '^https?://', 'i')">
  426. <xsl:attribute name="scope">external</xsl:attribute>
  427. </xsl:if>
  428. <xsl:apply-templates select="@* | node()"/>
  429. </xref>
  430. </xsl:template>
  431. <xsl:template match="a" mode="class">
  432. <xsl:attribute name="class">- topic/xref </xsl:attribute>
  433. </xsl:template>
  434. <xsl:template match="a/@target"/>
  435. <xsl:template match="del">
  436. <ph>
  437. <xsl:apply-templates select="." mode="class"/>
  438. <xsl:attribute name="status">deleted</xsl:attribute>
  439. <xsl:apply-templates select="@* | node()"/>
  440. </ph>
  441. </xsl:template>
  442. <xsl:template match="del" mode="class">
  443. <xsl:attribute name="class">- topic/ph </xsl:attribute>
  444. </xsl:template>
  445. <xsl:template match="code">
  446. <codeph>
  447. <xsl:apply-templates select="." mode="class"/>
  448. <xsl:apply-templates select="@* | node()"/>
  449. </codeph>
  450. </xsl:template>
  451. <xsl:template match="code" mode="class">
  452. <xsl:attribute name="class">+ topic/ph pr-d/codeph </xsl:attribute>
  453. </xsl:template>
  454. <!-- HDITA -->
  455. <xsl:template match="audio" mode="class">
  456. <xsl:attribute name="class">+ topic/object h5m-d/audio </xsl:attribute>
  457. </xsl:template>
  458. <xsl:template match="video" mode="class">
  459. <xsl:attribute name="class">+ topic/object h5m-d/video </xsl:attribute>
  460. </xsl:template>
  461. <xsl:template match="fallback" mode="class">
  462. <xsl:attribute name="class">+ topic/desc h5m-d/fallback </xsl:attribute>
  463. </xsl:template>
  464. <xsl:template match="controls" mode="class">
  465. <xsl:attribute name="class">+ topic/param h5m-d/controls </xsl:attribute>
  466. <xsl:attribute name="name" select="local-name()"/>
  467. </xsl:template>
  468. <xsl:template match="poster" mode="class">
  469. <xsl:attribute name="class">+ topic/param h5m-d/poster </xsl:attribute>
  470. <xsl:attribute name="name" select="local-name()"/>
  471. </xsl:template>
  472. <xsl:template match="source" mode="class">
  473. <xsl:attribute name="class">+ topic/param h5m-d/source </xsl:attribute>
  474. <xsl:attribute name="name" select="local-name()"/>
  475. </xsl:template>
  476. <xsl:template match="track" mode="class">
  477. <xsl:attribute name="class">+ topic/param h5m-d/track </xsl:attribute>
  478. <xsl:attribute name="name" select="local-name()"/>
  479. </xsl:template>
  480. <!-- Map -->
  481. <xsl:template match="nav">
  482. <map>
  483. <xsl:apply-templates select="." mode="class"/>
  484. <xsl:apply-templates select="." mode="topic"/>
  485. <xsl:attribute name="ditaarch:DITAArchVersion">1.3</xsl:attribute>
  486. <xsl:apply-templates select="ancestor::*/@xml:lang"/>
  487. <xsl:apply-templates select="@* | node()"/>
  488. </map>
  489. </xsl:template>
  490. <xsl:template match="nav" mode="class">
  491. <xsl:attribute name="class">- map/map </xsl:attribute>
  492. </xsl:template>
  493. <xsl:template match="nav/h1">
  494. <topicmeta class="- map/topicmeta ">
  495. <navtitle class="- map/navtitle ">
  496. <xsl:apply-templates select="@* | node()"/>
  497. </navtitle>
  498. </topicmeta>
  499. </xsl:template>
  500. <xsl:template match="nav//ul | nav//ol">
  501. <xsl:apply-templates/>
  502. </xsl:template>
  503. <xsl:template match="nav//li">
  504. <topicref class="- map/topicref ">
  505. <topicmeta class="- map/topicmeta ">
  506. <navtitle class="- map/navtitle ">
  507. <xsl:apply-templates select="node() except (ol | ul)"/>
  508. </navtitle>
  509. </topicmeta>
  510. <xsl:apply-templates select="ol | ul"/>
  511. </topicref>
  512. </xsl:template>
  513. <!-- Common -->
  514. <xsl:template match="@class">
  515. <xsl:attribute name="outputclass" select="."/>
  516. </xsl:template>
  517. <!--
  518. <xsl:template match="*[@data-hd-class]" mode="class" priority="-5">
  519. <xsl:attribute name="class">
  520. <xsl:text>- </xsl:text>
  521. <xsl:value-of select="@data-hd-class"/>
  522. <xsl:text> </xsl:text>
  523. </xsl:attribute>
  524. </xsl:template>
  525. -->
  526. <xsl:template match="*" mode="class" priority="-10">
  527. <xsl:attribute name="class">
  528. <xsl:text>- topic/</xsl:text>
  529. <xsl:value-of select="local-name()"/>
  530. <xsl:text> </xsl:text>
  531. </xsl:attribute>
  532. </xsl:template>
  533. <xsl:template match="@* | node()" mode="class" priority="-15"/>
  534. <xsl:template match="*" priority="-10">
  535. <xsl:element name="{name()}">
  536. <xsl:apply-templates select="." mode="class"/>
  537. <xsl:apply-templates select="@* | node()"/>
  538. </xsl:element>
  539. </xsl:template>
  540. <xsl:template match="@* | node()" priority="-15">
  541. <xsl:copy>
  542. <xsl:apply-templates select="@* | node()"/>
  543. </xsl:copy>
  544. </xsl:template>
  545. <xsl:template match="@data-hd-class" priority="10"/>
  546. <xsl:template match="@data-conref" priority="10">
  547. <xsl:attribute name="conref" select="."/>
  548. </xsl:template>
  549. <xsl:template match="@data-conkeyref" priority="10">
  550. <xsl:attribute name="conkeyref" select="."/>
  551. </xsl:template>
  552. </xsl:stylesheet>