xsl2profile.xsl 5.8 KB

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