-
Notifications
You must be signed in to change notification settings - Fork 0
LabelledEntriesXSLTWithContext
The plugin
de.wwu.scdh.teilsp.extensions.LabelledEntriesXSLTWithContext is
used to generate completion suggestions via XSLT. The currently edited
document and the editing context are also passed to the XSLT
script. This makes the plugin useful for generating suggestions based
on the the <prefixDef>s in the TEI header, see below.
Required: The path to the XSLT script. This must be a valid URL. Use
the right editor variables to get such an URL,
e.g. ${pdu}/resources/xsl/witnesses-context.xsl to point to
resources/xql/witnesses-context.xsl relative to your project directory URL.
Optional: Arbitrary external variables passed to your Xslt script. This has the form
VARIABLE1_NAME=VALUE1,VARIABLE2_NAME=VALUE2
Optional: The local name of the XSLT template to call.
Optional: The prefix of the Xslt template to call.
Optioal: The namespace of the template to call.
-
The plugin calls a template with the arity 0 (no arguments).
-
the current document is passed into the stylesheet as a parameter of type
document-node():<xsl:param name="document" as="document-node()"/>. This parameter is automatically passed by the plugin. -
the current editing context is passed into the stylesheet an XPath expression pointing to the current node. It's type is
xs:string:<xsl:param name="context" as="xs:string"/>. This parameter is automatically passed by the plugin. -
By default it is
obt:generate-entries(), where the prefixobtis bound tohttp://scdh.wwu.de/oxbytei. -
The name of this template can be choosen by plugin arguments.
-
The template must return
map(xs:string, xs:string)*, i.e. a sequence of maps, where keys and values are strings. Cf. Saxonica's documentation of maps. -
There should (must) be a key named
keyand a key namedlabelfor the key and label of the labelled entries. -
See witnesses-context.xsl to get an idea.
<plugin>
<class>de.wwu.scdh.teilsp.extensions.LabelledEntriesXSLTWithContext</class>
<type>de.wwu.scdh.teilsp.services.extensions.ILabelledEntriesProvider</type>
<configurations>
<configuration>
<conditions>
<condition domain="context">self::*:lem | self::*:rdg</condition>
<condition domain="priority">10</condition>
<condition domain="nodeName">wit</condition>
<condition domain="nodeType">attributeValue</condition>
</conditions>
<arguments>
<argument name="script">${pdu}/resources/xsl/witnesses-context.xsl</argument>
<argument name="parameters">witness-catalog=${pdu}/WitnessCatalogue.xml</argument>
</arguments>
</configuration>
</configurations>
</plugin>Since the currently edited document is passed into the plugin's XSLT
script, this plugin can be used to evaluate <prefixDef>s in the TEI
header and generate suggestions (labelled entries) based on the
information in there. Using this plugin is currently more powerful
than using
de.wwu.scdh.teilsp.extensions.LabelledEntriesFromXMLByPrefixDef,
which lacks proper handling of the XML base property.
There is an XSLT script with generic parts of such a transformation in
entries-prefixDef.xsl. Based
on this script, e.g. a script for generating labelled entries from a
personography might look like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:obt="http://scdh.wwu.de/oxbytei"
xmlns:map="http://www.w3.org/2005/xpath-functions/map" exclude-result-prefixes="xs map obt"
xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="3.0">
<xsl:import href="entries-prefixDef.xsl"/>
<xsl:template mode="generate-entries" match="person[@xml:id]" as="map(xs:string, xs:string)">
<xsl:variable name="key" select="@xml:id" as="xs:string"/>
<xsl:variable name="label">
<xsl:apply-templates mode="label"/>
</xsl:variable>
<xsl:sequence select="
map {
'key': concat($prefix, ':', $key),
'label': $label => string-join('') => normalize-space() => substring(1, 100)
}"/>
</xsl:template>
</xsl:stylesheet>
A configuration might look like follows:
<plugin>
<class>de.wwu.scdh.teilsp.extensions.LabelledEntriesXSLTWithContext</class>
<type>de.wwu.scdh.teilsp.services.extensions.ILabelledEntriesProvider</type>
<configurations>
<configuration>
<conditions>
<condition domain="context">self::*:persName and //*:teiHeader//*:prefixDef[@ident eq 'psn')]</condition>
<condition domain="priority">10</condition>
<condition domain="nodeType">attributeValue</condition>
<condition domain="nodeName">ref</condition>
</conditions>
<arguments>
<argument name="script">${pdu}/resources/xsl/entries-persons.xsl</argument>
<argument name="parameters">prefix=psn</argument>
</arguments>
</configuration>
</configurations>
</plugin>