Date: Thu, 28 Mar 2024 06:55:42 -0400 (EDT) Message-ID: <1664443749.27438.1711623342794@lyrasis1-roc-mp1> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_27437_1949974253.1711623342793" ------=_Part_27437_1949974253.1711623342793 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Sometimes you may want to do a complicated operation in your the= me. While it may be possible to create a XSLT template that achieves the de= sired result, it may be too much code or it may be too slow - XSLT is best = used as a templating language, not a programming language. Especially since= DSpace currently only supports XSLT 1.0, it lacks= many useful functions which are part of XSLT 2.0 and may be too cumbersome= to implement in form of templates.
Luckily, the extensibility of XSLT allows us to call functions implement= ed in other programming languages. In DSpace XMLUI, you call call simple Ja= va functions directly from XSLT.
Let's say we want to use a URL shortening service. This hypothetical ser=
vice ("http://example.com
"=
) requires us to pass the URL we want to be shortened to the service=
as a parameter ("?url=3D
"): http://example.com?url=
=3Dhttp://url-we-want-to-shorten
. But not all characters that can oc=
cur in url-we-want-to-shorten are allowed in a URL parameter value (e.g. th=
e "?", "&" and "=3D" characters). Thus, we need to escape such characte=
rs, which is commonly done by url encoding. Im=
plementing the urlencode function in XSLT would be certainly possible, but =
quite lengthy. Instead, we can just use a Java method from the java.net.URLEncoder class that alr=
eady implements this.
<xsl:= stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" version=3D"1.0" ... xmlns:confman=3D"org.dspace.core.ConfigurationManager" xmlns:urlenc=3D"java.net.URLEncoder" exclude-result-prefixes=3D"xsl ... urlenc"> ... <xsl:template match=3D"dim:dim" name=3D"url-in-url-parameter-example">= ; <a href=3D"{concat('http://example.com?url=3D', urlenc:encode(dim:fi= eld[@element=3D'relation' and @qualifier=3D'uri'], 'UTF-8'))}">example l= ink</a> </xsl:template>
In this use case, we'll explore rendering your theme based on configurat= ion parameters in the DSpace configuration files. To access them, we'll use= the Configur= ationManager class. We'll print the configuration parameter located in = this file: https://github.com/DSpace/DSpace/blob/dspace-5_x/dspace/config/modul= es/discovery.cfg#L8
<xsl:= stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" version=3D"1.0" ... xmlns:confman=3D"org.dspace.core.ConfigurationManager" exclude-result-prefixes=3D"xsl ... confman"> ... <xsl:template name=3D"configuration-value-example"> <xsl:value-of select=3D"confman:getProperty('discovery', 'search.ser= ver')"/> </xsl:template>