0

Ditac(XML MindによるDITAコンバーター)を使用して構文の色付けを実行する方法はありますか?XHTMLとXSL:FOの両方の出力をサポートしていれば、XSLT1またはXSLT2ベースのソリューションはすべて機能します。

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>

    ...

「highlighting/fo.xsl」には、「highlighting / common.xsl」という別のファイルが含まれています(これらのファイルはDocbookから取得して変更しました)。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>
4

2 に答える 2

2

このスタイルシートは、Saxon-HEではサポートされていない古い「再帰的」拡張メカニズムを使用しているように見えます。考えられる解決策は次のとおりです。

(a)古いオープンソースのSaxon-B製品を使用する:このメカニズムは、9.1までのリリースでサポートされていました。

(b)Saxon-PEを使用する(コスト£50):このメカニズムは、Saxon-PEおよびSaxon-EEの現在のリリースでも引き続きサポートされています。

(c)Saxon-HEでサポートされている「統合拡張関数」として拡張を実装するためのJavaラッパーコードを記述します。

于 2012-08-01T08:59:46.440 に答える
0

2012年9月11日以降、Ditacは、いわば箱から出してすぐに構文の色付けをサポートするようになりました。

言語は、次のoutputclass属性を使用して指定されます。

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

これは、元の質問で述べたように、XSLT構文の強調表示を使用してXMLマインドによって実際に実装されています。

次の値がサポートされていoutputclassます:

  • 言語-c
  • 言語-cpp
  • 言語-csharp
  • 言語-デルファイ
  • 言語-ini
  • 言語-java
  • 言語-javascript
  • 言語-m2
  • 言語-perl
  • 言語-php
  • 言語-python
  • 言語-ruby
  • 言語-tcl
  • language-xml
于 2013-01-29T02:28:46.253 に答える