OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]

Subject: Re: [docbook-apps] Re: Some beginner questions for db xslt20-stylesheets

On 17/12/2018 11:18, Jirka Kosek wrote:
On 17.12.2018 9:11, Norman Walsh wrote:
4. Is it possible to do source code highlighting in docbook?

In the browser, yes. I donât think thereâs a solution for doing it
in print at the moment.

XSLTH library (https://sourceforge.net/projects/xslthl/) used by
XSLT 1.0 stylesheets has Saxon9 connector, so in theory it can be
integrated into XSLT 2.0 styleshets as well.

Easily more than just a theory.  I used the XSLTHL library and an XSLT
2.0 stylesheet to add highlighting (to HTML) in the current version of
'Introduction to CSS for Paged Media' available at

The significant parts of the stylesheet (based on the XSLTHL example) are:


    extension-element-prefixes="sbhl xslthl"
    exclude-result-prefixes="saxonb sbhl xhtml xs xslthl">

<!-- this parameter is used to set the location of the filename -->
<xsl:param name="xslthl.config" />

<!-- for saxon 8.5 and later -->
<saxonb:script implements-prefix="sbhl" language="java"
               src="java:net.sf.xslthl.ConnectorSaxonB" />

<xsl:template match="xhtml:code[@class] | xhtml:pre[@class]">
  <xsl:element name="{local-name()}">
    <xsl:copy-of select="@*" />
    <xsl:call-template name="syntax-highlight">
      <xsl:with-param name="language"
                                       ' ')[last()]"
                      tunnel="yes" />
      <xsl:with-param name="source" select="." />

<!-- highlighting of the xslthl tags -->
<xsl:template match="xslthl:*" mode="hl">
   <span class="hl-{local-name()}">
    <xsl:apply-templates select="node()" />

<!-- This template will perform the actual highlighting -->
<xsl:template name="syntax-highlight">
  <xsl:param name="language" as="xs:string" tunnel="yes" />
  <xsl:param name="source" />
    <xsl:when test="function-available('sbhl:highlight')">
      <xsl:variable name="highlighted"
select="sbhl:highlight($language, $source, $xslthl.config)" />
      <xsl:apply-templates select="$highlighted" mode="hl" />
style="border: 2px solid red; background: white; font-family: sans-serif; padding: 0.5em; font-size: 2em;"
          >No syntax highlighter available</div>
      <xsl:apply-templates select="$source/* | $source/text()" />

I use Ant to run nearly everything, so if you want to reconstruct the
usage, this is the Ant command line:

   ant -lib xslthl-2.1.3.jar -lib saxon9.jar -emacs toc-hl.single

where the 'toc-hl.single' target uses the <xslt> target to run Saxon and
on the stylesheet and pass in the XSLTHL configuration file as a

I hope that helps.


Tony Graham.
Senior Architect
XML Division
Antenna House, Inc.
Skerries, Ireland

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]