Project

General

Profile

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
                xmlns:nxsl="http://www.w3.org/1999/XSL/TransformXX" version="2.0"
4
>
5

    
6
	<xsl:output omit-xml-declaration="yes" method="xml"/>
7
	<xsl:namespace-alias stylesheet-prefix="nxsl" result-prefix="xsl"/>
8

    
9
	<xsl:param name="format"/>
10

    
11
	<xsl:template match="/">
12
		<xsl:apply-templates select="//LAYOUT"/>
13
	</xsl:template>
14

    
15
	<xsl:template match="LAYOUT">
16
		<nxsl:stylesheet version="2.0"
17
		                 xmlns:dr="http://www.driver-repository.eu/namespace/dr" xmlns:dc="http://purl.org/dc/elements/1.1/"
18
		                 xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns:dnet="eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions"
19
		                 xmlns:exsl="http://exslt.org/common"
20
		                 extension-element-prefixes="exsl" exclude-result-prefixes="dnet">
21

    
22
			<nxsl:output version="1.0" omit-xml-declaration="yes"
23
			             method="xml"/>
24

    
25
			<nxsl:variable name="format">
26
				<xsl:value-of select="$format"/>
27
			</nxsl:variable>
28

    
29
			<nxsl:template match="/">
30
				<indexRecord>
31
					<indexRecordIdentifier>
32
						<nxsl:value-of select="//dri:objIdentifier"/>
33
					</indexRecordIdentifier>
34
					<targetFields>
35
						<nxsl:if test="count(//*[local-name()='metadata']/*) &gt; 0">
36
							<xsl:apply-templates select="FIELDS/FIELD[@indexable='true']"/>
37
						</nxsl:if>
38
					</targetFields>
39
					<dnetResult>
40
						<nxsl:copy-of select="/*[local-name()='record']/*[local-name()='result']/*[local-name()='header']"/>
41
						<metadata>
42
							<xsl:apply-templates select="FIELDS/FIELD"
43
							                     mode="result"/>
44
						</metadata>
45
					</dnetResult>
46
				</indexRecord>
47
			</nxsl:template>
48
		</nxsl:stylesheet>
49
	</xsl:template>
50

    
51
	<xsl:template match="FIELD[@indexable='true']">
52
		<xsl:choose>
53
			<xsl:when test="@constant">
54
				<xsl:element name="{@name}">
55
					<xsl:value-of select="@constant"/>
56
				</xsl:element>
57
			</xsl:when>
58
			<xsl:when test="@value and not(@xpath)">
59
				<xsl:choose>
60
					<xsl:when test="@type='date'">
61
						<nxsl:variable name="{@name}" select="dnet:normalizeDate(normalize-space({normalize-space(@value)}), false())"/>
62
						<nxsl:if test="string-length(${@name}) &gt; 0">
63
							<nxsl:element name="{@name}">
64
								<nxsl:value-of select="${@name}"/>
65
							</nxsl:element>
66
						</nxsl:if>
67
					</xsl:when>
68
					<xsl:otherwise>
69
						<nxsl:element name="{@name}">
70
							<nxsl:value-of select="{@value}"/>
71
						</nxsl:element>
72
					</xsl:otherwise>
73
				</xsl:choose>
74
			</xsl:when>
75
			<xsl:otherwise>
76
				<xsl:variable name="value">
77
					<xsl:choose>
78
						<xsl:when test="@value">
79
							<xsl:value-of select="@value"/>
80
						</xsl:when>
81
						<xsl:otherwise>
82
							.
83
						</xsl:otherwise>
84
					</xsl:choose>
85
				</xsl:variable>
86
				<nxsl:for-each select="{@xpath}">
87
					<xsl:element name="{@name}">
88
						<xsl:if test="@external='true'">
89
							<xsl:attribute name="external">true</xsl:attribute>
90
						</xsl:if>
91
						<xsl:choose>
92
							<xsl:when test="@tokenizable='false'">
93
								<nxsl:value-of select="normalize-space({normalize-space($value)})"/>
94
							</xsl:when>
95
							<xsl:otherwise>
96
								<nxsl:value-of select="{normalize-space($value)}"/>
97
							</xsl:otherwise>
98
						</xsl:choose>
99
					</xsl:element>
100
				</nxsl:for-each>
101
			</xsl:otherwise>
102
		</xsl:choose>
103
	</xsl:template>
104

    
105

    
106
	<xsl:template match="FIELD" mode="result">
107
		<xsl:if test="@result='true'">
108
			<nxsl:copy-of select="{@xpath}"/>
109
		</xsl:if>
110
	</xsl:template>
111

    
112
	<xsl:template match="FIELD" mode="header">
113
		<xsl:if test="@header='true'">
114
			<nxsl:copy-of select="{@xpath}"/>
115
		</xsl:if>
116
	</xsl:template>
117

    
118
</xsl:stylesheet>
    (1-1/1)