84 lines
No EOL
9.7 KiB
HTML
84 lines
No EOL
9.7 KiB
HTML
<!DOCTYPE html
|
||
SYSTEM "about:legacy-compat">
|
||
<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 2020"><meta name="generator" content="DITA-OT"><meta name="description" content="Plug-ins can provide custom URI resolvers that provide collators for specific collation URIs."><meta name="keywords" content="Saxon, service, Ant, jar, xsl:sort, Chinese, I18N, plug-in, XSLT, URI resolver"><link rel="stylesheet" type="text/css" href="../css/commonltr.css"><link rel="stylesheet" type="text/css" href="../css/dita-ot-doc.css"><title>Implementing custom Saxon collation URI resolvers</title></head><body id="implement-saxon-collation-uri-resolvers"><header role="banner"><div class="header">
|
||
<p>DITA Open Toolkit</p>
|
||
<hr>
|
||
</div></header><nav role="toc"><ul><li><a href="../index.html">DITA Open Toolkit 3.6</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/building-output.html">Building output</a></li><li><a href="../topics/input-formats.html">Authoring formats</a></li><li><a href="../topics/output-formats.html">Output formats</a></li><li><a href="../parameters/index.html">Parameters</a></li><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/adding-plugins.html">Adding plug-ins</a></li><li><a href="../topics/custom-plugins.html">Creating plug-ins</a><ul><li><a href="../topics/plugin-benefits.html">Plug-in benefits</a></li><li><a href="../topics/plugin-configfile.html">Plug-in descriptor file</a></li><li><a href="../topics/plugin-coding-conventions.html">Coding conventions</a></li><li><a href="../topics/plugin-dependencies.html">Plug-in dependencies</a></li><li><a href="../topics/plugin-use-cases.html">Plug-in use cases</a><ul><li><a href="../topics/plugin-set-parameters.html">Setting parameters</a></li><li><a href="../topics/plugin-anttarget.html">Adding a new Ant target</a></li><li><a href="../topics/plugin-antpreprocess.html">Adding a pre-processing step</a></li><li><a href="../topics/plugin-newtranstype.html">Adding a new output format</a></li><li><a href="../topics/plugin-xsltparams.html">Adding new parameters</a></li><li><a href="../topics/plugin-overridestyle.html">Overriding XSLT steps</a></li><li><a href="../topics/plugin-javalib.html">Adding a Java library</a></li><li><a href="../topics/plugin-messages.html">Adding new messages</a></li><li><a href="../topics/plugin-newextensions.html">New extension points</a></li><li><a href="../topics/plugin-xmlcatalog.html">Extending an XML catalog file</a></li><li><a href="../topics/plugin-rewrite-rules.html">Rewriting file names</a></li><li><a href="../topics/implement-saxon-customizations.html">Saxon customizations</a><ul><li><a href="../topics/implement-saxon-extension-functions.html">Saxon extensions</a></li><li class="active"><a href="../topics/implement-saxon-collation-uri-resolvers.html">Custom collation URI resolvers</a></li></ul></li></ul></li><li><a href="../topics/html-customization-plugins.html">Custom HTML plug-ins</a></li><li><a href="../topics/pdf-customization-plugins.html">Custom PDF plug-ins</a></li><li><a href="../topics/globalization.html">Globalizing DITA content</a></li><li><a href="../topics/migration.html">Migrating customizations</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">
|
||
<h1 class="title topictitle1" id="ariaid-title1">Implementing custom Saxon collation URI resolvers</h1>
|
||
|
||
|
||
|
||
<div class="body"><p class="shortdesc">Plug-ins can provide custom URI resolvers that provide collators for specific collation URIs.</p>
|
||
<p class="p">To do custom sorting and grouping in XSLT, you identify collators using URIs that Saxon resolves to collator
|
||
implementations. You implement the mapping from collation URIs to collators through custom collation URI
|
||
resolvers.</p>
|
||
<p class="p">For example, the DITA Community I18N plugin provides a custom collator for doing dictionary-based sorting and
|
||
grouping of Simplified Chinese. </p>
|
||
<p class="p">To allow multiple plug-ins to contribute collation URI resolvers, DITA-OT defines a superinterface of Saxon’s
|
||
<code class="ph codeph">CollationUriResolver</code> interface,
|
||
<code class="ph codeph">org.dita.dost.module.saxon.DelegatingCollationUriResolver</code>, that takes a base resolver.</p>
|
||
<p class="p">Implementations of <code class="ph codeph">DelegatingCollationUriResolver</code> should delegate to their base resolver if they
|
||
do not resolve the URI specified on the resolve request. When multiple plug-ins provide resolvers it results in a
|
||
chain of resolvers, ending with the built-in Saxon default resolver.</p>
|
||
<div class="note note note_note"><span class="note__title">Note:</span> The order in which plug-ins will be processed during collation URI resolver configuration is variable, so two
|
||
plug-ins should not try to resolve the same collation URI. In that case the first one configured will be used at
|
||
run time.</div>
|
||
<div class="p">A typical delegating collation URI resolver looks like
|
||
this:<pre class="pre codeblock language-java"><code>public class DCI18nCollationUriResolver implements DelegatingCollationUriResolver {
|
||
|
||
public static final String DITA_COMMUNITY_I18N_ZH_CNAWARE_COLLATOR =
|
||
"http://org.dita-community.i18n.zhCNawareCollator";
|
||
public static final String LANG_URI_PARAM = "lang";
|
||
|
||
private CollationURIResolver baseResolver;
|
||
|
||
public DCI18nCollationUriResolver() {
|
||
super();
|
||
this.baseResolver = StandardCollationURIResolver.getInstance();
|
||
}
|
||
|
||
|
||
public net.sf.saxon.lib.StringCollator resolve(String uri, Configuration configuration)
|
||
throws XPathException {
|
||
ZhCnAwareCollator collator = resolveToZhCnAwareCollator(uri, null, configuration);
|
||
if (null == collator) {
|
||
return baseResolver.resolve(uri, configuration);
|
||
}
|
||
return (StringCollator) collator;
|
||
}
|
||
|
||
|
||
@Override
|
||
public void setBaseResolver(CollationURIResolver baseResolver) {
|
||
this.baseResolver = baseResolver;
|
||
}
|
||
|
||
/* ... Code to evaluate the collation URI and provide the appropriate collator goes here */
|
||
}</code></pre></div>
|
||
<div class="p">To implement a custom collation URI resolver:
|
||
<ol class="ol">
|
||
<li class="li">Add your plugin’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 classpath</a>.</li>
|
||
<li class="li">Implement an instance of <code class="ph codeph">org.dita.dost.module.saxon.DelegatingCollationUriResolver</code> as
|
||
described above.</li>
|
||
<li class="li">Include a file named <span class="ph filepath">org.dita.dost.module.saxon.DelegatingCollationUriResolver</span> in the
|
||
directory <span class="ph filepath">META-INF/services</span> in the compiled JAR that your plug-in provides. Each line of
|
||
the file must be the name of a class that implements
|
||
<code class="ph codeph">org.dita.dost.module.saxon.DelegatingCollationUriResolver</code>:<pre class="pre codeblock"><code>org.example.i18n.saxon.MyCollationUriResolver</code></pre>
|
||
<div class="p">You can create the services file using <code class="keyword markupname xmlelement"><service></code> elements in an Ant
|
||
<code class="keyword markupname xmlelement"><jar></code>
|
||
task:<pre class="pre codeblock language-xml"><code><jar destfile="${basedir}/target/lib/example-saxon.jar">
|
||
⋮
|
||
<service type="org.dita.dost.module.saxon.DelegatingCollationUriResolver">
|
||
<provider classname="org.example.i18n.saxon.MyCollationUriResolver"/>
|
||
</service>
|
||
⋮
|
||
</jar></code></pre></div></li>
|
||
<li class="li">To use the collator in XSLT style sheets, specify the collation URI on <code class="keyword markupname xmlatt">@xsl:sort</code> elements
|
||
(or anywhere a collator URI can be
|
||
specified):<pre class="pre codeblock language-xml"><code><xsl:apply-templates select="word">
|
||
<xsl:sort collation="http://org.example.i18n.MyCollator"/>
|
||
</xsl:apply-templates></code></pre></li>
|
||
</ol></div>
|
||
</div>
|
||
<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><div class="linklist relinfo"><strong>Related information</strong><br><ul class="linklist"><li class="linklist"><a class="link" href="https://www.oxygenxml.com/events/2015/dita-ot_day.html#DITA_Community" target="_blank" rel="external noopener" title="The DITA Community GitHub organization serves as a general place for people to contribute DITA Open Toolkit plugins and other DITA-related tools and utilities that are not maintained by DITA-OT or other projects. This presentation provides an overview of the DITA Community organization, what's there today, and how you can contribute.">DITA Community</a></li></ul></div></nav></article></main></body></html> |