What are the steps needed in DITA-OT to pass ANT command line parameters to custom plugin's override XSLT-script

StackOverflow https://stackoverflow.com/questions/22780152

Domanda

This question follows this: Is it possible to pass custom ANT parameters into custom plugin with DITA-OT?

I have plugin folder called: com.mymods.pdf under DITA-OT/plugins folder. Under is explained the structure and files shortly (follows this example closely http://dita-ot.github.io/1.8/readme/dita2pdf-customization.html). Plugin works but now I want to pass ANT command line parameters into 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)

So where I need to apply changes and/or add new files?

I use the plugin from other location with "mainANT.xml" which has target and transtype for using "dita2mymodsPDF".

plugin.xml code:

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

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

Also integrator.xml code:

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

Not totally sure whether integrator.xml or build_mymods_pdf_template.xml is like it actually should. But this fileset works and uses mycustom.xsl (other for attributes and other for XSLT overrides). Now the problem is that how to get my own custom ANT parameters so the plugin can see its value.

This is really easy for pdf2 plugin but still can't yet get it working inside my com.mymods.pdf . I think I don't need to post catalog.xml because it just tells where are "mycustom.xsl" files that are working properly.

È stato utile?

Soluzione

Really easy way, not the cleanest way to do this is:

Note: This applies for DITA-OT 1.8.4 check suitability for other versions.

  1. Create your custom PDF plugin as told in: http://dita-ot.github.io/1.8/readme/dita2pdf-customization.html

  2. Create "insertParameters.xml" as in: http://dita-ot.github.io/1.8/dev_ref/plugin-xsltparams.html

In my case with following custom parameters:

<?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. Now drop this "insertParameters.xml" into DITA-OT\plugins\org.dita.pdf2

  2. Create processing to custom.xsl under xsl\custom.xsl.

Here is an example code snippet for 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. Run integrator.xml to integrate changes into your DITA-OT.

  2. Give in command line commands for running your PDF scenario like: "ant dita2mypdf -f -Dcustom.data1="myCustomParameter1value" -Dcustom.data2="myCustomParameter2value"

  3. Run the process to create PDF and your parameters should be visible!

What this question was really intended to achieve to get a step by step instruction to set all these things to work 100% in the custom plugin that not a single thing needs to be added into DITA-OT default plugins (not even single file into pdf2 folder as in this solution). This could make updating DITA-OT remarkably easier for future.

Altri suggerimenti

The cleaner? alternative to this approach is

  • add a placeholder insertParameters.xml to the root of the DITA-OT 1.8.5. The file does not exist in the standard DITA-OT 1.8.5

    <?xml version='1.0' encoding='UTF-8'?>
    <dummy>
        <param name="dummy" expression="{$dummy} if="dummy"/>
    </dummy>
    
  • add the override insertParameters.xml to the root of your plugin

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

Then run ant -f integrator.xml

Without knowing precisely which parameters you need to pass, it's difficult to answer this question. However, let's assume you're invoking this from the command line and you've defined a transtype of mymodspdf. The command would look like this:

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

HTH,

Julio J. Vazquez Write Spirit http://www.writespiritservices.com

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top