Skip to content

LabelledEntriesXSLTWithContext

Christian Lück edited this page Aug 12, 2022 · 4 revisions

de.wwu.scdh.teilsp.extensions.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.

Arguments

script

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.

parameters

Optional: Arbitrary external variables passed to your Xslt script. This has the form

VARIABLE1_NAME=VALUE1,VARIABLE2_NAME=VALUE2

templateLName

Optional: The local name of the XSLT template to call.

templatePrefix

Optional: The prefix of the Xslt template to call.

templateNamespace

Optioal: The namespace of the template to call.

Requirements for the Xslt script

  • 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 prefix obt is bound to http://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 key and a key named label for the key and label of the labelled entries.

  • See witnesses-context.xsl to get an idea.

Sample configuration

        <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>

Generating suggestions from <prefixDef>

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>

Clone this wiki locally