Chain transformations, dita + HTML5

Post here questions and problems related to editing and publishing DITA content.
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Chain transformations, dita + HTML5

Post by gbv34 »

Hello,
I'm seeking a method to apply consecutive changes to a project using a single transformation type (DITA first, HTML5 after from the modified DITA source). I've been advised to use an extension point to execute an ant target ("depend.preprocess.pre") and I have started designing this plugin.
com.xxx.beforeafter.zip
(3.49 KiB) Downloaded 26 times
I don't get why I keep having an error that "the Target "addstring" does not exist in the project "DOST". It is used from target "preprocess2". while I have declared it in my build xml file:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<project name="com.xxx.beforeafter" default="addstring">
    <target name="dita2html5-addstring">
        <xslt basedir="${args.input.dir}" 
              includes="**/*.dita" 
              destdir="${dita.temp.dir}" 
              style="${dita.plugin.com.xxx.beforeafter.dir}/xsl/addstring.xsl" 
              classpathref="dita-ot-classpath" 
              extension=".dita" 
              force="true"/>
    </target>
</project>
Because the plugin.xml uses a transtype custom(html5-addstring), I have used "dita2html5-addstring" in the target.

Code: Select all

   <plugin id="com.xxx.beforeafter">
       <require plugin="org.dita.base"/>
       <feature extension="dita.conductor.target.relative" file="build.xml"/>
       <feature extension="depend.preprocess.pre" value="addstring"/>
       <transtype name="html5-addstring" extends="html5" 
                  transtype="true" 
                  description="HTML5 transformation with string addition"/>
   </plugin>
Right now, my goal is simple, getting a simple plugin prototype used to trigger a transformation in DITA content before publishing the source as HTML5.

I'm currently struggling with this plugin and any tips would be very appreciated :)
------
Gaspard
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Chain transformations, dita + HTML5

Post by Radu »

Hi Gaspard.

Here are some observations about your plugin:

1) If you are using Oxygen XML Editor to edit the plugin.xml you can add this xml-model processing instruction before the root element:

Code: Select all

<?xml-model href="dita-ot/plugin.rnc" type="application/relax-ng-compact-syntax"?>
<plugin id="com.xxx.beforeafter">
    <require plugin="org.dita.base"/>
    <feature extension="dita.conductor.target.relative" file="build.xml"/>
    <feature extension="depend.preprocess.pre" value="addstring"/>
    <transtype name="html5-addstring" extends="html5" transtype="true"
        description="HTML5 transformation with string addition"/>
</plugin>
this should allow Oxygen to validate and report validation errors in the file, like for example the invalid 'transtype="true"' or the "description" which should be renamed to "desc".

2) If you open in Oxygen your "com.xxx.beforeafter/build.xml", Oxygen reports a validation error:
The default target 'addstring' does not exist in this project.
You can probably remove the entire " default="addstring"" attribute from the <project> root element.

3) Your plugin declares a preprocessing stage dependency and states that a custom target named "addstring" should be called from your build.xml, but there is no target named "addstring" in your build.xml:

Code: Select all

<feature extension="depend.preprocess.pre" value="addstring"/>
So I think your build.xml would need to look something like this:

Code: Select all

<project name="com.xxx.beforeafter">
    <!-- Your main target calls the html5 target -->
    <target name="dita2html5-addstring" depends="dita2html5"/>
    <!-- This "addstring" target is called automatically from the preprocess stage. -->
    <target name="addstring">
        <xslt basedir="${args.input.dir}" 
              includes="**/*.dita" 
              destdir="${dita.temp.dir}" 
              style="${dita.plugin.com.xxx.beforeafter.dir}/xsl/addstring.xsl" 
              classpathref="dita-ot-classpath" 
              extension=".dita" 
              force="true"/>
    </target>
</project>
but it will still not work. The "depend.preprocess.pre" stage is called very early in the processing stage, your DITA XML content has not yet been copied to the temporary files folder and this is not something you can easily substitute.
You can look inside this build file "DITA-OT3.x/plugins/org.dita.base/build_preprocess_template.xml", search inside it for "dita:depends" to see how your target would get called depending on what extension point it implements.

Could you tell me more precisely what changes you want to make to the DITA XML content? I could try to maybe recommend you a better extension point.

Also as this question is DITA OT specific I would recommend in the future opening a discussion on the DITA OT discussions list:
https://github.com/orgs/dita-ot/discussions/
or write an email on the DITA Users List: https://dita-users.groups.io/g/main

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Re: Chain transformations, dita + HTML5

Post by gbv34 »

Thanks a lot, Radu!
I was able to check the different points you listed and designing the plugin in Oxygen highly helps indeed :)

Right now, the use case is pretty simple, I just want to add a string into the first paragraphs of the DITA source (not in the HTML( publishing that I want to publish after the DITA files modification).

This is more a rudimentary test to understand the logics with the extension points and being able to preprocessDITA content before processing it as HTML or XHTML. Why am I looking this workaround, because I publish documentation in a portal which uses a specific OT and gets rid of certain content that are processed through a regular extension point like this one that I use most of the time:

Code: Select all

<feature extension="dita.xsl.html5" file="xsl/revhistory-topic.xsl"/>
That's why I would like to provide an update DITA content through the plugin.
------
Gaspard
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Chain transformations, dita + HTML5

Post by Radu »

Hi Gaspard,

If you look in the build file "DITA-OT3.x/plugins/org.dita.base/build_preprocess_template.xml" the "preprocess" target depends on a bunch of other targets which expand map references, replace key refs with direct links, resolve conrefs, conkeyrefs, apply profiling. Each of these preprocessing tasks usually read the content already placed in a temporary files folder and then write it again to the same temporary files folder. Usually regular plugin developers do not change pre-processing steps.
There is a "depend.preprocess.post" extension point which could be interesting to you, it's called at the end of the pre-processing when all the conrefs have been expanded, all the filters have been applied and the pre-processed DITA XML content is present in the temporary files folder. So this is a stage after preprocess but before the XSLT which produces HTML has been applied.
To see how to apply the XSLT in your plugin, you can look for example how the conref expansion ANT target looks like:

Code: Select all

<target name="conref" 
    dita:depends="{depend.preprocess.conref.pre}"
    dita:extension="depends org.dita.dost.platform.InsertDependsAction"
    unless="preprocess.conref.skip"
    description="Resolve conref in input files">
    <property name="dita.preprocess.reloadstylesheet.conref" value="${dita.preprocess.reloadstylesheet}"/>
    <makeurl property="exportfile.url" file="${dita.temp.dir}/export.xml" validate="false"/>
    <pipeline message="Resolve conref in input files" taskname="conref">
      <xslt basedir="${dita.temp.dir}"
        reloadstylesheet="${dita.preprocess.reloadstylesheet.conref}"
        style="${dita.plugin.org.dita.base.dir}/xsl/preprocess/conref.xsl" filenameparameter="file-being-processed"
        parallel="${parallel}">
        <ditafileset conref="true"/>
        <param name="EXPORTFILE" expression="${exportfile.url}"/>
        <param name="TRANSTYPE" expression="${transtype}"/>
        <dita:extension id="dita.preprocess.conref.param" behavior="org.dita.dost.platform.InsertAction"/>
      </xslt>
    </pipeline>
  </target>
So your custom post-process target would probably look something like:

Code: Select all

<target name="custom.post-process" 
    description="Custom Post Process">
    <pipeline message="XSLT Post Process">
      <xslt basedir="${dita.temp.dir}"
        style="${dita.plugin.com.xxx.beforeafter}/xsl/post-process.xsl">
	<ditafileset format="dita"/>
      </xslt>
    </pipeline>
  </target>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply