From: <sp...@us...> - 2011-05-17 09:15:24
|
Revision: 7721 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=7721&view=rev Author: sppigot Date: 2011-05-17 09:15:17 +0000 (Tue, 17 May 2011) Log Message: ----------- Refactor eml-gbif rifcs xslt Modified Paths: -------------- schemaPlugins/trunk/eml-gbif/convert/rif.xsl Modified: schemaPlugins/trunk/eml-gbif/convert/rif.xsl =================================================================== --- schemaPlugins/trunk/eml-gbif/convert/rif.xsl 2011-05-17 07:32:37 UTC (rev 7720) +++ schemaPlugins/trunk/eml-gbif/convert/rif.xsl 2011-05-17 09:15:17 UTC (rev 7721) @@ -305,8 +305,8 @@ </xsl:element> </xsl:if> - <!-- parties generated here --> - <xsl:for-each-group select="dataset/*[(individualName/surName!='' or positionName!='' or organizationName!='') and not(role='')]" group-by="role"> + <!-- parties generated here - individuals first --> + <xsl:for-each-group select="dataset/*[individualName/surName!='' and not(role='')]" group-by="role"> <xsl:element name="relatedObject"> <xsl:element name="key"> <xsl:choose> @@ -331,6 +331,7 @@ </xsl:element> </xsl:for-each-group> + <!-- parties generated here - now organizations --> <xsl:for-each-group select="dataset/*[organizationName != '' and not(role='') and not(individualName)]" group-by="organizationName"> <xsl:element name="relatedObject"> <xsl:element name="key"> @@ -346,7 +347,8 @@ </xsl:element> </xsl:for-each-group> - <xsl:for-each select="dataset/*[(individualName/surName!='' or positionName!='' or organizationName!='') and (name()='creator' or name()='metadataProvider')]" > + <!-- parties generated here - implied by name of element --> + <xsl:for-each select="dataset/*[(individualName/surName!='' or positionName!='' or organizationName!='') and (name()='creator' or name()='metadataProvider') and not(role)]" > <xsl:element name="relatedObject"> <xsl:element name="key"> <xsl:choose> @@ -406,49 +408,85 @@ </xsl:element> </xsl:element> - <xsl:for-each-group select="//dataset/*[(individualName!='' or positionName!='' or organizationName!='') and not(role='')]" group-by="role"> + <!-- Create all the associated party objects for individuals --> + <xsl:for-each-group select="//dataset/*[(individualName!='') and not(role='')]" group-by="role"> <xsl:element name="registryObject"> + <xsl:call-template name="createPartyRegistryObject"> + <xsl:with-param name="group" select="$group"/> + <xsl:with-param name="originatingSource" select="$originatingSource"/> + <xsl:with-param name="origSource" select="$origSource"/> + </xsl:call-template> + + <xsl:element name="relatedObject"> + <xsl:element name="key"> + <xsl:value-of select="ancestor::eml:eml/dataset/alternateIdentifier[1]"/> + </xsl:element> + <xsl:for-each select="role"> + <xsl:variable name="code"> + <xsl:value-of select="current-grouping-key()"/> + </xsl:variable> + + <xsl:element name="relation"> + <xsl:attribute name="type"> + <xsl:value-of select="$code"/> + </xsl:attribute> + </xsl:element> + </xsl:for-each> + + </xsl:element> + </xsl:element> + </xsl:for-each-group> + + + <!-- Again, sometimes we have an implied role in creator and metadataProvider + elements so process these separately --> + <xsl:for-each-group select="//dataset/*[(individualName!='' or positionName!='' or organizationName!='') and (name()='creator' or name()='metadataProvider') and not(role)]" group-by="name()"> + <xsl:element name="registryObject"> + <xsl:call-template name="createPartyRegistryObject"> + <xsl:with-param name="group" select="$group"/> + <xsl:with-param name="originatingSource" select="$originatingSource"/> + <xsl:with-param name="origSource" select="$origSource"/> + </xsl:call-template> + <xsl:element name="relatedObject"> + <xsl:element name="key"> + <xsl:value-of select="ancestor::eml:eml/dataset/alternateIdentifier[1]"/> + </xsl:element> + + <xsl:variable name="code"> + <xsl:value-of select="current-grouping-key()"/> + </xsl:variable> + + <xsl:element name="relation"> + <xsl:attribute name="type"> + <xsl:value-of select="$code"/> + </xsl:attribute> + </xsl:element> + </xsl:element> + </xsl:element> + </xsl:for-each-group> + + <!-- Create all the associated party objects for organisations --> + <xsl:for-each-group select="//dataset/*[not(individualName) and organizationName!='' and not(role='')]" group-by="organizationName"> + <xsl:element name="registryObject"> <xsl:attribute name="group"> <xsl:value-of select="$group"/> </xsl:attribute> - <xsl:element name="key"> - <xsl:choose> - <xsl:when test="individualName"> - <xsl:apply-templates select="individualName"/> - </xsl:when> - <xsl:when test="string(positionName)"> - <xsl:value-of select="positionName"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="organizationName"/> - </xsl:otherwise> - </xsl:choose> - <!--<xsl:value-of select="current-grouping-key()"/> --> + <xsl:element name="key"> + <xsl:value-of select="current-grouping-key()"/> </xsl:element> <xsl:element name="originatingSource"> - <xsl:choose> - <xsl:when test="not($originatingSource)"> - <xsl:value-of select="$origSource"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="$originatingSource"/> - </xsl:otherwise> - </xsl:choose> + <xsl:choose> + <xsl:when test="not($originatingSource)"> + <xsl:value-of select="$origSource"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$originatingSource"/> + </xsl:otherwise> + </xsl:choose> </xsl:element> <xsl:element name="party"> <xsl:attribute name="type"> - <xsl:choose> - <xsl:when test="individualName"> - <xsl:value-of select="'person'" /> - </xsl:when> - <xsl:when test="string(positionName)"> - <xsl:value-of select="'person'"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="'group'"/> - </xsl:otherwise> - </xsl:choose> - <!--<xsl:text>person</xsl:text>--> + <xsl:text>group</xsl:text> </xsl:attribute> <xsl:element name="name"> <xsl:attribute name="type"> @@ -458,29 +496,19 @@ <xsl:attribute name="type"> <xsl:text>full</xsl:text> </xsl:attribute> - <xsl:choose> - <xsl:when test="individualName"> - <xsl:apply-templates select="individualName"/> - </xsl:when> - <xsl:when test="string(positionName)"> - <xsl:value-of select="positionName"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="organizationName"/> - </xsl:otherwise> - </xsl:choose> - <!--<xsl:value-of select="current-grouping-key()"/>--> + <xsl:value-of select="current-grouping-key()"/> </xsl:element> </xsl:element> - <!-- to normalise parties within a single record we group them --> + <!-- to normalise parties within a single record we need to group them, obtain the fragment for each party with the most information, and at the same time cope with rubbish data. In the end the only way to cope is to ensure at least an organisation name, city, phone or fax exists (sigh) --> <xsl:for-each select="current-group()"> <xsl:sort select="count(address/child::*) + count(phone)" data-type="number" order="descending"/> <xsl:choose> <xsl:when test="position()=1"> - <xsl:if test="organizationName!='' or address/city or phone"> + <xsl:if test="organizationName[text()!=''] or address/city or phone"> <xsl:element name="location"> <xsl:element name="address"> + <xsl:apply-templates select="phone[text()!='']"/> <xsl:element name="physical"> <xsl:attribute name="type"> <xsl:text>streetAddress</xsl:text> @@ -488,47 +516,26 @@ <xsl:apply-templates select="organizationName"/> <xsl:apply-templates select="address/deliveryPoint"/> <xsl:apply-templates select="address/city"/> - <xsl:apply-templates select="address/administrativeArea"/> - <xsl:apply-templates select="address/postalCode"/> + <xsl:apply-templates select="address/administrativeArea[text()!='']"/> + <xsl:apply-templates select="address/postalCode[text()!='']"/> <xsl:apply-templates select="address/country"/> </xsl:element> </xsl:element> - <xsl:if test="phone or electronicMailAddress or onlineUrl"> - <xsl:if test="phone"> - <xsl:element name="address"> - <xsl:apply-templates select="phone"/> - </xsl:element> - </xsl:if> - <xsl:if test="electronicMailAddress"> - <xsl:element name="address"> - <xsl:apply-templates select="electronicMailAddress"/> - </xsl:element> - </xsl:if> - <xsl:if test="onlineUrl"> - <xsl:element name="address"> - <xsl:apply-templates select="onlineUrl"/> - </xsl:element> - </xsl:if> - </xsl:if> - </xsl:element> + </xsl:element> </xsl:if> - </xsl:when> + </xsl:when> </xsl:choose> </xsl:for-each> - - <xsl:element name="relatedObject"> + + <xsl:element name="relatedObject"> <xsl:element name="key"> <xsl:value-of select="ancestor::eml:eml/dataset/alternateIdentifier[1]"/> </xsl:element> <xsl:for-each select="role"> - <xsl:variable name="code"> - <xsl:value-of select="current-grouping-key()"/> - </xsl:variable> - <xsl:element name="relation"> <xsl:attribute name="type"> - <xsl:value-of select="$code"/> + <xsl:value-of select="."/> </xsl:attribute> </xsl:element> </xsl:for-each> @@ -537,8 +544,24 @@ </xsl:element> </xsl:for-each-group> - <xsl:for-each-group select="//dataset/*[(individualName!='' or positionName!='' or organizationName!='') and (name()='creator' or name()='metadataProvider')]" group-by="name()"> - <xsl:element name="registryObject"> +</xsl:template> + +<xsl:template match="individualName"> + <xsl:choose> + <xsl:when test="givenName"> + <xsl:value-of select="concat(givenName,' ',surName)" /> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="surName"/> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template name="createPartyRegistryObject"> + <xsl:param name="group"/> + <xsl:param name="originatingSource"/> + <xsl:param name="origSource"/> + <xsl:attribute name="group"> <xsl:value-of select="$group"/> </xsl:attribute> @@ -554,7 +577,6 @@ <xsl:value-of select="organizationName"/> </xsl:otherwise> </xsl:choose> - <!--<xsl:value-of select="current-grouping-key()"/> --> </xsl:element> <xsl:element name="originatingSource"> <xsl:choose> @@ -603,7 +625,12 @@ <!--<xsl:value-of select="current-grouping-key()"/>--> </xsl:element> </xsl:element> - + <xsl:call-template name="fillOutAddress"/> + </xsl:element> +</xsl:template> + +<xsl:template name="fillOutAddress"> + <!-- to normalise parties within a single record we group them --> <xsl:for-each select="current-group()"> <xsl:sort select="count(address/child::*) + count(phone)" data-type="number" order="descending"/> @@ -646,118 +673,8 @@ </xsl:when> </xsl:choose> </xsl:for-each> - - <xsl:element name="relatedObject"> - <xsl:element name="key"> - <xsl:value-of select="ancestor::eml:eml/dataset/alternateIdentifier[1]"/> - </xsl:element> - - <xsl:variable name="code"> - <xsl:value-of select="current-grouping-key()"/> - </xsl:variable> - - <xsl:element name="relation"> - <xsl:attribute name="type"> - <xsl:value-of select="$code"/> - </xsl:attribute> - </xsl:element> - </xsl:element> - </xsl:element> - </xsl:element> - </xsl:for-each-group> - - <!-- Create all the associated party objects for organisations --> - <xsl:for-each-group select="//dataset/*[not(individualName) and organizationName!='' and not(role='')]" group-by="organizationName"> - <xsl:element name="registryObject"> - <xsl:attribute name="group"> - <xsl:value-of select="$group"/> - </xsl:attribute> - <xsl:element name="key"> - <xsl:value-of select="current-grouping-key()"/> - </xsl:element> - <xsl:element name="originatingSource"> - <xsl:choose> - <xsl:when test="not($originatingSource)"> - <xsl:value-of select="$origSource"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="$originatingSource"/> - </xsl:otherwise> - </xsl:choose> - </xsl:element> - <xsl:element name="party"> - <xsl:attribute name="type"> - <xsl:text>person</xsl:text> - </xsl:attribute> - <xsl:element name="name"> - <xsl:attribute name="type"> - <xsl:text>primary</xsl:text> - </xsl:attribute> - <xsl:element name="namePart"> - <xsl:attribute name="type"> - <xsl:text>full</xsl:text> - </xsl:attribute> - <xsl:value-of select="current-grouping-key()"/> - </xsl:element> - </xsl:element> - - <!-- to normalise parties within a single record we need to group them, obtain the fragment for each party with the most information, and at the same time cope with rubbish data. In the end the only way to cope is to ensure at least an organisation name, city, phone or fax exists (sigh) --> - <xsl:for-each select="current-group()"> - <xsl:sort select="count(address/child::*) + count(phone)" data-type="number" order="descending"/> - <xsl:choose> - <xsl:when test="position()=1"> - <xsl:if test="organizationName[text()!=''] or address/city or phone"> - <xsl:element name="location"> - <xsl:element name="address"> - <xsl:apply-templates select="phone[text()!='']"/> - <xsl:element name="physical"> - <xsl:attribute name="type"> - <xsl:text>streetAddress</xsl:text> - </xsl:attribute> - <xsl:apply-templates select="organizationName"/> - <xsl:apply-templates select="address/deliveryPoint"/> - <xsl:apply-templates select="address/city"/> - <xsl:apply-templates select="address/administrativeArea[text()!='']"/> - <xsl:apply-templates select="address/postalCode[text()!='']"/> - <xsl:apply-templates select="address/country"/> - </xsl:element> - </xsl:element> - </xsl:element> - </xsl:if> - </xsl:when> - </xsl:choose> - </xsl:for-each> - - <xsl:element name="relatedObject"> - <xsl:element name="key"> - <xsl:value-of select="ancestor::eml:eml/dataset/alternateIdentifier[1]"/> - </xsl:element> - - <xsl:for-each select="role"> - <xsl:element name="relation"> - <xsl:attribute name="type"> - <xsl:value-of select="."/> - </xsl:attribute> - </xsl:element> - </xsl:for-each> - </xsl:element> - </xsl:element> - </xsl:element> - </xsl:for-each-group> - </xsl:template> -<xsl:template match="individualName"> - <xsl:choose> - <xsl:when test="givenName"> - <xsl:value-of select="concat(givenName,' ',surName)" /> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="surName"/> - </xsl:otherwise> - </xsl:choose> -</xsl:template> - <xsl:template match="node()"/> </xsl:stylesheet> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |