common.xsl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:hl="java:net.sf.xslthl.ConnectorSaxon6"
  4. xmlns:exsl="http://exslt.org/common"
  5. exclude-result-prefixes="exsl hl"
  6. version='1.0'>
  7. <!-- ********************************************************************
  8. $Id$
  9. ********************************************************************
  10. This file is part of the XSL DocBook Stylesheet distribution.
  11. See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  12. and other information.
  13. ******************************************************************** -->
  14. <!-- You can override this template to do more complex mapping of
  15. language attribute to highlighter language ID (see xslthl-config.xml) -->
  16. <xsl:template name="language.to.xslthl">
  17. <xsl:param name="context"/>
  18. <xsl:choose>
  19. <xsl:when test="$context/@language != ''">
  20. <xsl:value-of select="$context/@language"/>
  21. </xsl:when>
  22. <xsl:when test="$highlight.default.language != ''">
  23. <xsl:value-of select="$highlight.default.language"/>
  24. </xsl:when>
  25. </xsl:choose>
  26. </xsl:template>
  27. <xsl:template name="apply-highlighting">
  28. <xsl:choose>
  29. <!-- Do we want syntax highlighting -->
  30. <xsl:when test="$highlight.source != 0 and function-available('hl:highlight')">
  31. <xsl:variable name="language">
  32. <xsl:call-template name="language.to.xslthl">
  33. <xsl:with-param name="context" select="."/>
  34. </xsl:call-template>
  35. </xsl:variable>
  36. <xsl:choose>
  37. <xsl:when test="$language != ''">
  38. <xsl:variable name="content">
  39. <xsl:apply-templates/>
  40. </xsl:variable>
  41. <xsl:apply-templates select="hl:highlight($language, exsl:node-set($content))"/>
  42. </xsl:when>
  43. <xsl:otherwise>
  44. <xsl:apply-templates/>
  45. </xsl:otherwise>
  46. </xsl:choose>
  47. </xsl:when>
  48. <!-- No syntax highlighting -->
  49. <xsl:otherwise>
  50. <xsl:apply-templates/>
  51. </xsl:otherwise>
  52. </xsl:choose>
  53. </xsl:template>
  54. </xsl:stylesheet>