implement-saxon-extension-functions.html 8.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html
  2. SYSTEM "about:legacy-compat">
  3. <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="UTF-8"><meta name="copyright" content="(C) Copyright 2019"><meta name="DC.rights.owner" content="(C) Copyright 2019"><meta name="DC.type" content="topic"><meta name="description" content="Plug-ins can contribute Saxon extension functions for use in XSLT transformations run by DITA Open Toolkit."><meta name="DC.subject" content="Saxon, service, Ant, jar, XSLT, Java, extension functions"><meta name="keywords" content="Saxon, service, Ant, jar, XSLT, Java, extension functions"><meta name="DC.relation" scheme="URI" content="../topics/implement-saxon-customizations.html"><meta name="DC.format" content="HTML5"><meta name="DC.identifier" content="implement-saxon-extension-functions"><link rel="stylesheet" type="text/css" href="../css/commonltr.css"><link rel="stylesheet" type="text/css" href="../css/dita-ot-doc.css"><title>Implementing Saxon extension functions</title></head><body id="implement-saxon-extension-functions"><header role="banner"><div class="header">
  4. <p>DITA Open Toolkit</p>
  5. <hr>
  6. </div></header><nav role="toc"><ul><li><a href="../index.html">DITA Open Toolkit 3.3</a></li><li><a href="../release-notes/index.html">Release Notes</a></li><li><a href="../topics/installing-client.html">Installing DITA-OT</a></li><li><a href="../topics/alternative-input-formats.html">Authoring formats</a></li><li><a href="../topics/building-output.html">Building output</a></li><li><a href="../parameters/index.html">Setting parameters</a></li><li><a href="../topics/customizing.html">Customizing DITA-OT</a><ul><li><a href="../topics/html-customization.html">Customizing HTML</a></li><li><a href="../topics/pdf-customization.html">Customizing PDF</a></li><li><a href="../topics/custom-plugins.html">Working with plug-ins</a><ul><li><a href="../topics/plugins-installing.html">Installing plug-ins</a></li><li><a href="../topics/plugins-removing.html">Removing plug-ins</a></li><li><a href="../topics/plugins-registry.html">Plug-in registry</a></li><li><a href="../topics/plugin-configfile.html">Plug-in descriptor file</a></li><li><a href="../topics/plugin-dependencies.html">Plug-in dependencies</a></li><li><a href="../topics/plugin-applications.html">Plug-in applications</a><ul><li><a href="../topics/plugin-xmlcatalog.html">Extending an XML catalog file</a></li><li><a href="../topics/plugin-anttarget.html">Adding a new target to the Ant build process</a></li><li><a href="../topics/plugin-antpreprocess.html">Adding an Ant target to the pre-processing pipeline</a></li><li><a href="../topics/plugin-newtranstype.html">Adding a new transformation type</a></li><li><a href="../topics/plugin-overridestyle.html">Overriding an XSLT-processing step</a></li><li><a href="../topics/using-plugin-URI-extension.html">Referencing files from other plug-ins</a></li><li><a href="../topics/plugin-xsltparams.html">Adding parameters to existing XSLT steps</a></li><li><a href="../topics/plugin-javalib.html">Adding a Java library to the classpath</a></li><li><a href="../topics/plugin-messages.html">Adding new diagnostic messages</a></li><li><a href="../topics/plugin-newextensions.html">Creating a new plug-in extension point</a></li><li><a href="../topics/implement-saxon-customizations.html">Adding Saxon customizations</a><ul><li class="active"><a href="../topics/implement-saxon-extension-functions.html">Saxon extensions</a></li><li><a href="../topics/implement-saxon-collation-uri-resolvers.html">Custom collation URI resolvers</a></li></ul></li></ul></li><li><a href="../topics/plugin-sample.html">Example plugin.xml file</a></li><li><a href="../topics/plugin-best-practices.html">Best practices</a></li><li><a href="../topics/plugin-coding-conventions.html">Coding conventions</a></li></ul></li><li><a href="../extension-points/plugin-extension-points.html">Extension points</a></li><li><a href="../topics/migration.html">Migrating customizations</a></li><li><a href="../topics/globalization.html">Globalizing DITA content</a></li><li><a href="../topics/rebuilding-docs.html">Rebuilding documentation</a></li></ul></li><li><a href="../topics/troubleshooting-overview.html">Troubleshooting</a></li><li><a href="../reference/index.html">Reference</a></li><li><a href="../topics/dita-and-dita-ot-resources.html">Resources</a></li></ul></nav><main role="main"><article role="article" aria-labelledby="ariaid-title1">
  7. <h1 class="title topictitle1" id="ariaid-title1">Implementing Saxon extension functions</h1>
  8. <div class="body"><p class="shortdesc">Plug-ins can contribute Saxon extension functions for use in XSLT transformations run by DITA Open
  9. Toolkit.</p>
  10. <p class="p">Starting with Saxon 9.2, the mechanism for implementing extension functions has changed such that Saxon HE, in
  11. particular, can no longer use the older “reflexive” mechanism for finding Java extension functions using a magic
  12. URL. Instead, you implement extension functions and then register them directly on the Saxon Configuration object.
  13. DITA-OT provides a dynamic mechanism to perform this registration for plug-in-provided extension functions.</p>
  14. <div class="p">To implement extension functions, you must do the following:
  15. <ol class="ol">
  16. <li class="li">Add your plug-in’s JAR file in the DITA-OT class path as described in <a class="xref" href="plugin-javalib.html" title="You can use the dita.conductor.lib.import extension point to add an additional Java library to the DITA-OT classpath parameter.">Adding a Java library to the DITA-OT classpath</a>.</li>
  17. <li class="li">For each function, implement a class that extends
  18. <code class="ph codeph">net.sf.saxon.lib.ExtensionFunctionDefinition</code>. This class provides the namespace name and
  19. function name for the function as well as details about its arguments and so on. See <a class="xref" href="http://www.saxonica.com/html/documentation9.8/extensibility/integratedfunctions" target="_blank">Integrated extension functions</a> in the Saxon documentation.</li>
  20. <li class="li">Include a file named <span class="ph filepath">net.sf.saxon.lib.ExtensionFunctionDefinition</span> in the directory
  21. <span class="ph filepath">META-INF/services</span> in the compiled JAR that your plug-in provides. Each line of the file
  22. must be the name of a class that implements <code class="ph codeph">net.sf.saxon.lib.ExtensionFunctionDefinition</code>: <pre class="pre codeblock"><code>com.example.saxon.functions.Add
  23. com.example.saxon.functions.Substract</code></pre>
  24. <div class="p">You can create the file using <code class="keyword markupname xmlelement">&lt;service&gt;</code> elements in an Ant
  25. <code class="keyword markupname xmlelement">&lt;jar&gt;</code>
  26. task:<pre class="pre codeblock language-xml"><code>&lt;jar destfile="${basedir}/target/lib/example-saxon.jar"&gt;
  27. &lt;service type="net.sf.saxon.lib.ExtensionFunctionDefinition"&gt;
  28. &lt;provider classname="com.example.saxon.functions.Add"/&gt;
  29. &lt;provider classname="com.example.saxon.functions.Subtract"/&gt;
  30. &lt;/service&gt;
  31. &lt;/jar&gt;</code></pre></div></li>
  32. <li class="li">In your XSLT transformations, declare the namespace the functions are bound
  33. to:<pre class="pre codeblock language-xml"><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  34. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  35. <strong class="ph b">xmlns:eg="http://example.com/saxon-extensions"</strong>
  36. version="2.0"&gt;</code></pre></li>
  37. </ol></div>
  38. <div class="p">You should then be able to use the extension functions as you would any other
  39. function:<pre class="pre codeblock language-xml"><code>&lt;xsl:variable name="test" select="<strong class="ph b">eg:add(1, 2)</strong>"/&gt;</code></pre></div>
  40. </div>
  41. <nav role="navigation" class="related-links"><div class="familylinks"><div class="parentlink"><strong>Parent topic:</strong> <a class="link" href="../topics/implement-saxon-customizations.html" title="Plug-ins can contribute XSLT extension functions and collation URI resolvers. These customizations are automatically configured to work with Saxon when transformations are run using the DITA-OT pipeline task with custom XSLT.">Adding Saxon customizations</a></div></div></nav></article></main></body></html>