代码之家  ›  专栏  ›  技术社区  ›  sailfish

DITA-OT中需要哪些步骤将ANT命令行参数传递给自定义插件的重写XSLT脚本

  •  0
  • sailfish  · 技术社区  · 12 年前

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

    我的插件文件夹名为: com.mymods.pdf DITA-OT/plugins文件夹下。下面简要介绍了结构和文件(请密切关注此示例 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”,该插件具有使用“dita2myodsPDF”的目标和转换类型。

    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”文件在哪里。

    3 回复  |  直到 9 年前
        1
  •  1
  •   sailfish    12 年前

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

    注:这适用于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. 在下面创建对custom.xsl的处理 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.data 2=”myCustomParameters2value“

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

    这个问题的真正目的是获得一个逐步指令,将所有这些设置为在自定义插件中100%工作,而不需要将任何内容添加到DITA-OT默认插件中(甚至不需要像这个解决方案中那样将单个文件添加到pdf2文件夹中)。这将使DITA-OT的更新在未来变得更加容易。

        2
  •  1
  •   Tomasz Jakub Rup    10 年前

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

    • 添加占位符 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

        3
  •  0
  •   JulioV    12 年前

    如果不知道需要传递哪些参数,很难回答这个问题。然而,我们假设您从命令行调用这个,并且定义了mymodspdf的transtype。命令如下所示:

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

    其中,

    胡里奥·J·巴斯克斯 书写精神 http://www.writespiritservices.com