From 7e9638a0ddf9c28e18a8bbf3ac6405cac0eccd0f Mon Sep 17 00:00:00 2001 From: David Maus <maus@hab.de> Date: Fri, 16 Feb 2018 10:23:41 +0100 Subject: [PATCH] Normalisiere file/@ID und @FILEID --- src/xslt/mets.xsl | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/xslt/mets.xsl b/src/xslt/mets.xsl index 6530acf..f22742e 100644 --- a/src/xslt/mets.xsl +++ b/src/xslt/mets.xsl @@ -2,18 +2,24 @@ exclude-result-prefixes="#all" xpath-default-namespace="http://www.loc.gov/METS/" xmlns="http://www.loc.gov/METS/" + xmlns:fun="tag:maus@hab.de,2018-02:XSLT" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Normalisiert die von Kitodo.Production erzeugte METS-Datei --> + <xsl:param name="objectId" as="xs:string" required="yes"/> + + <xsl:key name="files" match="file" use="@ID"/> <xsl:template match="node() | @*"> <xsl:copy><xsl:apply-templates select="node() | @*"/></xsl:copy> </xsl:template> <xsl:template match="mets"> - <xsl:copy> + <mets OBJID="{$objectId}"> <xsl:apply-templates/> - </xsl:copy> + </mets> </xsl:template> <xsl:template match="metsHdr"> @@ -24,4 +30,17 @@ </metsHdr> </xsl:template> + <xsl:template match="@ID[parent::file]"> + <xsl:attribute name="ID" select="fun:normalize-fileId(..)"/> + </xsl:template> + + <xsl:template match="@FILEID"> + <xsl:attribute name="FILEID" select="fun:normalize-fileId(key('files', .))"/> + </xsl:template> + + <xsl:function name="fun:normalize-fileId" as="xs:string"> + <xsl:param name="file" as="element(file)"/> + <xsl:value-of select="string-join( ('image', if ($file/../@USE) then lower-case($file/../@USE) else (), tokenize($file/FLocat/@xlink:href, '/')[last()]), '.')"/> + </xsl:function> + </xsl:transform> -- GitLab