Commit 05f8fb7f authored by Gerrit Hübbers's avatar Gerrit Hübbers 🃏
Browse files

Start work on zoai xslt template

parent a351e5b0
......@@ -923,6 +923,25 @@ public class XsltTransformerOaiPmhBundlesStreamSourceTest {
bss.getBundlesStream().map(Object::toString).forEach(LOG::info);
}
@Test
public void getRecordsSsoar() throws IOException {
Map<String, String> map = new HashMap<>();
String xMetaDissPlusXsltString = IOUtils.toString(
getClass().
getClassLoader().
getResourceAsStream("xslt/ssoar-xoai-2-xmlbundle.xslt"), StandardCharsets.UTF_8);
map.put("xoai", xMetaDissPlusXsltString);
XsltTransformerOaiPmhBundlesStreamSource bss = new XsltTransformerOaiPmhBundlesStreamSource("http://www.ssoar.info/OAIHandler/request", map);
Bundle bundle = bss.getBundle("oai:gesis.izsoz.de:document/28836");
LOG.info("{}", bundle);
Set<Metadatum> metadata = bundle.getMetadata();
metadata.stream().map(Object::toString).forEach(LOG::info);
}
@Test
public void matchDdcString() {
final String NOT_DDC_NUMBERS_PATTERN = "(\\s?\\D+;?)+";
......
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
xmlns:cc="http://www.d-nb.de/standards/cc/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcmitype="http://purl.org/dc/dcmitype/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:ddb="http://www.d-nb.de/standards/ddb/"
xmlns:dini="http://www.d-nb.de/standards/xmetadissplus/type/"
xmlns:doi="http://www.d-nb.de/standards/doi/"
xmlns:hdl="http://www.d-nb.de/standards/hdl/"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:nlm="http://dtd.nlm.nih.gov/publishing/2.3"
xmlns:oai="http://www.openarchives.org/OAI/2.0/"
xmlns:pc="http://www.d-nb.de/standards/pc/"
xmlns:thesis="http://www.ndltd.org/standards/metadata/etdms/1.0/"
xmlns:urn="http://www.d-nb.de/standards/urn/"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xMetaDiss="http://www.d-nb.de/standards/xmetadissplus/"
xmlns:xoai="http://www.lyncode.com/xoai"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:zoai="http://git.gesis.org/dda/zoai"
>
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- <xsl:message terminate="no">here is the tree at the current node <xsl:copy-of select="."/> </xsl:message> -->
<!-- <xsl:message terminate="no">here is some message for stderr, e.g. <xsl:value-of select='text()' /> </xsl:message> -->
<!--
<xsl:for-each select="./*">
<xsl:message terminate="no">a child=<xsl:value-of select="name()"/></xsl:message>
</xsl:for-each>
-->
<!-- override default template -->
<xsl:template match="*" />
<xsl:template match="/">
<xsl:element name="bundle">
<xsl:element name="metadata">
<xsl:apply-templates select="oai:OAI-PMH/oai:GetRecord/oai:record/oai:metadata/xoai:metadata" />
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="oai:OAI-PMH/oai:GetRecord/oai:record/oai:metadata/xoai:metadata">
<xsl:apply-templates></xsl:apply-templates>
</xsl:template>
<xsl:template match="xoai:element">
<xsl:param name="keyHead" />
<xsl:message terminate="no">keyHead=<xsl:value-of select="$keyHead" /> and @name=<xsl:value-of select="@name" /></xsl:message>
<xsl:apply-templates>
<xsl:with-param name="keyHead">
<xsl:choose>
<xsl:when test="$keyHead = ''">
<xsl:value-of select="@name" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat( $keyHead, '.', @name )" />
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="xoai:field">
<xsl:param name="keyHead" />
<xsl:param name="nameLanguageAttribute" />
<xsl:message terminate="no">inside field: keyHead=<xsl:value-of select="$keyHead" /> and @nameAttribute=<xsl:value-of select="@nameLanguageAttribute" /></xsl:message>
</xsl:template>
<xsl:template name="new-metadatum">
<xsl:param name="key" />
<xsl:param name="language" />
<xsl:param name="value" />
<xsl:element name="metadatum">
<xsl:element name="key">
<xsl:value-of select="$key" />
</xsl:element>
<xsl:if test="$language != ''">
<xsl:variable name="sanitizedLanguage" select="zoai:sanitizeLanguage($language)" />
<xsl:element name="language">
<xsl:value-of select="$sanitizedLanguage" />
</xsl:element>
</xsl:if>
<xsl:element name="value">
<xsl:value-of select="$value" />
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:function name="zoai:capitalizeNames">
<xsl:param name="inputString" />
<xsl:variable name="capitalizedNames">
<!-- tokenize an $inputString such as 'AHEDO SANTIESTEBAN' in order to create a $capitalizedNames such as 'Ahedo Santiesteban' -->
<xsl:for-each select="tokenize($inputString,' ')">
<xsl:sequence select="concat( upper-case( substring(., 1, 1) ), lower-case(substring(., 2) ) )"/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select='$capitalizedNames' />
</xsl:function>
<xsl:function name="zoai:cleanIssn">
<xsl:param name="inputString" />
<xsl:choose>
<xsl:when test="matches($inputString, '^\d{4}-\d{4}$')">
<xsl:message terminate="no">when 1</xsl:message>
<xsl:value-of select="$inputString" />
</xsl:when>
<xsl:when test="matches($inputString, '^\d{8}$')">
<xsl:message terminate="no">when 2</xsl:message>
<xsl:value-of select="concat( substring($inputString, 1, 4), '-', substring($inputString, 5) )" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$inputString" />
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="zoai:sanitizeLanguage">
<xsl:param name="inputLanguage" />
<xsl:choose>
<xsl:when test="$inputLanguage = 'ger' or $inputLanguage = 'DE' or $inputLanguage = 'de-DE' or $inputLanguage = 'deu'">
<xsl:value-of select="'de'" />
</xsl:when>
<xsl:when test="$inputLanguage = 'eng' or $inputLanguage = 'EN' or $inputLanguage = 'en-US' or $inputLanguage = 'en-GB'">
<xsl:value-of select="'en'" />
</xsl:when>
<xsl:when test="$inputLanguage = 'spa' or $inputLanguage = 'ES' or $inputLanguage = 'es-ES'">
<xsl:value-of select="'es'" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$inputLanguage" />
</xsl:otherwise>
</xsl:choose>
</xsl:function>
</xsl:stylesheet>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment