Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9199353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:31:02+00:00 2026-06-17T22:31:02+00:00

Is there a way to perform syntax colouring using Ditac (the DITA converter by

  • 0

Is there a way to perform syntax colouring using Ditac (the DITA converter by XML Mind)? Any XSLT1 or XSLT2 based solution would work provided that it supports both XHTML and XSL:FO output.

XSLTHL (http://sourceforge.net/projects/xslthl/) has been suggested, though Saxon-HE (used by Ditac) doesn’t seem to detect the extension JAR file.

I modified the provided XSL files so that they should work with DITA; but the default behaviour of just copying the non-coloured source listing occurs because the extension function is not being detected:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:fo="http://www.w3.org/1999/XSL/Format"
        xmlns:ditac="http://www.xmlmind.com/ditac/schema/ditac"
        xmlns:u="http://www.xmlmind.com/namespace/ditac"
        version="2.0">

    <xsl:import href="ditac-xsl:fo/fo.xsl"/>
    <xsl:import href="highlighting/fo.xsl"/>

    <!-- Syntax highlighting -->
    <xsl:template match="*[contains(@class,' topic/pre ')]">
        <fo:block xsl:use-attribute-sets="pre">
            <xsl:call-template name="commonAttributes"/>
            <xsl:call-template name="displayAttributes"/>
            <xsl:call-template name="apply-highlighting"/>
        </fo:block>
    </xsl:template>

    ...

“highlighting/fo.xsl” includes another file called “highlighting/common.xsl” (I took and modified these files from Docbook). Here is the part that should link with Saxon:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

        xmlns:sbhl="http://net.sf.xslthl/ConnectorSaxonB"
        xmlns:saxonb="http://saxon.sf.net/" 

        xmlns:exsl="http://exslt.org/common"
        xmlns:xslthl="http://xslthl.sf.net"
        exclude-result-prefixes="exsl xslthl sbhl"
        version='1.0'>

<!-- ********************************************************************
     $Id: common.xsl,v 1.11 2009/06/02 11:41:23 sorin Exp $
     ********************************************************************

     This file is part of the XSL DocBook Stylesheet distribution.
     See ../README or http://docbook.sf.net/release/xsl/current/ for
     and other information.

     ******************************************************************** -->

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


<xsl:variable name="highlight.default.language" select="csharp"/>


<!-- You can override this template to do more complex mapping of
     language attribute to highlighter language ID (see xslthl-config.xml) -->
<xsl:template name="language.to.xslthl">
  <xsl:param name="context"/>

  <xsl:choose>
    <xsl:when test="$context/@outputclass != ''">
      <xsl:value-of select="$context/@outputclass"/>
    </xsl:when>
    <xsl:when test="$highlight.default.language != ''">
      <xsl:value-of select="$highlight.default.language"/>
    </xsl:when>
  </xsl:choose>
</xsl:template>

<xsl:template name="apply-highlighting">
    <xsl:variable name="language">
        <xsl:call-template name="language.to.xslthl">
            <xsl:with-param name="context" select="."/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:choose>
        <xsl:when test="$language != ''">
            <xsl:variable name="content">
                <xsl:apply-templates/>
            </xsl:variable>
            <xsl:choose>
                <xsl:when test="function-available('sbhl:highlight')">
                    <xsl:apply-templates select="sbhl:highlight($language, exsl:node-set($content), 'xslthl-config.xml')" mode="xslthl"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:copy-of select="$content"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- A fallback when the specific style isn't recognized -->
<xsl:template match="xslthl:*" mode="xslthl">
  <xsl:message>
    <xsl:text>unprocessed xslthl style: </xsl:text>
    <xsl:value-of select="local-name(.)" />
  </xsl:message>
  <xsl:apply-templates mode="xslthl"/>
</xsl:template>

<!-- Copy over already produced markup (FO/HTML) -->
<xsl:template match="node()" mode="xslthl" priority="-1">
  <xsl:copy>
    <xsl:apply-templates select="node()" mode="xslthl"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="*" mode="xslthl">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="node()" mode="xslthl"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:31:03+00:00Added an answer on June 17, 2026 at 10:31 pm

    Since September 11, 2012 Ditac now support syntax colouring out of the box so to speak!

    The language is specified using the outputclass attribute:

    <codeblock outputclass="language-csharp"><![CDATA[
        public class SomethingNeat {
            public string someString = "Hello World!";
        }
    ]]></codeblock>
    

    This has indeed been implemented by XML Mind using XSLT Syntax Highlighting as mentioned in the original question.

    The following values are supported for outputclass:

    • language-c
    • language-cpp
    • language-csharp
    • language-delphi
    • language-ini
    • language-java
    • language-javascript
    • language-m2
    • language-perl
    • language-php
    • language-python
    • language-ruby
    • language-tcl
    • language-xml
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to perform an update for normalizing a field using a
Is there a way to perform sequential k-means clustering using scikit-learn? I can't seem
Is there a way to perform data validation using CHECK constraints in t-sql and
Is there any way I can get jQuery to perform a function when you
Currently, generics in C# do not allow any sane way to perform arithmetic. There
I was wondering, is there any way to perform random access in multimap's values.
Is there a way to perform a grep based on the results of a
Is there any way to perform a Linq OrderBy on a column in an
Is there a way to perform row wise operations on matrices in octave ?
With MongoDB is there a way to perform a bounds query (within a box)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.