dita2xhtml-util.xsl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. This file is part of the DITA Open Toolkit project.
  4. See the accompanying LICENSE file for
  5. applicable licenses.-->
  6. <!--
  7. This file is part of the DITA Open Toolkit project.
  8. Copyright 2013 Jarno Elovirta
  9. See the accompanying LICENSE file for applicable license.
  10. -->
  11. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  12. version="2.0">
  13. <xsl:template match="/">
  14. <xsl:variable name="content" as="node()*">
  15. <xsl:apply-imports/>
  16. </xsl:variable>
  17. <xsl:apply-templates select="$content" mode="add-xhtml-ns"/>
  18. </xsl:template>
  19. <xsl:template match="*[namespace-uri() eq '']" mode="add-xhtml-ns" priority="10">
  20. <xsl:element name="{name()}" namespace="http://www.w3.org/1999/xhtml">
  21. <xsl:apply-templates select="@* | node()" mode="add-xhtml-ns"/>
  22. </xsl:element>
  23. </xsl:template>
  24. <xsl:template match="nav | section | figure | article" mode="add-xhtml-ns" priority="20">
  25. <xsl:element name="div" namespace="http://www.w3.org/1999/xhtml">
  26. <xsl:apply-templates select="@* except @role | node()" mode="add-xhtml-ns"/>
  27. </xsl:element>
  28. </xsl:template>
  29. <!-- Group for root document node does not need extra XHTML div -->
  30. <xsl:template match="main/article" mode="add-xhtml-ns" priority="30">
  31. <xsl:apply-templates select="node()" mode="add-xhtml-ns"/>
  32. </xsl:template>
  33. <xsl:template match="header | footer | main" mode="add-xhtml-ns" priority="20">
  34. <xsl:apply-templates select="node()" mode="add-xhtml-ns"/>
  35. </xsl:template>
  36. <xsl:template match="div/@role" mode="add-xhtml-ns" priority="10"/>
  37. <xsl:template match="@*[starts-with(name(), 'data-')]" mode="add-xhtml-ns" priority="10"/>
  38. <xsl:template match="@* | node()" mode="add-xhtml-ns">
  39. <xsl:copy>
  40. <xsl:apply-templates select="@* | node()" mode="add-xhtml-ns"/>
  41. </xsl:copy>
  42. </xsl:template>
  43. </xsl:stylesheet>