Changeset 5243


Ignore:
Timestamp:
05/20/14 19:24:02 (10 years ago)
Author:
Menzo Windhouwer
Message:

M xsl/Component2RDF.xsl

  • now creates an output RDF file per profile and component
  • the output location is controlled by an out parameter
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CMDI-Interoperability/CMD2RDF/trunk/xsl/Component2RDF.xsl

    r4830 r5243  
    66    <!ENTITY cmdm 'http://www.clarin.eu/cmd/general.rdf#'>
    77]>
    8 <xsl:stylesheet
    9     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    10     xmlns:dcr="http://www.isocat.org/ns/dcr.rdf#"
    11     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    12     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    13     xmlns:cmd="http://www.clarin.eu/cmd/"
    14     xmlns:cmdm="http://www.clarin.eu/cmd/general.rdf"
    15     xmlns:dcterms="http://purl.org/dc/terms/"
    16 >
    17    
     8<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:dcr="http://www.isocat.org/ns/dcr.rdf#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:cmd="http://www.clarin.eu/cmd/" xmlns:cmdm="http://www.clarin.eu/cmd/general.rdf" xmlns:dcterms="http://purl.org/dc/terms/">
     9
    1810    <xsl:output method="xml" encoding="UTF-8"/>
    19    
    20     <xsl:param name="base" select="base-uri()"/>
    21    
     11
     12    <xsl:param name="out" select="'.'"/>
     13
    2214    <xsl:include href="CMD2RDF.xsl"/>
    23    
     15
    2416    <!-- let's create some RDF -->
    25     <xsl:template match="/">
     17    <xsl:template match="/CMD_ComponentSpec">
    2618        <!-- for the output base replace the xml extension by rdf -->
    27         <rdf:RDF xml:base="{replace($base,'xml$','')}rdf#">
    28             <xsl:apply-templates>
    29                 <xsl:with-param name="context" tunnel="yes" select="''"/>
    30             </xsl:apply-templates>
    31         </rdf:RDF>   
    32     </xsl:template>
    33    
     19        <xsl:result-document href="{concat($out,'/',Header/ID,'.rdf')}">
     20            <rdf:RDF xml:base="{if (@isProfile='true') then (cmd:ppath(Header/ID,'rdf')) else (cmd:cpath(Header/ID,'rdf'))}#">
     21                <xsl:apply-templates>
     22                    <xsl:with-param name="context" tunnel="yes" select="''"/>
     23                </xsl:apply-templates>
     24            </rdf:RDF>
     25        </xsl:result-document>
     26    </xsl:template>
     27
    3428    <!-- override default text template -->
    3529    <xsl:template match="text()"/>
    36    
     30
    3731    <!-- some attributes appear everywhere -->
    3832    <xsl:template name="generic">
     
    4842        </xsl:if>
    4943    </xsl:template>
    50    
     44
    5145    <!-- a profile (and component?) contains all the nested components as well,
    5246         but as these are shared we want to also share their RDF representations.
    53          So cut off the traversal when there is reuse. -->
    54     <xsl:template match="CMD_Component[exists(@ComponentId)]"/>
    55 
    56     <!-- component belonging only to the root profile/component -->
    57     <xsl:template match="CMD_Component[empty(@ComponentId)]">
     47         So restart the traversal when there is reuse. -->
     48    <xsl:template match="CMD_Component[exists(@ComponentId)]">
     49        <xsl:if test="empty(preceding::CMD_Component[@ComponentId=current()/@ComponentId])">
     50            <xsl:result-document href="{concat($out,'/',@ComponentId,'.rdf')}">
     51                <!-- for the output base replace the xml extension by rdf -->
     52                <rdf:RDF xml:base="{cmd:cpath(@ComponentId,'rdf')}#">
     53                    <xsl:call-template name="CMD_Component">
     54                        <xsl:with-param name="context" tunnel="yes" select="''"/>
     55                    </xsl:call-template>
     56                </rdf:RDF>
     57            </xsl:result-document>
     58        </xsl:if>
     59    </xsl:template>
     60
     61    <xsl:template name="CMD_Component">
    5862        <xsl:param name="context" tunnel="yes"/>
    5963        <!-- extend the context path with this component -->
     
    6266        <rdfs:Class rdf:about="{$id}">
    6367            <xsl:choose>
    64                 <xsl:when test="../CMD_ComponentSpec/@isProfile='true'">
     68                <xsl:when test="parent::CMD_ComponentSpec/@isProfile='true'">
    6569                    <rdfs:subClassOf rdf:resource="&cmdm;Profile"/>
    6670                </xsl:when>
     
    7478                </dcterms:identifier>
    7579            </xsl:if>
     80            <xsl:if test="exists(@ComponentId)">
     81                <dcterms:identifier>
     82                    <xsl:value-of select="@ComponentId"/>
     83                </dcterms:identifier>
     84            </xsl:if>
    7685            <xsl:call-template name="generic"/>
    7786        </rdfs:Class>
     
    8190        </xsl:apply-templates>
    8291    </xsl:template>
    83    
     92
     93    <!-- component belonging only to the root profile/component -->
     94    <xsl:template match="CMD_Component[empty(@ComponentId)]">
     95        <xsl:param name="context" tunnel="yes"/>
     96        <xsl:call-template name="CMD_Component">
     97            <xsl:with-param name="context" tunnel="yes" select="$context"/>
     98        </xsl:call-template>
     99    </xsl:template>
     100
    84101    <!-- a CMD element -->
    85102    <xsl:template match="CMD_Element">
     
    131148        </xsl:apply-templates>
    132149    </xsl:template>
    133    
     150
    134151    <!-- a CDM value -->
    135152    <xsl:template match="item">
     
    148165        </rdf:Class>
    149166    </xsl:template>
    150    
     167
    151168    <!-- a CMD attribute -->
    152169    <xsl:template match="Attribute">
     
    163180        <rdf:Property rdf:about="{$has}Value">
    164181            <rdfs:subPropertyOf rdf:resource="&cmdm;hasAttributeValue"/>
    165             <!-- the domain is the CMD element RDF class --> 
     182            <!-- the domain is the CMD element RDF class -->
    166183            <rdfs:domain rdf:resource="{$id}"/>
    167184            <xsl:choose>
     
    187204            <rdf:Property rdf:about="{$has}Entity">
    188205                <rdfs:subPropertyOf rdf:resource="&cmdm;hasAttributeEntity"/>
    189                 <!-- the domain is the CMD element RDF class --> 
     206                <!-- the domain is the CMD element RDF class -->
    190207                <rdfs:domain rdf:resource="{id}"/>
    191208                <!-- the range consists of a superclass for the specific value classes -->
Note: See TracChangeset for help on using the changeset viewer.