Changeset 1494


Ignore:
Timestamp:
08/25/11 13:35:55 (13 years ago)
Author:
larlam
Message:

imdi2clarin.xsl: Added a parameter to provide URL context. If defined, it will be used to resolve relative path links to absolute URLs and also to modify the MdSelfLink? element. (Mirrors MPI svn changeset 25994.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • metadata/trunk/toolkit/xslt/imdi2clarin.xsl

    r1302 r1494  
    11<?xml version="1.0" encoding="UTF-8"?>
    2 <xsl:stylesheet xmlns="http://www.clarin.eu/cmd/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    3     xpath-default-namespace="http://www.mpi.nl/IMDI/Schema/IMDI">
     2<xsl:stylesheet xmlns="http://www.clarin.eu/cmd/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     3    version="2.0" xpath-default-namespace="http://www.mpi.nl/IMDI/Schema/IMDI">
    44    <!-- this is a version of imdi2clarin.xsl that batch processes a whole directory structure of imdi files, call it from the command line like this:
    55        java -jar saxon8.jar -it main batch-imdi2clarin.xsl
     
    1010    <!-- A collection name can be specified for each record. This
    1111    information is extrinsic to the IMDI file, so it is given as an
    12     external parameter. -->
     12    external parameter. Omit this if you are unsure. -->
    1313    <xsl:param name="collection"/>
    1414
     15    <!-- If this optional parameter is defined, the behaviour of this
     16    stylesheet changes in the following ways: If no archive handle is
     17    available for MdSelfLink, the base URI is inserted there
     18    instead. All links (ResourceProxy elements) that contain relative
     19    paths are resolved into absolute URIs in the context of the base
     20    URI. Omit this if you are unsure. -->
     21    <xsl:param name="uri-base"/>
     22
    1523    <xsl:template name="metatranscriptDelegate">
    16         <xsl:param name="profile"></xsl:param>
     24        <xsl:param name="profile"/>
    1725        <Header>
    1826            <MdCreator>imdi2clarin.xsl</MdCreator>
    1927            <MdCreationDate><xsl:value-of select="format-date(current-date(), '[Y]-[M01]-[D01]')"/></MdCreationDate>
    20             <MdSelfLink>test-<xsl:value-of select="@ArchiveHandle"/></MdSelfLink>
    21             <MdProfile><xsl:value-of select="$profile"/></MdProfile>
     28            <MdSelfLink>
     29                <xsl:choose>
     30                    <xsl:when test="not($uri-base='') and normalize-space(@ArchiveHandle)=''"><xsl:value-of select="$uri-base"/></xsl:when>
     31                    <xsl:otherwise>
     32                        test-<xsl:value-of select="@ArchiveHandle"/>
     33                    </xsl:otherwise>
     34                </xsl:choose>
     35            </MdSelfLink>
     36            <MdProfile>
     37                <xsl:value-of select="$profile"/>
     38            </MdProfile>
    2239            <xsl:if test="$collection">
    2340                <MdCollectionDisplayName><xsl:value-of select="$collection"/></MdCollectionDisplayName>
     
    4158        <xsl:choose>
    4259            <xsl:when test=".[@Type='SESSION'] or .[@Type='SESSION.Profile']">
    43                 <CMD CMDVersion="1.1"
    44                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     60                <CMD CMDVersion="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4561                    xsi:schemaLocation="http://www.clarin.eu/cmd/ http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1271859438204/xsd">
    4662                    <xsl:call-template name="metatranscriptDelegate">
     
    5066            </xsl:when>
    5167            <xsl:when test=".[@Type='CORPUS'] or .[@Type='CORPUS.Profile']">
    52                 <CMD CMDVersion="1.1"
    53                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     68                <CMD CMDVersion="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    5469                    xsi:schemaLocation="http://www.clarin.eu/cmd/ http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1274880881885/xsd">
    5570                    <xsl:call-template name="metatranscriptDelegate">
     
    100115            <ResourceProxy id="{generate-id()}">
    101116                <ResourceType>Metadata</ResourceType>
    102                 <ResourceRef><xsl:value-of select="."/>.cmdi</ResourceRef>
     117                <ResourceRef>
     118                    <xsl:choose>
     119                        <xsl:when test="$uri-base='' or starts-with(., 'hdl:')"><xsl:value-of select="."/>.cmdi</xsl:when>
     120                        <xsl:otherwise><xsl:value-of select="concat(resolve-uri(., $uri-base), '.cmdi')"/></xsl:otherwise>
     121                    </xsl:choose>
     122                </ResourceRef>
    103123            </ResourceProxy>
    104124        </xsl:for-each>
     
    115135                    </xsl:if>Resource</ResourceType>
    116136                <ResourceRef>
    117                     <xsl:value-of select="ResourceLink/@ArchiveHandle"/>
     137                    <xsl:choose>
     138                        <xsl:when test="not(normalize-space(ResourceLink/@ArchiveHandle)='')"><xsl:value-of select="ResourceLink/@ArchiveHandle"/></xsl:when>
     139                        <xsl:when test="not($uri-base='')"><xsl:value-of select="resolve-uri(ResourceLink/., $uri-base)"/></xsl:when>
     140                    </xsl:choose>
    118141                </ResourceRef>
    119142            </ResourceProxy>
     
    128151                    </xsl:if>Resource</ResourceType>
    129152                <ResourceRef>
    130                     <xsl:value-of select="ResourceLink/@ArchiveHandle"/>
     153                    <xsl:choose>
     154                        <xsl:when test="not(normalize-space(ResourceLink/@ArchiveHandle)='')"><xsl:value-of select="ResourceLink/@ArchiveHandle"/></xsl:when>
     155                        <xsl:when test="not($uri-base='')"><xsl:value-of select="resolve-uri(ResourceLink/., $uri-base)"/></xsl:when>
     156                    </xsl:choose>
    131157                </ResourceRef>
    132158            </ResourceProxy>
     
    730756        </References>
    731757    </xsl:template>
    732    
     758
    733759    <xsl:template name="main">
    734760        <xsl:for-each
     
    739765        </xsl:for-each>
    740766    </xsl:template>
    741    
     767
    742768</xsl:stylesheet>
Note: See TracChangeset for help on using the changeset viewer.