Changeset 5233
- Timestamp:
- 05/19/14 15:24:48 (10 years ago)
- Location:
- CMDI-Interoperability/CMD2RDF/trunk/xsl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
CMDI-Interoperability/CMD2RDF/trunk/xsl/CMD2RDFcache.xsl
r5215 r5233 15 15 <xsl:include href="../../../../SMC/src/xsl/smc_commons.xsl"/> 16 16 17 <!-- location of the registry -->18 <xsl:param name="registry" select="'http://catalog.clarin.eu/ds/ComponentRegistry'"/>19 20 <!-- separator when traversing the component/element hierarchy -->21 <xsl:variable name="STEP" select="'.'"/>22 23 <!-- XSD data types allowed in RDF (see http://www.w3.org/TR/2004/REC-rdf-mt-20040210/#DTYPEINTERP) -->24 <xsl:variable name="RDF-XSD-DataTypes" select="(25 'string',26 'boolean',27 'decimal',28 'float',29 'double',30 'dateTime',31 'time',32 'date',33 'gYearMonth',34 'gYear',35 'gMonthDay',36 'gDay',37 'gMonth',38 'hexBinary',39 'base64Binary',40 'anyURI',41 'normalizedString',42 'token',43 'language',44 'NMTOKEN',45 'Name',46 'NCName',47 'integer',48 'nonPositiveInteger',49 'negativeInteger',50 'long',51 'int',52 'short',53 'byte',54 'nonNegativeInteger',55 'unsignedLong',56 'unsignedInt',57 'unsignedShort',58 'unsignedByte',59 'positiveInteger'60 )"/>61 62 <!-- append a step to a path -->63 <xsl:function name="cmd:path">64 <xsl:param name="context"/>65 <xsl:param name="name"/>66 <xsl:sequence select="concat($context,if (normalize-space($context)='') then ('') else ($STEP),$name)"/>67 </xsl:function>68 69 <!-- turn a CMD XSD datatype into a XSD datatype allowed by RDF -->70 <xsl:function name="cmd:datatype">71 <xsl:param name="datatype"/>72 <xsl:sequence select="if ($datatype=$RDF-XSD-DataTypes) then ($datatype) else ('string')"/>73 </xsl:function>74 75 <!-- the registry URL for a profile76 $id[1] = ignore error in MDrecords (two MdProfile elements )77 http://hdl.handle.net/1839/00-56657635-3608-495D-9F4A-1F3F9EA58108-->78 <xsl:function name="cmd:ppath">79 <xsl:param name="id"/>80 <xsl:param name="ext"/>81 <xsl:sequence select="concat($registry,'/rest/registry/profiles/',$id[1],'/',$ext)"/>82 </xsl:function>83 84 <!-- the registry URL for a component -->85 86 <xsl:function name="cmd:cpath">87 <xsl:param name="id"/>88 <xsl:param name="ext"/>89 <xsl:sequence select="concat($registry,'/rest/registry/components/',$id[1],'/',$ext)"/>90 </xsl:function>91 92 17 <!-- load a profile from the registry --> 93 18 <xsl:function name="cmd:profile"> 94 19 <xsl:param name="id"/> 95 20 <!-- <xsl:sequence select="doc(cmd:ppath($id,'xml'))"/>--> 21 <xsl:message>getting from cache via function</xsl:message> 96 22 <xsl:call-template name="getData"> 97 23 <xsl:with-param name="id" select="$id" /> … … 100 26 </xsl:function> 101 27 102 <xsl:template name="cmd:profile"> 103 <xsl:param name="id"/> 104 <!-- <xsl:sequence select="doc(cmd:ppath($id,'xml'))"/>--> 105 <xsl:call-template name="getData"> 106 <xsl:with-param name="id" select="$id" /> 107 <xsl:with-param name="key" select="'profiles'" /> 108 </xsl:call-template> 109 </xsl:template> 110 28 111 29 </xsl:stylesheet> -
CMDI-Interoperability/CMD2RDF/trunk/xsl/CMDRecord2RDFcache.xsl
r5215 r5233 20 20 > 21 21 22 <xsl:import href="CMDRecord2RDF.xsl"/> 23 22 24 <xsl:output method="xml" encoding="UTF-8"/> 23 25 … … 26 28 <xsl:include href="CMD2RDFcache.xsl"/> 27 29 28 <xsl:template match="text()"/>29 30 30 <!-- let's create some RDF -->31 <xsl:template match="/cmd:CMD">32 <rdf:RDF xml:base="{replace($base,'([./])(xml|cmdi)$','$1rdf')}">33 <!-- The CMDI is seen as OA Annotation of a (set of) resource(s) -->34 <oa:Annotation rdf:about="{$base}">35 <xsl:apply-templates select="cmd:Resources" mode="resources"/>36 <oa:hasBody>37 <xsl:apply-templates select="cmd:Components">38 <xsl:with-param name="context" tunnel="yes" select="''"/>39 </xsl:apply-templates>40 </oa:hasBody>41 <oa:motivatedBy rdf:resource="&oa;describing"/>42 </oa:Annotation>43 <!-- The CMDI is an ORE ResourceMap to other metadata descriptions -->44 <xsl:if test="exists(cmd:Resources/ResourceProxyList/ResourceProxy[ResourceType='Metadata'])">45 <ore:ResourceMap rdf:about="{$base}">46 <ore:describes>47 <ore:Aggregation>48 <xsl:apply-templates select="cmd:Resources" mode="metadata"/>49 </ore:Aggregation>50 </ore:describes>51 </ore:ResourceMap>52 </xsl:if>53 <xsl:apply-templates select="cmd:Header"/>54 <xsl:apply-templates select="cmd:Resources" mode="other"/>55 </rdf:RDF>56 </xsl:template>57 58 <xsl:template match="cmd:MdCreator">59 <rdf:Description rdf:about="{concat('#',generate-id(/cmd:CMD/cmd:Components/*))}">60 <dc:creator>61 <xsl:value-of select="."/>62 </dc:creator>63 </rdf:Description>64 </xsl:template>65 66 <xsl:template match="cmd:MdCreationDate">67 <rdf:Description rdf:about="{concat('#',generate-id(/cmd:CMD/cmd:Components/*))}">68 <dc:created>69 <xsl:value-of select="."/>70 </dc:created>71 </rdf:Description>72 </xsl:template>73 74 <xsl:template match="cmd:MdSelfLink">75 <rdf:Description rdf:about="{concat('#',generate-id(/cmd:CMD/cmd:Components/*))}">76 <dc:identifier>77 <xsl:value-of select="."/>78 </dc:identifier>79 </rdf:Description>80 </xsl:template>81 82 <xsl:template match="cmd:MdProfile">83 <!-- TODO? -->84 </xsl:template>85 86 <xsl:template match="cmd:MdCollectionDisplayName">87 <!-- TODO -->88 </xsl:template>89 90 <xsl:template match="text()" mode="resources"/>91 <xsl:template match="cmd:ResourceProxy[cmd:ResourceType!='Resource']" mode="resources"/>92 <xsl:template match="cmd:ResourceProxy[cmd:ResourceType='Resource']" mode="resources">93 <oa:hasTarget>94 <cmdm:Resource rdf:about="{cmd:ResourceRef}">95 <xsl:if test="normalize-space(cmd:ResourceType/@mimetype)!=''">96 <cmdm:hasMimeType>97 <xsl:value-of select="cmd:ResourceType/@mimetype"/>98 </cmdm:hasMimeType>99 </xsl:if>100 </cmdm:Resource>101 </oa:hasTarget>102 </xsl:template>103 104 <xsl:template match="text()" mode="metadata"/>105 <xsl:template match="cmd:ResourceProxy[cmd:ResourceType!='Metadata']" mode="metadata"/>106 <xsl:template match="cmd:ResourceProxy[cmd:ResourceType='Metadata']" mode="metadata">107 <ore:aggregates rdf:resource="{cmd:ResourceRef}"/>108 <!--109 <cmdm:hasMimeType rdf:about="{ResourceRef}">110 <xsl:value-of select="ResourceType/@mimetype"/>111 </cmdm:hasMimeType>112 -->113 </xsl:template>114 115 <xsl:template match="text()" mode="other"/>116 <xsl:template match="cmd:ResourceProxy[cmd:ResourceType=('Resource','Metadata')]" mode="other"/>117 <xsl:template match="cmd:ResourceProxy[not(cmd:ResourceType=('Resource','Metadata'))]" mode="other">118 <xsl:element name="cmdm:has{cmd:ResourceType}">119 <xsl:attribute name="rdf:resource" select="cmd:ResourceRef"/>120 </xsl:element>121 <!--122 <cmdm:hasMimeType rdf:about="{ResourceRef}">123 <xsl:value-of select="ResourceType/@mimetype"/>124 </cmdm:hasMimeType>125 -->126 </xsl:template>127 128 <!-- the CMD body -->129 <xsl:template match="/cmd:CMD/cmd:Components">130 <!-- get the profile id -->131 <xsl:variable name="id" select="/cmd:CMD/cmd:Header/cmd:MdProfile"/>132 <!-- load the profile -->133 <!-- select="cmd:profile($id)"-->134 <xsl:variable name="profile" >135 <xsl:call-template name="cmd:profile">136 <xsl:with-param name="id" select="$id[1]"></xsl:with-param>137 </xsl:call-template>138 </xsl:variable>139 <!-- the base URL (the namespace in RDF/XML) of the RDF resources will change during traversal to the URL of the active profile/component -->140 <xsl:variable name="ns" select="concat(cmd:ppath($id[1],'rdf'),'#')"/>141 <!-- we traverse the profile/component scheme and find the matching instances -->142 <xsl:apply-templates select="$profile/CMD_ComponentSpec/CMD_Component">143 <xsl:with-param name="context" tunnel="yes" select="''"/>144 <xsl:with-param name="ns" tunnel="yes" select="$ns"/>145 <xsl:with-param name="instance" tunnel="yes" select="."/>146 </xsl:apply-templates>147 </xsl:template>148 149 <!-- a CMD component -->150 <xsl:template match="CMD_Component">151 <xsl:param name="context" tunnel="yes"/>152 <xsl:param name="ns" tunnel="yes"/>153 <xsl:param name="instance" tunnel="yes"/>154 <!-- if the component has its own id its something that can be shared by multiple profiles/components and has its own base RDF (namespace) -->155 <xsl:variable name="local-ns">156 <xsl:choose>157 <xsl:when test="exists(@ComponentId)">158 <xsl:sequence select="concat(cmd:cpath(@ComponentId,'rdf'),'#')"/>159 </xsl:when>160 <xsl:otherwise>161 <xsl:sequence select="$ns"/>162 </xsl:otherwise>163 </xsl:choose>164 </xsl:variable>165 <!-- if the component has its own id its something that can be shared by multiple profiles/components a new context is started -->166 <xsl:variable name="local-context">167 <xsl:choose>168 <xsl:when test="exists(@ComponentId)">169 <xsl:sequence select="''"/>170 </xsl:when>171 <xsl:otherwise>172 <xsl:sequence select="$context"/>173 </xsl:otherwise>174 </xsl:choose>175 </xsl:variable>176 <xsl:variable name="profile" select="."/>177 <xsl:variable name="name" select="@name"/>178 <!-- extend the context with this component -->179 <xsl:variable name="id" select="cmd:path($local-context,$name)"/>180 <!-- find the matching instances -->181 <xsl:for-each select="$instance/*[local-name()=$name]">182 <!-- create a class -->183 <xsl:variable name="class">184 <xsl:element name="{$id}" namespace="{$local-ns}">185 <xsl:attribute name="rdf:about" select="concat('#',generate-id(.))"/>186 <xsl:for-each select="tokenize(@ref,'\s+')">187 <xsl:variable name="res" select="."/>188 <cmdm:describesResource rdf:resource="{$instance/ancestor::cmd:CMD/cmd:Resources/cmd:ResourceProxyList/cmd:ResourceProxy[@id=$res]/cmd:ResourceRef}"/>189 </xsl:for-each>190 <!-- switch back from the instance to the profile -->191 <xsl:apply-templates select="$profile/*">192 <xsl:with-param name="context" tunnel="yes" select="$id"/>193 <xsl:with-param name="ns" tunnel="yes" select="$local-ns"/>194 <xsl:with-param name="instance" tunnel="yes" select="."/>195 </xsl:apply-templates>196 </xsl:element>197 </xsl:variable>198 <!-- is this the root or not -->199 <xsl:choose>200 <xsl:when test="exists(parent::cmd:Components)">201 <xsl:copy-of select="$class"/>202 </xsl:when>203 <xsl:otherwise>204 <!-- use the generic RELcat related relationship for the nesting of components -->205 <cmdm:contains>206 <xsl:copy-of select="$class"/>207 </cmdm:contains>208 </xsl:otherwise>209 </xsl:choose>210 </xsl:for-each>211 </xsl:template>212 213 <!-- a CMD element -->214 <xsl:template match="CMD_Element">215 <xsl:param name="context" tunnel="yes"/>216 <xsl:param name="ns" tunnel="yes"/>217 <xsl:param name="instance" tunnel="yes"/>218 <xsl:variable name="profile" select="."/>219 <xsl:variable name="name" select="@name"/>220 <!-- extend the context with this element -->221 <xsl:variable name="id" select="cmd:path($context,$name)"/>222 <xsl:variable name="has" select="cmd:path($context,concat('has',@name))"/>223 <!-- find the matching instances -->224 <xsl:for-each select="$instance/*[local-name()=$name]">225 <!-- use the generic RELcat related relationship for the nesting of the element in its component -->226 <cmdm:contains>227 <!-- a CMD element is a RDF class -->228 <xsl:element name="{$id}" namespace="{$ns}">229 <xsl:attribute name="rdf:about" select="concat('#',generate-id(.))"/>230 <!-- the value is assigned to a propery of the CMD element RDF class -->231 <xsl:element name="{$has}ElementValue" namespace="{$ns}">232 <!-- map the CMD XSD datatype to a datatype supported by RDF -->233 <xsl:attribute name="rdf:datatype" select="concat('&xsd;',cmd:datatype($profile/@ValueScheme))"/>234 <!-- copy @xml:lang -->235 <xsl:copy-of select="@xml:lang"/>236 <!-- copy the literal -->237 <xsl:value-of select="."/>238 </xsl:element>239 <!-- if there is enum we also have an entity property -->240 <xsl:if test="exists($profile/ValueScheme/enumeration)">241 <xsl:element name="{$id}ElementEntity" namespace="{$ns}">242 <xsl:attribute name="rdf:resource" select="concat($ns,$id,'ValueScheme',$STEP,replace(.,'\s',''))"/>243 </xsl:element>244 </xsl:if>245 <!-- switch back from the instance to the profile to handle the attributes -->246 <xsl:apply-templates select="$profile/AttributeList/Attribute">247 <xsl:with-param name="context" tunnel="yes" select="$id"/>248 <xsl:with-param name="ns" tunnel="yes" select="$ns"/>249 <xsl:with-param name="instance" tunnel="yes" select="."/>250 </xsl:apply-templates>251 </xsl:element>252 </cmdm:contains>253 </xsl:for-each>254 </xsl:template>255 256 <!-- a CMD attribute -->257 <xsl:template match="Attribute">258 <xsl:param name="context" tunnel="yes"/>259 <xsl:param name="ns" tunnel="yes"/>260 <xsl:param name="instance" tunnel="yes"/>261 <xsl:variable name="profile" select="."/>262 <xsl:variable name="name" select="Name"/>263 <!-- extend the context with this attribute -->264 <xsl:variable name="id" select="concat(cmd:path($context,$name),'Attribute')"/>265 <xsl:variable name="has" select="concat(cmd:path($context,concat('has',$name)),'Attribute')"/>266 <!-- find the matching instances -->267 <xsl:for-each select="$instance/@*[local-name()=$name]">268 <cmdm:containsAttribute>269 <xsl:element name="{$id}" namespace="{$ns}">270 <xsl:attribute name="rdf:about" select="concat('#',generate-id(.))"/>271 <xsl:element name="{$has}Value" namespace="{$ns}">272 <!-- map the CMD XSD datatype to a datatype supported by RDF -->273 <xsl:attribute name="rdf:datatype" select="concat('&xsd;',cmd:datatype($profile/Type))"/>274 <!-- copy the literal -->275 <xsl:value-of select="."/>276 </xsl:element>277 <xsl:if test="exists($profile/ValueScheme/enumeration)">278 <xsl:element name="{$has}Entity" namespace="{$ns}">279 <xsl:attribute name="rdf:resource" select="concat($ns,$id,'ValueScheme',$STEP,replace(.,'\s',''))"/>280 </xsl:element>281 </xsl:if>282 </xsl:element>283 </cmdm:containsAttribute>284 </xsl:for-each>285 </xsl:template>286 287 31 </xsl:stylesheet>
Note: See TracChangeset
for help on using the changeset viewer.