0

这个问题如下:Is it possible to pass custom ANT parameters into custom plugin with DITA-OT?

我在 DITA-OT/plugins 文件夹下有一个名为: com.mymods.pdf的插件文件夹。下面简要解释一下结构和文件(紧跟这个例子http://dita-ot.github.io/1.8/readme/dita2pdf-customization.html)。插件有效,但现在我想将 ANT 命令行参数传递到 mycustom.xsl:

com.mymods.pdf/
  cfg/
    common/
      vars/
        en.xml
    fo/
      attrs/
        mycustom.xsl
      xsl/
        mycustom.xsl
    catalog.xml
  integrator.xml
  plugin.xml
  build_mymods_pdf_template.xml (dita2com.mymods.pdf.init   target is here and it depends on dita2pdf2)
  build.xml (<project><import file="build_mymods_pdf.xml"/></project>)
  insertParameters.xml (see the linked question for contents)

那么我需要在哪里应用更改和/或添加新文件?

我将其他位置的插件与“mainANT.xml”一起使用,该插件具有使用“dita2mymodsPDF”的目标和转换类型。

plugin.xml 代码:

<?xml version='1.0' encoding='UTF-8'?>
<plugin id="com.mymods.pdf">
<require plugin="org.dita.pdf2" />
<feature extension="dita.conductor.transtype.check" value="com.mymods.pdf" />
<feature extension="dita.transtype.print" value="com.mymods.pdf" />
<feature extension="dita.conductor.target.relative" file="integrator.xml" />
<feature extension="dita.conductor.com.mymods.pdf.param" file="insertParameters.xml"/>
<extension-point id="dita.conductor.com.mymods.pdf.param" name="PDF XSLT parameters"/>
</plugin>

build_mymods_pdf_template.xml 代码:

<?xml version='1.0' encoding='UTF-8'?>
<project name="com.mymods.pdf" default="com.mymods.pdf">
<property name="transtype" value="com.mymods.pdf"/>

<target name="dita2com.mymods.pdf.init">
<property location="${dita.plugin.com.mymods.pdf.dir}/cfg" name="customization.dir" />
<property location="${dita.plugin.com.mymods.pdf.dir}/xsl/fo/topic2fo_shell_fop.xsl" name="args.xsl.pdf" />
<property name="args.chapter.layout" value="BASIC" />
<property name="args.bookmark.style" value="COLLAPSED" />
<!--property name="args.fo.include.rellinks" value="nofamily" /-->
</target>
<target depends="dita2com.mymods.pdf.init, dita2pdf2" name="dita2com.mymods.pdf" />
</project>

还有integrator.xml代码:

<?xml version='1.0' encoding='UTF-8'?>
<project name="com.mymods.pdf">
<target name="dita2com.mymods.pdf.init">
<property location="${dita.plugin.com.mymods.pdf.dir}/cfg" name="customization.dir" />
<property location="${dita.plugin.com.mymods.pdf.dir}/xsl/fo/topic2fo_shell_fop.xsl" name="args.xsl.pdf" />
<property name="args.chapter.layout" value="BASIC" />
<property name="args.bookmark.style" value="COLLAPSED" />
<!--property name="args.fo.include.rellinks" value="nofamily" /-->
</target>
<target depends="dita2com.mymods.pdf.init, dita2pdf2" name="dita2com.mymods.pdf" />
</project>

不完全确定 integrator.xml 或 build_mymods_pdf_template.xml 是否像它实际上应该的那样。但这个文件集工作并使用 mycustom.xsl(其他用于属性,其他用于 XSLT 覆盖)。现在的问题是如何获取我自己的自定义 ANT 参数,以便插件可以看到它的值。

这对于 pdf2 插件来说真的很容易,但仍然不能让它在我的com.mymods.pdf中工作。我想我不需要发布catalog.xml,因为它只是告诉“mycustom.xsl”文件在哪里正常工作。

4

3 回答 3

1

真正简单的方法,而不是最干净的方法是:

注意:这适用于 DITA-OT 1.8.4 检查其他版本的适用性。

  1. 按照以下说明创建您的自定义 PDF 插件: http: //dita-ot.github.io/1.8/readme/dita2pdf-customization.html

  2. 创建“insertParameters.xml”,如:http ://dita-ot.github.io/1.8/dev_ref/plugin-xsltparams.html

在我的情况下,使用以下自定义参数:

<?xml version='1.0' encoding='UTF-8'?>
<dummy>
 <!-- EXAMPLE: <param name="paramNameinXSLT" expression="${antProperty}" if="antProperty"/> -->
<param name="custom.data1" expression="${custom.data1}" if="custom.data1"/>
<param name="custom.data2" expression="${custom.data2}" if="custom.data2"/>
</dummy>
  1. 现在将这个“insertParameters.xml”放到DITA-OT\plugins\org.dita.pdf2

  2. 在xsl\custom.xsl下创建对 custom.xsl 的处理。

这是 custom.xsl 的示例代码片段

<?xml version='1.0' encoding='UTF-8'?>
<snippet>
<xsl:param name="custom.data1"/>
<xsl:param name="custom.data2"/>
<fo:block><xsl:value-of select="$custom.data1"/></fo:block>
<fo:block><xsl:value-of select="$custom.data2"/></fo:block>
</snippet>
  1. 运行 integrator.xml 以将更改集成到您的 DITA-OT。

  2. 提供用于运行 PDF 场景的命令行命令,例如:"ant dita2mypdf -f -Dcustom.data1="myCustomParameter1value" -Dcustom.data2="myCustomParameter2value"

  3. 运行创建 PDF 的过程,您的参数应该是可见的!

这个问题的真正目的是为了获得一步一步的指示,将所有这些东西设置为在自定义插件中 100% 工作,不需要将任何东西添加到 DITA-OT 默认插件中(甚至不需要将单个文件添加到 pdf2此解决方案中的文件夹)。这可以使将来更新 DITA-OT 变得非常容易。

于 2014-04-07T13:16:30.783 回答
1

清洁工?这种方法的替代方法是

  • insertParameters.xml在 DITA-OT 1.8.5 的根目录中添加一个占位符。该文件在标准 DITA-OT 1.8.5 中不存在

    <?xml version='1.0' encoding='UTF-8'?>
    <dummy>
        <param name="dummy" expression="{$dummy} if="dummy"/>
    </dummy>
    
  • 将覆盖添加insertParameters.xml到插件的根目录

    <?xml version='1.0' encoding='UTF-8'?>
    <dummy>
        <param name="my.runtime.parameter" expression="{$my.runtime.parameter} if="my.runtime.parameter"/>
    </dummy>
    

然后运行ant -f integrator.xml

于 2015-12-03T19:13:59.437 回答
0

在不准确知道需要传递哪些参数的情况下,很难回答这个问题。但是,假设您从命令行调用它并且您已经定义了 mymodspdf 的转换类型。该命令如下所示:

ant -f build.xml -Dtranstype mymodspdf -Dmyparameter1 paramval1 -Dmyparameter2 paramval2

高温下,

Julio J. Vazquez 写精神 http://www.writespiritservices.com

于 2014-04-01T14:36:02.683 回答