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

Plugins DITA-OT中需要哪些步骤将ANT命令行参数传递给自定义插件';s重写XSLT脚本,plugins,ant,customization,dita,dita-ot,Plugins,Ant,Customization,Dita,Dita Ot,问题如下: 我在DITA-OT/plugins文件夹下有一个名为:com.mymods.pdf的插件文件夹。下面简要介绍了结构和文件(紧跟本例)。插件可以工作,但现在我想将ANT命令行参数传递到mycustom.xsl中: com.mymods.pdf/ cfg/ common/ vars/ en.xml fo/ attrs/ mycustom.xsl xsl/ mycustom.xsl

问题如下:

我在DITA-OT/plugins文件夹下有一个名为:com.mymods.pdf的插件文件夹。下面简要介绍了结构和文件(紧跟本例)。插件可以工作,但现在我想将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)
com.mymods.pdf/
cfg/
普通的/
瓦尔斯/
en.xml
fo/
属性/
mycustom.xsl
xsl/
mycustom.xsl
catalog.xml
integrator.xml
plugin.xml
build_mymods_pdf_template.xml(dita2com.mymods.pdf.init目标在这里,它取决于dita2pdf2)
build.xml()
insertParameters.xml(有关内容,请参见链接问题)
那么我需要在哪里应用更改和/或添加新文件

我使用来自其他位置的带有“mainANT.xml”的插件,该插件具有使用“dita2mymodsPDF”的target和transtype

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>
<?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>
<?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>

build_mymods_pdf_template.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>
<?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>
<?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代码:

<?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>
<?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>
<?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”文件在哪里正常工作。

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

ant-f build.xml-Dtranstype mymodspdf-dmypParameter1 paramval1-dmypParameter2 paramval2

嗯,

胡里奥·J·巴斯克斯 书写精神

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

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

  • 创建自定义PDF插件,如中所述:

  • 创建“insertParameters.xml”,如中所示:

  • 在我的例子中,使用以下自定义参数:

    <?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>
    
    
    
  • 现在将这个“insertParameters.xml”放到DITA-OT\plugins\org.DITA.pdf2中

  • 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>
    
    
    
  • 运行integrator.xml将更改集成到DITA-OT中

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

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


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

    更干净的方法是

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

    然后运行
    ant-f integrator.xml

    您的答案只是外部ant参数的标准输入。这仍然不允许在com.mymods.pdf插件的“plugin.xml”和“insertParameters.xml”中定义的“dita2mymodsPDF”transtype的“mycustom.xsl”中使用这些参数“。我没有添加所有内容,因为我在这之前问了一个链接问题:您能将
    plugin.xml
    build\u mymods\u pdf\u template.xml
    的内容添加到问题中吗?”。