有沒有使用Ditac(XML Mind的DITA轉換器)執行語法着色的方法?任何基於XSLT1或XSLT2的解決方案都可以工作,只要它支持XHTML和XSL:FO輸出。使用Ditac(XML Mind Dita轉換器)的語法着色
已經提出XSLTHL(http://sourceforge.net/projects/xslthl/),雖然Saxon-HE(由Ditac使用)似乎沒有檢測到擴展JAR文件。
我修改了提供的XSL文件,以便它們應該與DITA一起使用;但發生的只是複製非着色的源代碼列表默認行爲,因爲沒有檢測的擴展功能:
<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>
...
「高亮/ fo.xsl」包括所謂的「高亮/ common.xsl」另一個文件(我從Docbook中獲取並修改了這些文件)。下面是應該撒克遜鏈接部分:
<?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>
它不是」從你的問題中清楚輸出格式應該是什麼。如果這是HTML,那麼您可能有興趣查看XPath Visualizer的源代碼,它以某種方式漂亮地打印XML,類似於IE。 http://www.huttar.net/dimitre/XPV/TopXML-XPV.html – 2012-08-01 03:27:36
我認爲問題的一部分是XSLTHL是[種類擴展](http://www.saxonica.com/documentation/extensibility /functions.xml),Saxon-HE不支持。 – mzjn 2012-08-01 08:53:25