Project

General

Profile

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
    xmlns:oai="http://www.openarchives.org/OAI/2.0/"
4
    xmlns:dnet="http://www.d-net.research-infrastructures.eu/saxon-extension"
5
    xmlns:dri="http://www.driver-repository.eu/namespace/dri"
6
    exclude-result-prefixes="xsl dnet">
7
    
8
    <xsl:variable name="status" select="/*[local-name() = 'record']/*[local-name() = 'header']/@status" />
9
    
10
    <xsl:template match="/">
11
        <oai:record xmlns:oai="http://www.openarchives.org/OAI/2.0/"
12
            xmlns:dri="http://www.driver-repository.eu/namespace/dri">
13
            
14
            <xsl:variable name="datestamp" select="current-dateTime()" />
15
            <xsl:variable name="evaluatedMetadataId" select="normalize-space($xpath$)" />
16
            
17
			<!-- Patch OAI header or create ex-novo if not oai -->
18
            <oai:header>
19
                <xsl:if test="\$status">
20
                    <xsl:attribute name="status" >
21
                        <xsl:value-of select="\$status"/>
22
                    </xsl:attribute>
23
                </xsl:if>
24
                <xsl:if test="not(.//dri:objIdentifier)">
25
                	<xsl:if test="\$evaluatedMetadataId != ''">
26
	                    <dri:objIdentifier><xsl:value-of select="concat('$namespacePrefix$::', dnet:md5(\$evaluatedMetadataId))"/></dri:objIdentifier>
27
                	</xsl:if>
28
                </xsl:if>
29
                <xsl:if test="not(.//dri:recordIdentifier)">
30
                    <dri:recordIdentifier><xsl:value-of select="\$evaluatedMetadataId"/></dri:recordIdentifier>
31
                </xsl:if>
32
                <xsl:if test="not(.//dri:dateOfCollection)">
33
                    <dri:dateOfCollection><xsl:value-of select="\$datestamp"/></dri:dateOfCollection>
34
                </xsl:if>
35
                <xsl:if test="not(.//dri:datasourceprefix)">
36
                    <dri:datasourceprefix>$namespacePrefix$</dri:datasourceprefix>
37
                </xsl:if>
38
                    <dri:datasourcename>$datasourceName$</dri:datasourcename>
39
                    <dri:datasourceapi>$datasourceApi$</dri:datasourceapi>
40
                
41
				<!-- Bulk copy of old header -->
42
                <xsl:for-each select="/*[local-name() = 'record']/*[local-name() = 'header']/*">
43
                    <xsl:copy-of select="."/>
44
                </xsl:for-each>
45
            </oai:header>
46
            
47
			<!-- Handle metadata block -->
48
            <xsl:choose>
49
            	<!-- If OAI then copy copy the metadata block along -->
50
                <xsl:when test="count(/*[local-name() = 'record']/*[local-name() = 'metadata']) &gt; 0">
51
                    <xsl:copy-of select="/*[local-name() = 'record']/*[local-name() = 'metadata']"/>
52
                </xsl:when>
53
                <!-- If OAI copy in bulk the metadata block -->
54
                <xsl:when test="\$status = 'deleted'" />
55
                <!-- If not-OAI copy ALL the record inside metadata block -->
56
                <xsl:otherwise>
57
                    <oai:metadata>
58
                        <xsl:copy-of select="." />
59
                    </oai:metadata>
60
                </xsl:otherwise>
61
            </xsl:choose>
62
            
63
            <!-- Handle oai:about block -->
64
            <oai:about>
65
                <provenance xmlns="http://www.openarchives.org/OAI/2.0/provenance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/provenance http://www.openarchives.org/OAI/2.0/provenance.xsd">
66
  					<originDescription harvestDate="{\$datestamp}" altered="true">
67
	    				<baseURL>$baseurl$</baseURL>
68
	    				<identifier><xsl:value-of select="//*[local-name()='header']/*[local-name()='identifier']"/></identifier>
69
	    				<datestamp><xsl:value-of select="//*[local-name()='header']/*[local-name()='datestamp']"/></datestamp>
70
	    				<metadataNamespace>$metadatanamespace$</metadataNamespace>
71
	    				<xsl:copy-of select="//*[local-name()='provenance']/*[local-name() = 'originDescription']"/>
72
  					</originDescription>
73
				</provenance>
74
			</oai:about>
75
        </oai:record>
76
    </xsl:template>
77
    
78
</xsl:stylesheet>
(2-2/2)