[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 https://www.antennahouse.com/css/. The significant parts of the stylesheet (based on the XSLTHL example) are: ---------------------------------------------- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:sbhl="http://net.sf.xslthl/ConnectorSaxonB" xmlns:saxonb="http://saxon.sf.net/" xmlns:xslthl="http://xslthl.sf.net" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" 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" select="tokenize(normalize-space(@class), ' ')[last()]" as="xs:string" tunnel="yes" /> <xsl:with-param name="source" select="." /> </xsl:call-template> </xsl:element> </xsl:template> <!-- highlighting of the xslthl tags --> <xsl:template match="xslthl:*" mode="hl"> <span class="hl-{local-name()}"> <xsl:apply-templates select="node()" /> </span> </xsl:template> <!-- 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:choose> <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" /> </xsl:when> <xsl:otherwise> <divstyle="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()" /> </xsl:otherwise> </xsl:choose> </xsl:template> ---------------------------------------------- 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 parameter. I hope that helps. Regards, Tony Graham. -- Senior Architect XML Division Antenna House, Inc. ---- Skerries, Ireland tgraham@antenna.co.jp
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]