2012-07-31 31 views
0

有沒有使用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> 
+0

它不是」從你的問題中清楚輸出格式應該是什麼。如果這是HTML,那麼您可能有興趣查看XPath Visualizer的源代碼,它以某種方式漂亮地打印XML,類似於IE。 http://www.huttar.net/dimitre/XPV/TopXML-XPV.html – 2012-08-01 03:27:36

+0

我認爲問題的一部分是XSLTHL是[種類擴展](http://www.saxonica.com/documentation/extensibility /functions.xml),Saxon-HE不支持。 – mzjn 2012-08-01 08:53:25

回答

0

自2012年9月11日起,Ditac現在支持語法着色開箱即可!

的語言使用outputclass屬性指定:

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

這確實已經通過XML介意使用XSLT Syntax Highlighting在原來的問題提到實現。

下面的值都支持outputclass

  • 語言-C
  • 語言-CPP
  • 語言CSHARP
  • 語言的Delphi
  • 語言-INI
  • 語言 - java
  • language-javascript
  • 語言-M2
  • 語言Perl的
  • 語言PHP
  • 語言蟒蛇
  • 語言紅寶石
  • 語言TCL
  • 語言XML
2

看起來好像這個樣式表使用了舊的「反身性」擴展機制,這是不是在撒克遜他支持。可能的解決方案是:

(a)中使用舊的開源撒克遜-B產物:這種機制:這種機制是在釋放到9.1

(b)中使用撒克遜-PE(費用£50)的支持在當前版本的Saxon-PE和Saxon-EE中仍然受到支持。

(c)編寫一些Java包裝代碼來實現該擴展作爲Saxon-HE支持的「集成擴展功能」。

+0

我擔心是這樣。出於利益,撒克遜-PE的價格是否已經降低?我似乎記得它更昂貴。我確實嘗試用Saxon-B替代「saxon9.jar」文件,但得到了來自Ditac的一些缺失的類錯誤。感謝您的答覆! – 2012-08-01 12:06:28

+0

使用選項(c)如何加載擴展JAR文件?擴展可以通過XSL樣式表加載嗎?或通過被放置在一個特殊的目錄? – 2012-08-01 12:38:36

+0

Saxon-PE總是50英鎊,也許你在想Saxon-EE。選項(c)不依賴於動態加載,這是好處之一。您可以通過編程方式(Configuration.registerExtensionFunction)或通過配置文件向Saxon配置註冊擴展。從命令行可以在-init選項的幫助下完成。 – 2012-08-01 13:52:47