Saxon 9.4.0.6 EE with xslthl

Here should go questions about transforming XML with XSLT and FOP.
karablik
Posts: 1
Joined: Mon Apr 29, 2013 12:47 pm

Saxon 9.4.0.6 EE with xslthl

Post by karablik »

Hello everybody,

I am trying to use qwdita.highlight plugin with Oxygen 14.2. This plugin is based on xslthl tool. I am trying to use it to highlight blocks of source code in DITA documents. After installation of plugin I faced the following problem: saxon 9.4.0.6 EE does not see Java-functions exported by xslthl (<xsl:when test="function-available('XXX:highlight')"> always returns false). The following code prints "NO FUNCS!!!" message if I use saxon 9.4, but if I configure to use saxon6.5.5 (as it is done by default in docbook framework) everything works, "s6hl:highlight!!!" is printed and XHTML transformation produces html with highlighted source code.
And I would be happy but I need also to produce highlighted code in PDFs. With PDF transform "saxon6.5.5" trick does not work, because as I understand this transformation requires XSLT2.0 transformer. So I think I have to make xslthl working with saxon 9.4.0.6 EE. Could anybody give me a hint, how can I make Java-functions exported by xslthl visible to saxon 9.4.0.6 EE?

Code: Select all


<!-- 
All of this code was taken from: http://xslthl.wiki.sourceforge.net/Usage
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s6hl="http://net.sf.xslthl/ConnectorSaxon6"
xmlns:sbhl="http://net.sf.xslthl/ConnectorSaxonB"
xmlns:xhl="http://net.sf.xslthl/ConnectorXalan"

xmlns:saxon6="http://icl.com/saxon"
xmlns:saxonb="http://saxon.sf.net/"
xmlns:xalan="http://xml.apache.org/xalan"

xmlns:xslthl="http://xslthl.sf.net"

extension-element-prefixes="s6hl sbhl xhl xslthl"
>
<!-- exclude-result-prefixes="xslthl s6hl sbhl xhl" -->

<!-- for Xalan 2.7 -->
<xalan:component prefix="xhl" functions="highlight">
<xalan:script lang="javaclass" src="xalan://net.sf.xslthl.ConnectorXalan" />
</xalan:component>

<!-- for saxon 6 -->
<saxon6:script implements-prefix="s6hl" language="java"
src="java:net.sf.xslthl.ConnectorSaxon6" />

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

<xsl:template name="syntax-highlight">
<xsl:param name="language" />
<xsl:param name="source" />
<xsl:param name="config"></xsl:param>
<xsl:choose>
<xsl:when test="function-available('sbhl:highlight')">
<xsl:message>sbhl:highlight!!!</xsl:message>
<xsl:variable name="highlighted" select="sbhl:highlight($language, $source, $config)" />
<xsl:apply-templates select="$highlighted" />
</xsl:when>
<xsl:when test="function-available('s6hl:highlight')">
<xsl:message>s6hl:highlight!!!</xsl:message>
<xsl:variable name="highlighted" select="s6hl:highlight($language, $source, $config)" />
<xsl:apply-templates select="$highlighted" />
</xsl:when>
<xsl:when test="function-available('xhl:highlight')">
<xsl:message>xhl:highlight!!!</xsl:message>
<xsl:variable name="highlighted" select="xhl:highlight($language, $source, $config)" />
<xsl:apply-templates select="$highlighted" />
</xsl:when>
<xsl:otherwise>
<xsl:message>NO FUNCS!!!</xsl:message>
<xsl:apply-templates select="$source/*|$source/text()" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
Regards
Alexey
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Saxon 9.4.0.6 EE with xslthl

Post by sorin_ristache »

Hello,

Yes, the DITA transformations require XSLT 2.0 which in Oxygen are executed with Saxon the 9.4 Enterprise processor. I think a Saxon 9 connector class needs to be added in the xslthl jar library, because the Saxon B connector included in the xslthl jar only works with Saxon 8.x (when Saxon had the flavors B - Basic and SA - Schema Aware) but not with Saxon 9.x (when the new flavors are HE - Home Edition, PE - Professional Edition and EE - Enterprise Edition). So xslthl jar needs to include also a Saxon 9.x connector (something like net.sf.xslthl.ConnectorSaxon9), not only a Saxon 6.5, connector, a Saxon B one and a Xalan one.

I suggest getting the source code of the Saxon B connector class from the xslthl jar file, that is the Java source code for the class net.sf.xslthl.ConnectorSaxonB, creating a ConnectorSaxon9 class starting from ConnectorSaxonB and adding a method like the following one, compiling the Saxon 9 connector class, and adding it to the xslthl jar file.

Code: Select all

    public static SequenceIterator highlight(XPathContext xpathcontext, 
String s, SequenceIterator sequenceiterator) throws Exception

Regards,
Sorin
Post Reply