xsl2profile.xsl 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xslo="http://www.w3.org/1999/XSL/TransformAlias"
  4. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  5. exclude-result-prefixes="fo"
  6. version="1.0">
  7. <xsl:include href="../lib/lib.xsl"/>
  8. <xsl:output method="xml" encoding="US-ASCII"/>
  9. <xsl:namespace-alias stylesheet-prefix="xslo" result-prefix="xsl"/>
  10. <xsl:preserve-space elements="*"/>
  11. <xsl:template match="/">
  12. <xsl:text>&#10;</xsl:text>
  13. <xsl:comment>This file was created automatically by xsl2profile</xsl:comment>
  14. <xsl:text>&#10;</xsl:text>
  15. <xsl:comment>from the DocBook XSL stylesheets. Do not edit this file.</xsl:comment>
  16. <xsl:text>&#10;</xsl:text>
  17. <xsl:apply-templates/>
  18. <xsl:text>&#10;</xsl:text>
  19. </xsl:template>
  20. <!-- Make sure we override some templates and parameters appropriately for XHTML -->
  21. <xsl:template match="xsl:stylesheet">
  22. <xsl:copy>
  23. <xsl:attribute name="exslt:dummy" xmlns:exslt="http://exslt.org/common">dummy</xsl:attribute>
  24. <xsl:attribute name="ng:dummy" xmlns:ng="http://docbook.org/docbook-ng">dummy</xsl:attribute>
  25. <xsl:attribute name="db:dummy" xmlns:db="http://docbook.org/ns/docbook">dummy</xsl:attribute>
  26. <xsl:if test="not(@extension-element-prefixes)">
  27. <xsl:attribute name="extension-element-prefixes">exslt</xsl:attribute>
  28. </xsl:if>
  29. <xsl:if test="not(@exclude-result-prefixes)">
  30. <xsl:attribute name="exclude-result-prefixes">exslt</xsl:attribute>
  31. </xsl:if>
  32. <xsl:for-each select="@*">
  33. <xsl:choose>
  34. <xsl:when test="local-name(.) = 'extension-element-prefixes' or
  35. local-name(.) = 'exclude-result-prefixes'">
  36. <xsl:attribute name="{local-name(.)}"><xsl:value-of select="concat(., ' exslt')"/></xsl:attribute>
  37. </xsl:when>
  38. <xsl:otherwise>
  39. <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  40. </xsl:otherwise>
  41. </xsl:choose>
  42. </xsl:for-each>
  43. <xsl:apply-templates/>
  44. </xsl:copy>
  45. </xsl:template>
  46. <xsl:template match="*">
  47. <xsl:copy>
  48. <xsl:copy-of select="@*"/>
  49. <xsl:apply-templates/>
  50. </xsl:copy>
  51. </xsl:template>
  52. <xsl:template match="comment()|processing-instruction()|text()">
  53. <xsl:copy/>
  54. </xsl:template>
  55. <xsl:template match="xsl:template[@match='/']">
  56. <xslo:include href="../profiling/profile-mode.xsl"/>
  57. <xslo:variable name="profiled-content">
  58. <xslo:choose>
  59. <xslo:when test="*/self::ng:* or */self::db:*">
  60. <xslo:message>Stripping NS from DocBook 5/NG document.</xslo:message>
  61. <xslo:variable name="stripped-content">
  62. <xslo:apply-templates select="/" mode="stripNS"/>
  63. </xslo:variable>
  64. <xslo:message>Processing stripped document.</xslo:message>
  65. <xslo:apply-templates select="exslt:node-set($stripped-content)" mode="profile"/>
  66. </xslo:when>
  67. <xslo:otherwise>
  68. <xslo:apply-templates select="/" mode="profile"/>
  69. </xslo:otherwise>
  70. </xslo:choose>
  71. </xslo:variable>
  72. <xslo:variable name="profiled-nodes" select="exslt:node-set($profiled-content)"/>
  73. <xsl:copy>
  74. <xsl:copy-of select="@*"/>
  75. <xsl:apply-templates mode="correct"/>
  76. </xsl:copy>
  77. </xsl:template>
  78. <xsl:template match="xsl:template[@name='hhc-main' or @name='hhp-main'] | xsl:variable[@name='raw.help.title']">
  79. <xsl:copy>
  80. <xsl:copy-of select="@*"/>
  81. <xsl:apply-templates mode="correct"/>
  82. </xsl:copy>
  83. </xsl:template>
  84. <xsl:template match="*[starts-with(@select, '/')]" mode="correct">
  85. <xsl:copy>
  86. <xsl:for-each select="@*">
  87. <xsl:choose>
  88. <xsl:when test="local-name(.) = 'select' and string(.) = '/'">
  89. <xsl:attribute name="{local-name(.)}">$profiled-nodes</xsl:attribute>
  90. </xsl:when>
  91. <xsl:when test="local-name(.) = 'select' and starts-with(., '/')">
  92. <xsl:attribute name="{local-name(.)}">$profiled-nodes<xsl:value-of select="."/></xsl:attribute>
  93. </xsl:when>
  94. <xsl:otherwise>
  95. <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  96. </xsl:otherwise>
  97. </xsl:choose>
  98. </xsl:for-each>
  99. <xsl:apply-templates mode="correct"/>
  100. </xsl:copy>
  101. </xsl:template>
  102. <xsl:template match='*[contains(@*, "key(&apos;id&apos;,$rootid)")]' mode="correct" priority="2">
  103. <xsl:copy>
  104. <xsl:for-each select="@*">
  105. <xsl:choose>
  106. <xsl:when test='contains(., "key(&apos;id&apos;,$rootid)")'>
  107. <xsl:attribute name="{local-name(.)}">
  108. <xsl:call-template name="string.subst">
  109. <xsl:with-param name="string" select="."/>
  110. <xsl:with-param name="target">key('id',$rootid)</xsl:with-param>
  111. <xsl:with-param name="replacement">$profiled-nodes//*[@id=$rootid]</xsl:with-param>
  112. </xsl:call-template>
  113. </xsl:attribute>
  114. </xsl:when>
  115. <xsl:otherwise>
  116. <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  117. </xsl:otherwise>
  118. </xsl:choose>
  119. </xsl:for-each>
  120. <xsl:apply-templates mode="correct"/>
  121. </xsl:copy>
  122. </xsl:template>
  123. <!-- FO stylesheet has apply-templates without select, we must detect it by context -->
  124. <xsl:template match="fo:root//xsl:apply-templates" mode="correct">
  125. <xsl:copy>
  126. <xsl:copy-of select="@*"/>
  127. <xsl:attribute name="select">$profiled-nodes/node()</xsl:attribute>
  128. <xsl:apply-templates mode="correct"/>
  129. </xsl:copy>
  130. </xsl:template>
  131. <!-- DB5 namespace stripping is already done -->
  132. <xsl:template match="xsl:when[contains(@test, 'self::db')]" mode="correct">
  133. <xsl:copy>
  134. <xsl:attribute name="test">false()</xsl:attribute>
  135. </xsl:copy>
  136. </xsl:template>
  137. <xsl:template match="*" mode="correct">
  138. <xsl:copy>
  139. <xsl:copy-of select="@*"/>
  140. <xsl:apply-templates mode="correct"/>
  141. </xsl:copy>
  142. </xsl:template>
  143. <xsl:template match="comment()|processing-instruction()|text()" mode="correct">
  144. <xsl:copy/>
  145. </xsl:template>
  146. </xsl:stylesheet>