To describe the steps involved in creating a DITA Open Toolkit plugin this section uses an example of creating an XSLT customization plugin that provides syntax highlighting when publishing DITA codeblock elements to HTML and PDF output formats. This plugin (com.oxygenxml.highlight) is available in the DITA Open Toolkit distribution that comes bundled with the latest version of Oxygen XML Editor, but these instructions show you how to create it as if it were not included.
The steps to help you to create the plugin are as follows:
For example:
[OXYGEN_DIR]/frameworks/dita/DITA-OT/plugins/com.oxygenxml.highlight
<plugin id="com.oxygenxml.highlight"> <feature extension="package.support.name" value="Oxygen XML Editor Support"/> <feature extension="package.support.email" value="support@oxygenxml.com"/> <feature extension="package.version" value="1.0.0"/> <feature extension="dita.xsl.xhtml" value="xhtmlHighlight.xsl" type="file"/> <feature extension="dita.xsl.xslfo" value="pdfHighlight.xsl" type="file"/> </plugin>
The most important extensions in it are the references to the XSLT stylesheets that will be used to style the HTML and PDF outputs.
You can find other DITA OT plugin extension points here: http://dita-ot.sourceforge.net/1.5.3/dev_ref/extension-points.html
<xsl:template match="*[contains(@class,' topic/pre ')]" name="topic.pre"> <xsl:apply-templates select="." mode="pre-fmt" /> </xsl:template>
<xsl:template match="*[contains(@class,' topic/pre ')]" name="topic.pre"> <!-- This template is deprecated in DITA-OT 1.7. Processing will moved into the main element rule. --> <xsl:if test="contains(@frame,'top')"><hr /></xsl:if> <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/> <xsl:call-template name="spec-title-nospace"/> <pre> <xsl:attribute name="class"><xsl:value-of select="name()"/></xsl:attribute> <xsl:call-template name="commonattributes"/> <xsl:call-template name="setscale"/> <xsl:call-template name="setidaname"/> <!--Here I'm calling the styler of the content inside the codeblock.--> <xsl:call-template name="outputStyling"/> </pre> <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/> <xsl:if test="contains(@frame,'bot')"><hr /></xsl:if><xsl:value-of select="$newline"/> </xsl:template>
You could also use another XSLT template that applies the XSLTHL library as a Java extension to style the content.
In this case we found an appropriate XSLT stylesheet [OXYGEN_DIR]/frameworks/dita/DITA-OT/plugins/legacypdf/xslfo/dita2fo-elems.xsl to use as a template that we use to overwrite our pdfHighlight.xsl stylesheet, which results in the following:
<xsl:template match="*[contains(@class,' topic/pre ')]"> <xsl:call-template name="gen-att-label"/> <fo:block xsl:use-attribute-sets="pre"> <!-- setclass --> <!-- set id --> <xsl:call-template name="setscale"/> <xsl:call-template name="setframe"/> <xsl:apply-templates/> </fo:block> </xsl:template>
Apply
Transformation Scenario(s) dialog. If the integrator is not visible, enable
the Show all scenarios action that is available in the
settings drop-down list. For more
information, see Installing a Plugin in the DITA Open Toolkit.Results of running the integrator using our example:
XSLT content is applied with priority when publishing to both HTML and PDF outputs.
<xsl:import href="../plugins/com.oxygenxml.highlight/xhtmlHighlight.xsl"/>
This import is placed after all base imports and thus has a higher priority. See more about imported template precedence in the XSLT specs: http://www.w3.org/TR/xslt#import
<xsl:import href="../../../com.oxygenxml.highlight/pdfHighlight.xsl"/>
Now, you can distribute your plugin folder to anyone that has a DITA OT installation along with some simple installation notes. Your customization will work as long as the templates you are overwriting have not changed from one DITA OT distribution to the other.