normalize.xsl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.txt file for applicable licenses.
  5. -->
  6. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  8. xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"
  9. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  10. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  11. exclude-result-prefixes="xs ditaarch dita-ot xsi"
  12. version="2.0">
  13. <xsl:param name="output.dir.uri"/>
  14. <xsl:template match="/">
  15. <xsl:for-each select="job/files/file[@format = ('dita', 'ditamap')]">
  16. <xsl:variable name="output.uri" select="concat($output.dir.uri, @uri)"/>
  17. <xsl:message select="$output.uri"/>
  18. <xsl:for-each select="document(@uri, .)">
  19. <xsl:choose>
  20. <xsl:when test="*/@xsi:noNamespaceSchemaLocation">
  21. <xsl:result-document href="{$output.uri}">
  22. <xsl:apply-templates/>
  23. </xsl:result-document>
  24. </xsl:when>
  25. <xsl:otherwise>
  26. <xsl:result-document href="{$output.uri}"
  27. doctype-public="{dita-ot:get-doctype-public(.)}"
  28. doctype-system="{dita-ot:get-doctype-system(.)}">
  29. <xsl:apply-templates/>
  30. </xsl:result-document>
  31. </xsl:otherwise>
  32. </xsl:choose>
  33. </xsl:for-each>
  34. </xsl:for-each>
  35. </xsl:template>
  36. <xsl:function name="dita-ot:get-doctype-public">
  37. <xsl:param name="doc" as="document-node()"/>
  38. <xsl:choose>
  39. <xsl:when test="$doc/processing-instruction('doctype-public')">
  40. <xsl:value-of select="$doc/processing-instruction('doctype-public')"/>
  41. </xsl:when>
  42. <xsl:otherwise>
  43. <xsl:text>-//OASIS//DTD DITA </xsl:text>
  44. <xsl:choose>
  45. <xsl:when test="$doc/dita">Composite</xsl:when>
  46. <xsl:when test="$doc/*[contains(@class, ' bookmap/bookmap ')]">BookMap</xsl:when>
  47. <xsl:otherwise>
  48. <xsl:value-of select="upper-case(substring(name($doc/*), 1, 1))"/>
  49. <xsl:value-of select="lower-case(substring(name($doc/*), 2))"/>
  50. </xsl:otherwise>
  51. </xsl:choose>
  52. <xsl:text>//EN</xsl:text>
  53. </xsl:otherwise>
  54. </xsl:choose>
  55. </xsl:function>
  56. <xsl:function name="dita-ot:get-doctype-system">
  57. <xsl:param name="doc" as="document-node()"/>
  58. <xsl:choose>
  59. <xsl:when test="$doc/processing-instruction('doctype-system')">
  60. <xsl:value-of select="$doc/processing-instruction('doctype-system')"/>
  61. </xsl:when>
  62. <xsl:otherwise>
  63. <xsl:value-of select="name($doc/*)"/>
  64. <xsl:text>.dtd</xsl:text>
  65. </xsl:otherwise>
  66. </xsl:choose>
  67. </xsl:function>
  68. <xsl:template match="@class | @domains | @xtrf | @xtrc | @ditaarch:DITAArchVersion"
  69. priority="10"/>
  70. <xsl:template match="processing-instruction('workdir') |
  71. processing-instruction('workdir-uri') |
  72. processing-instruction('path2project') |
  73. processing-instruction('path2project-uri') |
  74. processing-instruction('ditaot') |
  75. processing-instruction('doctype-public') |
  76. processing-instruction('doctype-system') |
  77. @dita-ot:* |
  78. @mapclass"
  79. priority="10"/>
  80. <xsl:template match="*[number(@ditaarch:DITAArchVersion) &lt; 1.3]/@cascade"/>
  81. <xsl:template match="*[@class]" priority="-5">
  82. <xsl:element name="{tokenize(tokenize(normalize-space(@class), '\s+')[last()], '/')[last()]}"
  83. namespace="{namespace-uri()}">
  84. <xsl:apply-templates select="node() | @*"/>
  85. </xsl:element>
  86. </xsl:template>
  87. <xsl:template match="*" priority="-10">
  88. <xsl:element name="{name()}" namespace="{namespace-uri()}">
  89. <xsl:apply-templates select="node() | @*"/>
  90. </xsl:element>
  91. </xsl:template>
  92. <xsl:template match="node() | @*" priority="-15">
  93. <xsl:copy>
  94. <xsl:apply-templates select="node() | @*"/>
  95. </xsl:copy>
  96. </xsl:template>
  97. </xsl:stylesheet>