Project

General

Profile

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