Skip to content

Commit

Permalink
Merge pull request #2 from clarin-eric/cmdi-toolkit-1.2.4
Browse files Browse the repository at this point in the history
Update static files for CMDI toolkit 1.2.4
  • Loading branch information
andmor- authored Jan 7, 2021
2 parents 11f362a + 867dc10 commit 147d929
Show file tree
Hide file tree
Showing 19 changed files with 4,356 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMDI/1.2
135 changes: 135 additions & 0 deletions CMDI/1.2.3/downgrade/cmd-component-1_2-to-1_1.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:cue="http://www.clarin.eu/cmdi/cues/1"
exclude-result-prefixes="xs"
version="2.0">

<xsl:param name="cmd-component-xsd" select="'https://infra.clarin.eu/CMDI/1.1/general-component-schema.xsd'"/>

<xsl:param name="escape" select="'ccmmddii_'"/>

<!-- identity copy -->
<xsl:template match="@*">
<xsl:copy/>
</xsl:template>

<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<!-- refer to cmd-component.xsd -->
<xsl:template match="@xsi:noNamespaceSchemaLocation" priority="1">
<xsl:attribute name="xsi:noNamespaceSchemaLocation" select="$cmd-component-xsd"/>
</xsl:template>

<!-- add CMD_ prefix -->
<xsl:template match="ComponentSpec" priority="1">
<CMD_ComponentSpec>
<xsl:apply-templates select="@*|node()"/>
</CMD_ComponentSpec>
</xsl:template>

<xsl:template match="Component" priority="1">
<CMD_Component>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node() except Documentation"/>
</CMD_Component>
</xsl:template>

<xsl:template match="Element" priority="1">
<CMD_Element>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="Documentation"/>
<xsl:apply-templates select="node() except Documentation"/>
</CMD_Element>
</xsl:template>

<!-- remove CDM version attributes -->
<xsl:template match="ComponentSpec/@CMDVersion"/>
<xsl:template match="ComponentSpec/@CMDOriginalVersion"/>

<!-- remove Status and friends -->
<xsl:template match="Header/Status" priority="1"/>
<xsl:template match="Header/StatusComment" priority="1"/>
<xsl:template match="Header/Successor" priority="1"/>
<xsl:template match="Header/DerivedFrom" priority="1"/>

<!-- turn @ComponentRef into @ComponentId -->
<xsl:template match="@ComponentRef">
<xsl:attribute name="ComponentId" select="."/>
</xsl:template>

<!-- turn <Documentation/> into @Documentation -->
<xsl:template match="Documentation" priority="1">
<xsl:choose>
<xsl:when test="exists(../Documentation[@xml:lang=('en','eng')])">
<xsl:if test="@xml:lang=('en','eng') and empty(preceding-sibling::Documentation[@xml:lang=('en','eng')])">
<!-- first english documentation -->
<xsl:attribute name="Documentation" select="."/>
</xsl:if>
</xsl:when>
<xsl:when test="exists(../Documentation[normalize-space(@xml:lang)=''])">
<xsl:if test="normalize-space(@xml:lang)='' and empty(preceding-sibling::Documentation[normalize-space(@xml:lang)=''])">
<!-- first general documentation -->
<xsl:attribute name="Documentation" select="."/>
</xsl:if>
</xsl:when>
<xsl:when test="empty(preceding-sibling::Documentation)">
<!-- first documentation -->
<xsl:attribute name="Documentation" select="."/>
</xsl:when>
</xsl:choose>
</xsl:template>

<!-- remove Vocabulary level, incl. attributes -->
<xsl:template match="Vocabulary" priority="1">
<xsl:apply-templates select="node()"/>
</xsl:template>

<!-- turn Attribute child elements into attributes -->
<xsl:template match="Attribute" priority="1">
<xsl:variable name="name">
<xsl:choose>
<xsl:when test="exists(parent::AttributeList/parent::Component) and Name=('ref','ComponentId')">
<xsl:message>WRN: <xsl:value-of select="/ComponentSpec/Header/ID"/>: user-defined ref and ComponentId attributes for a Component are not supported by CMDI 1.1! Adding the <xsl:value-of select="$escape"/> prefix</xsl:message>
<xsl:value-of select="concat($escape,@name)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<Attribute>
<Name>
<xsl:value-of select="$name"/>
</Name>
<xsl:if test="normalize-space(@ConceptLink)!=''">
<ConceptLink>
<xsl:value-of select="@ConceptLink"/>
</ConceptLink>
</xsl:if>
<xsl:if test="normalize-space(@ValueScheme)!=''">
<Type>
<xsl:value-of select="@ValueScheme"/>
</Type>
</xsl:if>
<!-- @Required is skipped -->
<xsl:apply-templates select="node() except Documentation"/>
</Attribute>
</xsl:template>

<!-- remove cue namespace for DisplayPriority -->
<xsl:template match="@cue:DisplayPriority" priority="2">
<xsl:attribute name="DisplayPriority">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>

<!-- remove other cue attributes -->
<xsl:template match="@cue:*" priority="1"/>

</xsl:stylesheet>
23 changes: 23 additions & 0 deletions CMDI/1.2.3/sch/cmd-component-best-practices.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<sch:ns uri="http://www.w3.org/2001/XMLSchema-instance" prefix="xsi"/>

<sch:pattern id="c_nest">
<sch:title>Check nesting</sch:title>
<sch:rule context="Component[exists(Component|Element)]" role="warning">
<sch:assert test="empty((Component|Element)[@name=current()/@name])">
[CMDI Best Practices] A nested component or element has the same name ('<sch:value-of select="@name"/>') as this component! Please, consider to rename one of them.
</sch:assert>
</sch:rule>
</sch:pattern>

<sch:pattern id="a_nest">
<sch:title>Check attribute nesting</sch:title>
<sch:rule context="Attribute" role="warning">
<sch:assert test="empty((ancestor::Component|ancestor::Element)[1][@name=current()/@name])">
[CMDI Best Practices] An attribute has the same name ('<sch:value-of select="@name"/>') as its element or component! Please, consider to rename one of them.
</sch:assert>
</sch:rule>
</sch:pattern>

</sch:schema>
95 changes: 95 additions & 0 deletions CMDI/1.2.3/sch/cmd-record-best-practices.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<ns uri="http://www.clarin.eu/cmd/1" prefix="cmd"/>
<ns uri="http://www.w3.org/2001/XMLSchema-instance" prefix="xsi"/>

<pattern>
<title>Test cmd:MdProfile</title>
<rule role="warning" context="cmd:Header">
<assert test="string-length(cmd:MdProfile/text()) &gt; 0">
[CMDI Best Practices] A CMDI instance should contain a non-empty &lt;cmd:MdProfile&gt; element in &lt;cmd:Header&gt;.
</assert>
</rule>
</pattern>

<pattern>
<title>Test cmd:MdSelfLink</title>
<rule role="warning" context="cmd:Header">
<assert test="string-length(cmd:MdSelfLink/text()) &gt; 0">
[CMDI Best Practices] A CMDI instance should contain a non-empty &lt;cmd:MdSelfLink&gt; element in &lt;cmd:Header&gt;.
</assert>
</rule>
</pattern>

<!-- Does the schema reside in the Component Registry? -->
<pattern>
<title>Test xsi:schemaLocation</title>
<rule role="warning" context="/cmd:CMD">
<assert test="matches(@xsi:schemaLocation,'http(s)?://catalog.clarin.eu/ds/ComponentRegistry/rest/')">
[CMDI Best Practice] /cmd:CMD/@xsi:schemaLocation doesn't refer to a schema from the Component Registry! [Actual value was [<value-of select="@xsi:schemaLocation"/>]
</assert>
</rule>
</pattern>

<!-- Is there at least one ResourceProxy? -->
<pattern>
<title>Test for ResourceProxies</title>
<rule role="warning" context="/cmd:CMD/cmd:Resources/cmd:ResourceProxyList">
<assert test="count(cmd:ResourceProxy) ge 1">
[CMDI Best Practices] There are no ResourceProxies! Does the metadata not describe any (digital) resources?
</assert>
</rule>
</pattern>

<!-- Can we determine the profile used? -->
<pattern>
<title>Test for known profile</title>
<rule role="warning" context="/cmd:CMD">
<assert test="matches(@xsi:schemaLocation,'clarin.eu:cr[0-9]+:p_[0-9]+') or matches(cmd:Header/cmd:MdProfile,'clarin.eu:cr[0-9]+:p_[0-9]+')">
[CMDI Best Practice] the CMD profile of this record can't be found in the /cmd:CMD/@xsi:schemaLocation or /cmd:CMD/cmd:Header/cmd:MdProfile. The profile should be known for the record to be processed properly in the CLARIN joint metadata domain!
</assert>
</rule>
</pattern>

<!-- Do the MdProfile and the @xsi:schemaLocation refer to the same profile? -->
<pattern>
<title>Test if MdProfile and @xsi:schemaLocation are in sync</title>
<rule role="warning" context="/cmd:CMD[matches(@xsi:schemaLocation,'clarin.eu:cr[0-9]+:p_[0-9]+') and matches(cmd:Header/cmd:MdProfile,'clarin.eu:cr[0-9]+:p_[0-9]+')]">
<assert test="replace(@xsi:schemaLocation,'(clarin.eu:cr[0-9]+:p_[0-9]+)','$1') = replace(cmd:Header/cmd:MdProfile,'(clarin.eu:cr[0-9]+:p_[0-9]+)','$1')">
[CMDI Best Practice] The CMD profile referenced in the @xsi:schemaLocation is different than the one specified in /cmd:CMD/cmd:Header/cmd:MdProfile. They should be the same!
</assert>
</rule>
</pattern>

<!-- Is the CMD namespace bound to a schema? -->
<pattern>
<title>Test for CMD namespace schema binding</title>
<rule role="warning" context="/cmd:CMD">
<assert test="matches(@xsi:schemaLocation,'http://www.clarin.eu/cmd/1 ')">
[CMDI Best Practice] is the CMD 1.2 namespace bound to the envelop schema?
</assert>
</rule>
</pattern>

<!-- Is the CMD profile namespace bound to a schema? -->
<pattern>
<title>Test for CMD profile namespace schema binding</title>
<rule role="warning" context="/cmd:CMD">
<assert test="matches(@xsi:schemaLocation,'http://www.clarin.eu/cmd/1/profiles/')">
[CMDI Best Practice] is the CMD 1.2 profile namespace bound to the profile schema?
</assert>
</rule>
</pattern>

<!-- if the following rules trigger XSD validation will (have) fail(ed)! -->

<!-- Is the cmd:CMD root there? -->
<pattern>
<title>Test for cmd:CMD root</title>
<rule role="warning" context="/">
<assert test="exists(cmd:CMD)">
[CMDI violation] is this really a CMD record? Is the namespace properly declared, e.g., including ending slash?
</assert>
</rule>
</pattern>

</schema>
Loading

0 comments on commit 147d929

Please sign in to comment.