html2dita.xsl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet version="2.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  5. xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"
  6. xmlns:x="https://github.com/jelovirt/dita-ot-markdown"
  7. xpath-default-namespace="http://www.w3.org/1999/xhtml"
  8. exclude-result-prefixes="xs x">
  9. <xsl:import href="classpath:///hdita2dita-common.xsl"/>
  10. <xsl:import href="classpath:///specialize.xsl"/>
  11. <xsl:output indent="yes"></xsl:output>
  12. <xsl:template match="/">
  13. <xsl:variable name="dita" as="element()">
  14. <xsl:apply-templates select="html"/>
  15. </xsl:variable>
  16. <xsl:apply-templates select="$dita" mode="dispatch"/>
  17. </xsl:template>
  18. <xsl:template match="html">
  19. <xsl:choose>
  20. <xsl:when test="count(body/article) gt 1">
  21. <dita>
  22. <xsl:attribute name="ditaarch:DITAArchVersion">1.3</xsl:attribute>
  23. <xsl:apply-templates select="@* | node()"/>
  24. </dita>
  25. </xsl:when>
  26. <xsl:otherwise>
  27. <xsl:apply-templates select="body"/>
  28. </xsl:otherwise>
  29. </xsl:choose>
  30. </xsl:template>
  31. <xsl:template match="article">
  32. <xsl:variable name="name" select="'topic'"/>
  33. <xsl:element name="{$name}">
  34. <xsl:apply-templates select="." mode="class"/>
  35. <xsl:apply-templates select="." mode="topic"/>
  36. <xsl:attribute name="ditaarch:DITAArchVersion">1.3</xsl:attribute>
  37. <xsl:apply-templates select="ancestor::*/@xml:lang"/>
  38. <xsl:apply-templates select="@*"/>
  39. <xsl:variable name="h" select="(h1, h2, h3, h4, h5, h6)[1]" as="element()?"/>
  40. <xsl:choose>
  41. <xsl:when test="@id">
  42. <xsl:apply-templates select="@id"/>
  43. </xsl:when>
  44. <xsl:otherwise>
  45. <xsl:sequence select="x:get-id(.)"/>
  46. </xsl:otherwise>
  47. </xsl:choose>
  48. <xsl:apply-templates select="$h"/>
  49. <body class="- topic/body ">
  50. <xsl:apply-templates select="* except ($h, article)"/>
  51. </body>
  52. <xsl:apply-templates select="article"/>
  53. </xsl:element>
  54. </xsl:template>
  55. </xsl:stylesheet>