common.xsl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:s6hl="http://net.sf.xslthl/ConnectorSaxon6"
  4. xmlns:sbhl="http://net.sf.xslthl/ConnectorSaxonB"
  5. xmlns:xhl="http://net.sf.xslthl/ConnectorXalan"
  6. xmlns:saxon6="http://icl.com/saxon"
  7. xmlns:saxonb="http://saxon.sf.net/"
  8. xmlns:xalan="http://xml.apache.org/xalan"
  9. xmlns:exsl="http://exslt.org/common"
  10. xmlns:xslthl="http://xslthl.sf.net"
  11. exclude-result-prefixes="exsl xslthl s6hl sbhl xhl"
  12. version='1.0'>
  13. <!-- ********************************************************************
  14. $Id: common.xsl 8257 2009-02-20 04:40:16Z abdelazer $
  15. ********************************************************************
  16. This file is part of the XSL DocBook Stylesheet distribution.
  17. See ../README or http://docbook.sf.net/release/xsl/current/ for
  18. and other information.
  19. ******************************************************************** -->
  20. <!-- this construction is needed to have the saxon and xalan connectors working alongside each other -->
  21. <xalan:component prefix="xhl" functions="highlight">
  22. <xalan:script lang="javaclass" src="xalan://net.sf.xslthl.ConnectorXalan" />
  23. </xalan:component>
  24. <!-- for saxon 6 -->
  25. <saxon6:script implements-prefix="s6hl" language="java" src="java:net.sf.xslthl.ConnectorSaxon6" />
  26. <!-- for saxon 8.5 and later -->
  27. <saxonb:script implements-prefix="sbhl" language="java" src="java:net.sf.xslthl.ConnectorSaxonB" />
  28. <!-- You can override this template to do more complex mapping of
  29. language attribute to highlighter language ID (see xslthl-config.xml) -->
  30. <xsl:template name="language.to.xslthl">
  31. <xsl:param name="context"/>
  32. <xsl:choose>
  33. <xsl:when test="$context/@language != ''">
  34. <xsl:value-of select="$context/@language"/>
  35. </xsl:when>
  36. <xsl:when test="$highlight.default.language != ''">
  37. <xsl:value-of select="$highlight.default.language"/>
  38. </xsl:when>
  39. </xsl:choose>
  40. </xsl:template>
  41. <xsl:template name="apply-highlighting">
  42. <xsl:choose>
  43. <!-- Do we want syntax highlighting -->
  44. <xsl:when test="$highlight.source != 0">
  45. <xsl:variable name="language">
  46. <xsl:call-template name="language.to.xslthl">
  47. <xsl:with-param name="context" select="."/>
  48. </xsl:call-template>
  49. </xsl:variable>
  50. <xsl:choose>
  51. <xsl:when test="$language != ''">
  52. <xsl:variable name="content">
  53. <xsl:apply-templates/>
  54. </xsl:variable>
  55. <xsl:choose>
  56. <xsl:when test="function-available('s6hl:highlight')">
  57. <xsl:apply-templates select="s6hl:highlight($language, exsl:node-set($content), $highlight.xslthl.config)"
  58. mode="xslthl"/>
  59. </xsl:when>
  60. <xsl:when test="function-available('sbhl:highlight')">
  61. <xsl:apply-templates select="sbhl:highlight($language, exsl:node-set($content), $highlight.xslthl.config)"
  62. mode="xslthl"/>
  63. </xsl:when>
  64. <xsl:when test="function-available('xhl:highlight')">
  65. <xsl:apply-templates select="xhl:highlight($language, exsl:node-set($content), $highlight.xslthl.config)"
  66. mode="xslthl"/>
  67. </xsl:when>
  68. <xsl:otherwise>
  69. <xsl:copy-of select="$content"/>
  70. </xsl:otherwise>
  71. </xsl:choose>
  72. </xsl:when>
  73. <xsl:otherwise>
  74. <xsl:apply-templates/>
  75. </xsl:otherwise>
  76. </xsl:choose>
  77. </xsl:when>
  78. <!-- No syntax highlighting -->
  79. <xsl:otherwise>
  80. <xsl:apply-templates/>
  81. </xsl:otherwise>
  82. </xsl:choose>
  83. </xsl:template>
  84. <!-- A fallback when the specific style isn't recognized -->
  85. <xsl:template match="xslthl:*" mode="xslthl">
  86. <xsl:message>
  87. <xsl:text>unprocessed xslthl style: </xsl:text>
  88. <xsl:value-of select="local-name(.)" />
  89. </xsl:message>
  90. <xsl:apply-templates mode="xslthl"/>
  91. </xsl:template>
  92. <!-- Copy over already produced markup (FO/HTML) -->
  93. <xsl:template match="node()" mode="xslthl" priority="-1">
  94. <xsl:copy>
  95. <xsl:apply-templates select="node()" mode="xslthl"/>
  96. </xsl:copy>
  97. </xsl:template>
  98. <xsl:template match="*" mode="xslthl">
  99. <xsl:copy>
  100. <xsl:copy-of select="@*"/>
  101. <xsl:apply-templates select="node()" mode="xslthl"/>
  102. </xsl:copy>
  103. </xsl:template>
  104. </xsl:stylesheet>