Ignore:
Timestamp:
10/17/15 07:12:51 (9 years ago)
Author:
Menzo Windhouwer
Message:

M toolkit/src/main/resources/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl

  • try heuristics to see an XML element containing a @ref is a CMD element or component, otherwise resolve the path in to the XML element in the CMD profile specification

A toolkit/src/test/resources/toolkit/TEI/profiles/clarin.eu:cr1:p_1380106710826.xml

  • added for the test

M toolkit/src/main/resources/toolkit/xsd/cmd-envelop.xsd

  • styling
File:
1 edited

Legend:

Unmodified
Added
Removed
  • metadata/trunk/toolkit/src/main/resources/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl

    r6262 r6683  
    1717    <xsl:variable name="cr-profiles" select="concat($cr-uri,'/profiles')"/>
    1818    <xsl:variable name="cr-extension-xsd" select="'-1_2.xsd'"/>
    19 
     19    <xsl:variable name="cr-extension-xml" select="'.xml'"/>
     20   
    2021    <!-- identity copy -->
    2122    <xsl:template match="@*|node()">
     
    5758    <xsl:variable name="cmd-profile-uri" select="concat($cmd-profiles,'/',$profile)"/>
    5859    <xsl:variable name="cr-profile-xsd" select="concat($cr-profiles,'/',$profile,$cr-extension-xsd)"/>
     60    <xsl:variable name="cr-profile-xml" select="concat($cr-profiles,'/',$profile,$cr-extension-xml)"/>
    5961   
    6062    <!-- CMD version becomes 1.2 -->
     
    146148   
    147149    <!-- move CMD attributes to the CMD namespace -->
    148     <!-- TODO: @ref is allowed on elements, how to know if this is a element or a component with no children? -->
    149     <!--<xsl:template match="cmd0:Components//*[exists(*)]/@ref">-->
    150150    <xsl:template match="cmd0:Components//@ref">
    151         <xsl:attribute name="cmd:ref" select="."/>
     151        <xsl:choose>
     152            <xsl:when test="exists(parent::*/text()[normalize-space()!=''])">
     153                <!-- this is an element keep the @ref -->
     154                <xsl:copy/>
     155            </xsl:when>
     156            <xsl:when test="exists(../parent::*/node()) or exists(../parent::*/@ComponentId)">
     157                <!-- the parent is a component add the namespace to @ref -->
     158                <xsl:attribute name="cmd:ref" select="."/>
     159            </xsl:when>
     160            <xsl:otherwise>
     161                <!-- don't know if the parent is a component without children, or an element without value
     162                     have a look at the profile -->
     163                <xsl:variable name="prof" select="doc(resolve-uri($cr-profile-xml,base-uri()))"/>
     164                <xsl:variable name="path" select="ancestor::*[. >> /cmd0:CMD/cmd0:Components]"/>
     165                <xsl:variable name="attr" select="$prof//Attribute[Name='ref'][string-join(ancestor::*[local-name()=('CMD_Component','CMD_Element')]/@name,'/')=string-join($path/local-name(),'/')]"/>
     166                <xsl:choose>
     167                    <xsl:when test="exists($attr/parent::AttributeList/parent::CMD_Component)">
     168                        <!-- the parent is a component add the namespace to @ref -->
     169                        <xsl:message>!MENZO: the parent is a component add the namespace to @ref</xsl:message>
     170                        <xsl:attribute name="cmd:ref" select="."/>
     171                    </xsl:when>
     172                    <xsl:otherwise>
     173                        <!-- this is an element keep the @ref -->
     174                        <xsl:message>!MENZO: the parent is an element keep the @ref</xsl:message>
     175                        <xsl:copy/>
     176                    </xsl:otherwise>
     177                </xsl:choose>
     178            </xsl:otherwise>
     179        </xsl:choose>
    152180    </xsl:template>
    153181   
Note: See TracChangeset for help on using the changeset viewer.