I'm working on a DITA-OT plugin that calls a function from a JAR file. When I generate XHTML, the plugin finds the function. When I generate a PDF, it doesn't. I've read the DITA-OT docs about creating plugins and making JAR files available to them, and I've followed some leads from the google, but cannot figure out why this is happening.
Here's a simplified example that demonstrates the behavior.
Here's plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<plugin id="com.example.test.import">
<feature extension="dita.conductor.lib.import" file="ztest.jar" />
<feature extension="dita.xsl.xhtml" file="testimport.xsl" />
<feature extension="dita.xsl.xslfo" file="testimport.xsl" />
</plugin>
Here's the XSL stylesheet testimport.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:z="java:ztest.Ztest"
version="2.0" >
<xsl:template match="concept">
<xsl:call-template name="test"
use-when="function-available('z:zmsg')">
<xsl:with-param name="txt"
select="z:zmsg()" />
</xsl:call-template>
<xsl:call-template name="fail"
use-when="not(function-available('z:zmsg'))" />
<xsl:apply-templates />
</xsl:template>
<xsl:template name="test">
<xsl:param name="txt" />
<xsl:message>xxx txt from function z:zmsg = <xsl:value-of select="$txt"/></xsl:message>
</xsl:template>
<xsl:template name="fail">
<xsl:message>xxx Function z:zmsg is not available.</xsl:message>
</xsl:template>
</xsl:stylesheet>
I'm using DITA-OT 2.1.2. THE DITA-OT is unmodified (except for my plugin). No custom XSL for formatting. For DITA source, I'm using a file in the DITA-OT samples directory. It's a simple concept topic:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN"
"../../dtd/technicalContent/dtd/concept.dtd">
<concept id="lawnmowerconcept" xml:lang="en-us">
<title>Lawnmower</title>
<shortdesc>The lawnmower is a machine used to cut grass in the yard.</shortdesc>
<conbody><p>Lawnmowers can be electric, gas-powered, or manual.</p></conbody>
</concept>
I tried building from the command line using the dita command and the ant command.
Here's the dita command for XHTML output:
c:\dita\dita-ot\bin>dita -i ../samples/concepts/lawnmower.xml -f xhtml -o ../samples/atest -v
Here's the dita command for PDF output:
c:\dita\dita-ot\bin>dita -i ../samples/concepts/lawnmower.xml -f pdf -o ../samples/atest -v
Here's the ant command for XHTML output:
C:\dita\dita-ot\bin>ant -f ..\build.xml -Dargs.input=samples\concepts\lawnmower.xml -Dtranstype=xhtml -Doutput.dir=samples\atest
Here's the ant command for PDF output:
C:\dita\dita-ot\bin>ant -f ..\build.xml -Dargs.input=samples\concepts\lawnmower.xml -Dtranstype=pdf -Doutput.dir=samples\atest
When the transtype is xhtml, the "txt from function z:zmsg" message appears in the log:
dita.inner.topics.html.common:
[xslt] Transforming into c:\dita\dita-ot\samples\atest
[xslt] Processing c:\tmp\temp20151105150253420\lawnmower.xml to c:\dita\dita-ot\samples\atest\lawnmower.html
[xslt] Loading stylesheet c:\dita\dita-ot\plugins\org.dita.xhtml\xsl\dita2xhtml.xsl
[xslt] xxx txt from function z:zmsg = String from Ztest.zmsg
...
When the transtype is pdf2, the "Function z:zmsg is not available" message appears in the log:
transform.topic2fo.main:
[xslt] Processing c:\tmp\temp20151105143733996\stage1a.xml to c:\tmp\temp20151105143733996\stage2.fo
[xslt] Loading stylesheet c:\dita\dita-ot\plugins\org.dita.pdf2\xsl\fo\topic2fo_shell_fop.xsl
[xslt] xxx Function z:zmsg is not available.
...
Finally, here's the Java source for the Ztest class and the zmsg() function:
package ztest;
public class Ztest {
public static void main(String[] args) {
System.out.println(zmsg());
}
public static String zmsg() {
return "String from Ztest.zmsg";
}
}
In this example, the transformation does not complete successfully, but it does show the messages when the function is found and not found.