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

WIP

parent a2418255
......@@ -66,10 +66,30 @@
</xsl:apply-templates>
</xsl:template>
<xsl:template match="xoai:field">
<xsl:template match="xoai:field[@name='value']">
<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:variable name="rawLanguage">
<xsl:value-of select="tokenize($keyHead,'\.')[last()]"/>
</xsl:variable>
<xsl:message terminate="no">rawLanguage=<xsl:value-of select="$rawLanguage"/> </xsl:message>
<xsl:variable name="metadatumKey">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="haystack" select="$keyHead" />
<xsl:with-param name="lastNeedle" select="'.'" />
</xsl:call-template>
</xsl:variable>
<xsl:message terminate="no">metadatumKey=<xsl:value-of select="$metadatumKey"/> </xsl:message>
<xsl:call-template name="new-metadatum">
<xsl:with-param name="key" select="$metadatumKey"/>
<xsl:with-param name="language" select="$rawLanguage"/>
<xsl:with-param name="value" select="text()"/>
</xsl:call-template>
</xsl:template>
......@@ -84,10 +104,8 @@
</xsl:element>
<xsl:if test="$language != ''">
<xsl:variable name="sanitizedLanguage" select="zoai:sanitizeLanguage($language)" />
<xsl:element name="language">
<xsl:value-of select="$sanitizedLanguage" />
<xsl:value-of select="$language" />
</xsl:element>
</xsl:if>
......@@ -98,50 +116,25 @@
</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>
<!-- via https://stackoverflow.com/a/1119666/923560 -->
<xsl:template name="substring-before-last">
<xsl:param name="haystack" select="''" />
<xsl:param name="lastNeedle" select="''" />
<xsl:if test="$haystack != '' and $lastNeedle != ''">
<xsl:variable name="head" select="substring-before($haystack, $lastNeedle)" />
<xsl:variable name="tail" select="substring-after($haystack, $lastNeedle)" />
<xsl:value-of select="$head" />
<xsl:if test="contains($tail, $lastNeedle)">
<xsl:value-of select="$lastNeedle" />
<xsl:call-template name="substring-before-last">
<xsl:with-param name="haystack" select="$tail" />
<xsl:with-param name="lastNeedle" select="$lastNeedle" />
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
</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