Index: modules/dnet-openaireplus-profiles/trunk/src/main/resources/eu/dnetlib/test/profiles/TransformationRuleDSResources/TransformationRuleDSResourceType/funders/fct_2_db.xml
===================================================================
--- modules/dnet-openaireplus-profiles/trunk/src/main/resources/eu/dnetlib/test/profiles/TransformationRuleDSResources/TransformationRuleDSResourceType/funders/fct_2_db.xml	(revision 60430)
+++ modules/dnet-openaireplus-profiles/trunk/src/main/resources/eu/dnetlib/test/profiles/TransformationRuleDSResources/TransformationRuleDSResourceType/funders/fct_2_db.xml	(revision 60431)
@@ -14,135 +14,381 @@
 				<CODE>
 					<![CDATA[
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-                xmlns:xs="http://www.w3.org/2001/XMLSchema"
-                exclude-result-prefixes="xs" version="2.0">
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
 
-	<xsl:param name="varDataSourceId"/>
-	<xsl:variable name="namespacePrefix" select="string('fct_________')"/>
+    <xsl:param name="varDataSourceId"/>
+    <xsl:variable name="namespacePrefix" select="string('fct_________')"/>
 
-	<xsl:variable name="invalid" select="' ,-'"/>
-	<xsl:variable name="valid" select="'___'"/>
+    <xsl:variable name="invalid" select="' ,-'"/>
+    <xsl:variable name="valid" select="'___'"/>
 
-	<xsl:variable name="prefix" select="string('fct_________')"/>
-	<xsl:variable name="funderID" select="concat($prefix, '::FCT')"/>
+    <xsl:variable name="prefix" select="string('fct_________')"/>
+    <xsl:variable name="funderID" select="concat($prefix, '::FCT')"/>
 
-	<xsl:template match="/">
-		<record>
-			<xsl:copy-of select=".//*[local-name()='header']"/>
-			<metadata>
-				<ROWS>
-					<xsl:for-each select="//project">
-						<xsl:call-template name="projectTemplate"/>
-					</xsl:for-each>
-				</ROWS>
-			</metadata>
 
-		</record>
-	</xsl:template>
+    <!--    TO BE USED COUPLED WITH THE OTHER
 
-	<xsl:template name="projectTemplate">
+<xsl:template name="terminate">
+                <xsl:message terminate="yes">
 
-		<xsl:variable name="projectId" select="concat($namespacePrefix, '::',  ./id)"/>
-		<xsl:variable name="projectAcronym" select="./reference"/>
-		<xsl:variable name="tokens" select="tokenize(./reference,'/')"/>
-		<xsl:variable name="callID" select="concat($tokens[1], '/', $tokens[last()])"/>
+                    funder is not FCT; transformation interrupeted
+                </xsl:message>
+            </xsl:template>
 
-		<ROW table="projects">
-			<FIELD name="_dnet_resource_identifier_">
-				<xsl:value-of select="$projectId"/>
-			</FIELD>
-			<FIELD name="id">
-				<xsl:value-of select="$projectId"/>
-			</FIELD>
-			<FIELD name="code">
-				<xsl:value-of select="./id"/>
-			</FIELD>
-			<FIELD name="call_identifier">
-				<xsl:value-of select="$callID"/>
-			</FIELD>
-			<FIELD name="websiteurl">
-				<xsl:value-of select="./refUri"/>
-			</FIELD>
-			<FIELD name="acronym">
-				<xsl:value-of select="./reference"/>
-			</FIELD>
-			<FIELD name="title">
-				<xsl:value-of select="./name"/>
-			</FIELD>
-			<FIELD name="startdate" type="date" format="dd/MM/yyyy">
-				<xsl:value-of select="./startDate"/>
-			</FIELD>
-			<FIELD name="enddate" type="date" format="dd/MM/yyyy">
-				<xsl:value-of select="./endDate"/>
-			</FIELD>
-			<FIELD name="keywords">
-				<xsl:for-each select="./classification/elem">
-					<xsl:if test="position() &gt; 1">,</xsl:if>
-					<xsl:value-of select="."/>
-				</xsl:for-each>
-			</FIELD>
-			<FIELD name="collectedfrom">
-				<xsl:value-of select="$varDataSourceId"/>
-			</FIELD>
+ -->
 
 
-			<FIELD name="provenanceActionClass">sysimport:crosswalk:entityregistry</FIELD>
-			<FIELD name="provenanceActionScheme">dnet:provenanceActions</FIELD>
-			<xsl:if test="string-length(normalize-space(./oaMandate)) &gt; 0">
-				<FIELD name="oa_mandate_for_publications" type="boolean">
-					<xsl:value-of select="./oaMandate"/>
-				</FIELD>
-			</xsl:if>
-			<FIELD name="lastupdate" type="date"><xsl:value-of select="current-dateTime()"/></FIELD>
-		</ROW>
+    <xsl:template name="orgPid">
+        <xsl:param name="organizationPidType"/>
+        <xsl:param name="organizationPidValue"/>
+        <xsl:param name="organizationId"/>
+        <xsl:variable name="organizationPid"
+            select="concat($organizationPidType, ':', $organizationPidValue)"/>
+        <ROW table="dsm_identities">
+            <FIELD name="_dnet_resource_identifier_">
+                <xsl:value-of select="concat($organizationPid, '@@', $organizationPidType)"/>
+            </FIELD>
+            <FIELD name="pid">
+                <xsl:value-of select="$organizationPid"/>
+            </FIELD>
+            <FIELD name="issuertype">
+                <xsl:value-of select="$organizationPidType"/>
+            </FIELD>
+        </ROW>
+        <ROW table="dsm_organizationpids">
+            <FIELD name="organization">
+                <xsl:value-of select="$organizationId"/>
+            </FIELD>
+            <FIELD name="_dnet_resource_identifier_">
+                <xsl:value-of select="concat($organizationPid, '@@', $organizationId)"/>
+            </FIELD>
+            <FIELD name="pid">
+                <xsl:value-of select="$organizationPid"/>
+            </FIELD>
+        </ROW>
 
-		<xsl:for-each select="./funding">
-			<xsl:variable name="p1" select="normalize-space(./program)"/>
-			<xsl:variable name="p2" select="normalize-space(./program2)"/>
 
-			<xsl:variable name="tmpFundingId">
-				<xsl:choose>
-					<xsl:when test="string-length($p1) &gt; 0 and string-length($p2) &gt; 0">
-						<xsl:value-of select="concat($funderID, '::', $p1, '::', $p2)"/>
-					</xsl:when>
-					<xsl:when test="string-length($p1) &gt; 0">
-						<xsl:value-of select="concat($funderID, '::', $p1)"/>
-					</xsl:when>
-					<xsl:otherwise></xsl:otherwise>
-				</xsl:choose>
-			</xsl:variable>
 
-			<xsl:variable name="fundingId" select="normalize-space($tmpFundingId)"/>
 
-			<xsl:if test="string-length($fundingId) &gt; 0">
-				<ROW table="project_fundingpath">
-					<FIELD name="_dnet_resource_identifier_">
-						<xsl:value-of select="concat($fundingId, '@@', $projectId)"/>
-					</FIELD>
-					<FIELD name="funding">
-						<xsl:value-of select="$fundingId"/>
-					</FIELD>
-					<FIELD name="project">
-						<xsl:value-of select="$projectId"/>
-					</FIELD>
-					<FIELD name="startdate" type="date" format="dd/MM/yyyy">
-						<xsl:value-of select="../startDate"/>
-					</FIELD>
-					<FIELD name="enddate" type="date" format="dd/MM/yyyy">
-						<xsl:value-of select="../endDate"/>
-					</FIELD>
-					<FIELD name="optional1">
-						<xsl:value-of select="./amount"/>
-					</FIELD>
-					<FIELD name="optional2">
-						<xsl:value-of select="./dateAwarded"/>
-					</FIELD>
-				</ROW>
-			</xsl:if>
-		</xsl:for-each>
+    </xsl:template>
+    <xsl:template name="orgTempalte">
 
-	</xsl:template>
+        <xsl:param name="elem"/>
+        <xsl:param name="role"/>
+        <xsl:param name="projectId"/>
+        <xsl:variable name="organizationId"
+            select="concat($namespacePrefix, '::', $elem/*[local-name() = 'OrgUnit']/@id)"/>
+        <ROW table="dsm_organizations">
+            <FIELD name="_dnet_resource_identifier_">
+                <xsl:value-of select="$organizationId"/>
+            </FIELD>
+            <FIELD name="id">
+                <xsl:value-of select="$organizationId"/>
+            </FIELD>
+            <FIELD name="legalname">
+                <xsl:value-of select="normalize-space($elem//*[local-name() = 'Name'])"/>
+            </FIELD>
+            <FIELD name="legalshortname">
+                <xsl:value-of select="normalize-space($elem//*[local-name() = 'Acronym'])"/>
+            </FIELD>
+            <xsl:for-each
+                select=".//*[local-name() = 'Type'][@scheme = 'https://w3id.org/cerif/vocab/OrganisationTypes' and @xml:lang = 'en']">
+                <xsl:choose>
+                    <xsl:when test=". = 'Higher Education'">
+                        <FIELD name="ec_highereducation" type="boolean">
+                            <xsl:value-of select="true()"/>
+                        </FIELD>
+                    </xsl:when>
+                    <xsl:when test=". = 'Research Institute'">
+                        <FIELD name="ec_researchorganization" type="boolean">
+                            <xsl:value-of select="true()"/>
+                        </FIELD>
+                    </xsl:when>
+                    <xsl:when test=". = 'Private non-profit'">
+                        <FIELD name="ec_nonprofit" type="boolean">
+                            <xsl:value-of select="true()"/>
+                        </FIELD>
+                    </xsl:when>
+                </xsl:choose>
+
+            </xsl:for-each>
+
+            <FIELD name="websiteurl">
+                <xsl:value-of
+                    select="$elem//*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#URL']"
+                />
+            </FIELD>
+            <FIELD name="collectedfrom">
+                <xsl:value-of select="$varDataSourceId"/>
+            </FIELD>
+            <FIELD name="provenanceaction">sysimport:crosswalk:entityregistry</FIELD>
+            <FIELD name="lastupdate" type="date">
+                <xsl:value-of select="current-dateTime()"/>
+            </FIELD>
+        </ROW>
+        <ROW table="project_organization">
+            <FIELD name="_dnet_resource_identifier_">
+                <xsl:value-of select='concat($projectId, "@@", $organizationId)'/>
+            </FIELD>
+            <FIELD name="project">
+                <xsl:value-of select="$projectId"/>
+            </FIELD>
+            <FIELD name="resporganization">
+                <xsl:value-of select="$organizationId"/>
+            </FIELD>
+
+            <FIELD name="semanticclass">
+                <xsl:value-of select="$role"/>
+            </FIELD>
+
+        </ROW>
+        <xsl:if
+            test="$elem//*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#ISNI']">
+            <xsl:call-template name="orgPid">
+                <xsl:with-param name="organizationPidType" select="'ISNI'"/>
+                <xsl:with-param name="organizationPidValue"
+                    select="$elem//*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#ISNI']"/>
+                <xsl:with-param name="organizationId" select="$organizationId"/>
+            </xsl:call-template>
+        </xsl:if>
+        <xsl:if
+            test="$elem//*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#RingGold']">
+            <xsl:call-template name="orgPid">
+                <xsl:with-param name="organizationPidType" select="'RingGold'"/>
+                <xsl:with-param name="organizationPidValue"
+                    select="$elem//*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#RingGold']"/>
+                <xsl:with-param name="organizationId" select="$organizationId"/>
+            </xsl:call-template>
+        </xsl:if>
+        <xsl:if
+            test="$elem//*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#NIF']">
+            <xsl:call-template name="orgPid">
+                <xsl:with-param name="organizationPidType" select="'NIF'"/>
+                <xsl:with-param name="organizationPidValue"
+                    select="$elem//*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#NIF']"/>
+                <xsl:with-param name="organizationId" select="$organizationId"/>
+            </xsl:call-template>
+        </xsl:if>
+        <xsl:if
+            test="$elem//*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#DGEEC']">
+            <xsl:call-template name="orgPid">
+                <xsl:with-param name="organizationPidType" select="'DGEEC'"/>
+                <xsl:with-param name="organizationPidValue"
+                    select="$elem//*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#DGEEC']"/>
+                <xsl:with-param name="organizationId" select="$organizationId"/>
+            </xsl:call-template>
+        </xsl:if>
+    </xsl:template>
+
+    <!--    TO BE USED IF SOME OF THE PROJECTS ARE NOT FROM FCT
+
+<xsl:template match="/">
+<xsl:choose>
+<xsl:when test="//*[local-name() = 'Funded']//*[local-name() = 'Acronym'] = 'FCT'">
+        <record>
+            <xsl:copy-of select=".//*[local-name() = 'header']"/>
+            <metadata>
+                <ROWS>
+                    <xsl:for-each select="//*[local-name() = 'Project']">
+                        <xsl:call-template name="projectTemplate"/>
+                    </xsl:for-each>
+                </ROWS>
+            </metadata>
+
+        </record>
+</xsl:when>
+<xsl:otherwise>
+<FunderAcronym>
+<xsl:value-of select="//*[local-name() = 'Funded']//*[local-name() = 'Acronym'] "/>
+</FunderAcronym>
+</xsl:otherwise>
+</xsl:choose>
+    </xsl:template>
+
+-->
+
+    <xsl:template match="/">
+
+        <record>
+            <xsl:copy-of select=".//*[local-name() = 'header']"/>
+            <metadata>
+                <ROWS>
+                    <xsl:for-each select="//*[local-name() = 'Project']">
+                        <xsl:call-template name="projectTemplate"/>
+                    </xsl:for-each>
+                </ROWS>
+            </metadata>
+
+        </record>
+
+    </xsl:template>
+
+    <xsl:template name="projectTemplate">
+        <xsl:variable name="projectCode"
+            select="./*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#ProjectReference']"/>
+        <xsl:variable name="projectId" select="concat($namespacePrefix, '::', $projectCode)"/>
+        <!--<xsl:variable name="projectAcronym" select="./*[local-name() = 'Acronym']"/>-->
+        <xsl:variable name="projectTitle" select="./*[local-name() = 'Title'][@xml:lang = 'en']"/>
+        <xsl:variable name="startDate" select="./*[local-name() = 'StartDate']"/>
+        <xsl:variable name="endDate" select="./*[local-name() = 'EndDate']"/>
+        <xsl:variable name="projectSummary" select="./*[local-name() = 'Abstract']"/>
+        <xsl:variable name="tokens" select="tokenize($projectCode, '/')"/>
+        <xsl:variable name="callID" select="concat($tokens[1], '/', $tokens[last()])"/>
+        <xsl:variable name="projectKeywords"
+            select="./*[local-name() = 'Keyword'][@xml:lang = 'en']"/>
+        <xsl:variable name="contactPerson"
+            select="./*[local-name() = 'Team']/*[local-name() = 'Contact']//*[local-name() = 'PersonName']"/>
+        <xsl:variable name="fundedAmount"
+            select=".//*[local-name() = 'Funding']/*[local-name() = 'Amount']"/>
+        <xsl:variable name="fundedCurrency"
+            select=".//*[local-name() = 'Funding']/*[local-name() = 'Amount']/@currency"/>
+        <xsl:variable name="websiteUrl"
+            select=".//*[local-name() = 'Funding']/*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#URL']"/>
+        <xsl:variable name="coordinatorList" select=".//*[local-name() = 'Coordinator']"/>
+        <xsl:variable name="participantList" select=".//*[local-name() = 'Partner']"/>
+
+        <ROW table="projects">
+            <FIELD name="_dnet_resource_identifier_">
+                <xsl:value-of select="$projectId"/>
+            </FIELD>
+            <FIELD name="id">
+                <xsl:value-of select="$projectId"/>
+            </FIELD>
+            <FIELD name="code">
+                <xsl:value-of select="$projectCode"/>
+            </FIELD>
+
+            <!--   <FIELD name="websiteurl">
+                <xsl:choose>
+                    <xsl:when test="contains($websiteUrl,'?idProjecto')">
+                        <xsl:value-of select="$websiteUrl"/>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:variable name="prefix" select="substring-before($websiteUrl, 'idProjecto')"/>
+
+                        <xsl:value-of select="concat($prefix, '?', substring-after($websiteUrl, $prefix))"/>
+                    </xsl:otherwise>
+                </xsl:choose>
+
+            </FIELD> -->
+            <!--   <FIELD name="call_identifier">
+                <xsl:value-of select="$callID"/>
+            </FIELD> -->
+            <FIELD name="title">
+                <xsl:value-of select="$projectTitle"/>
+            </FIELD>
+            <FIELD name="summary">
+                <xsl:value-of select="$projectSummary"/>
+            </FIELD>
+            <FIELD name="startdate" type="date" format="yyyy/MM/dd">
+                <xsl:value-of select="$startDate"/>
+            </FIELD>
+            <FIELD name="enddate" type="date" format="yyyy/MM/dd">
+                <xsl:value-of select="$endDate"/>
+            </FIELD>
+            <FIELD name="keywords">
+                <xsl:value-of select="$projectKeywords"/>
+            </FIELD>
+            <FIELD name="contactfullname">
+                <xsl:value-of select="$contactPerson"/>
+            </FIELD>
+
+            <FIELD name="fundedamount" type="float">
+                <xsl:value-of select="$fundedAmount"/>
+            </FIELD>
+            <FIELD name="currency">
+                <xsl:value-of select="$fundedCurrency"/>
+            </FIELD>
+
+            <FIELD name="collectedfrom">
+                <xsl:value-of select="$varDataSourceId"/>
+            </FIELD>
+            <FIELD name="contracttypescheme">fct:contractTypes</FIELD>
+            <FIELD name="provenanceActionClass">sysimport:crosswalk:entityregistry</FIELD>
+            <FIELD name="provenanceActionScheme">dnet:provenanceActions</FIELD>
+            <xsl:if test="//*[local-name() = 'OAMandate']">
+                <FIELD name="oa_mandate_for_publications" type="boolean">
+                    <xsl:value-of select="lower-case(//*[local-name() = 'OAMandate']/@mandated)"/>
+                </FIELD>
+            </xsl:if>
+            <FIELD name="lastupdate" type="date">
+                <xsl:value-of select="current-dateTime()"/>
+            </FIELD>
+        </ROW>
+
+        <xsl:variable name="p1"
+            select="normalize-space(./*[local-name() = 'Identifier'][@type = 'https://w3id.org/cerif/vocab/IdentifierTypes#FundingProgram'])"/>
+
+
+        <xsl:variable name="fundingId">
+            <xsl:choose>
+                <xsl:when test="string-length($p1) > 0">
+                    <xsl:value-of select="concat($funderID, '::', $p1)"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="$funderID"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+
+
+
+
+        <ROW table="project_fundingpath">
+            <FIELD name="_dnet_resource_identifier_">
+                <xsl:value-of select="concat($fundingId, '@@', $projectId)"/>
+            </FIELD>
+            <FIELD name="funding">
+                <xsl:value-of select="$fundingId"/>
+            </FIELD>
+            <FIELD name="project">
+                <xsl:value-of select="$projectId"/>
+            </FIELD>
+            <FIELD name="startdate" type="date" format="yyyy/MM/dd">
+                <xsl:value-of select="$startDate"/>
+            </FIELD>
+            <FIELD name="enddate" type="date" format="yyyy/MM/dd">
+                <xsl:value-of select="$endDate"/>
+            </FIELD>
+        </ROW>
+
+
+        <xsl:for-each select="$coordinatorList">
+            <xsl:variable name="role">
+                <xsl:choose>
+                    <xsl:when test="position() = 1">
+                        <xsl:value-of select="coordinator"/>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:value-of select="participant"/>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </xsl:variable>
+            <xsl:call-template name="orgTempalte">
+                <xsl:with-param name="elem" select="."/>
+                <xsl:with-param name="role" select="$role"/>
+
+                <xsl:with-param name="projectId" select="$projectId"/>
+            </xsl:call-template>
+
+        </xsl:for-each>
+
+        <xsl:for-each select="$participantList">
+            <xsl:variable name="role">
+                <xsl:value-of select="participant"/>
+            </xsl:variable>
+            <xsl:call-template name="orgTempalte">
+                <xsl:with-param name="elem" select="."/>
+                <xsl:with-param name="role" select="$role"/>
+                <xsl:with-param name="projectId" select="$projectId"/>
+            </xsl:call-template>
+        </xsl:for-each>
+
+
+
+    </xsl:template>
 </xsl:stylesheet>
+
 ]]>
 				</CODE>
 			</SCRIPT>
