Changeset 3437


Ignore:
Timestamp:
08/20/13 11:31:41 (11 years ago)
Author:
vronk
Message:

added generation of direct edges profiles-datcats and edges for datcat-relations (from RR)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • SMC/trunk/SMC/src/xsl/terms2graph.xsl

    r2962 r3437  
    1 <?xml version="1.0"?>
    2 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    3          xmlns:my="myFunctions" >
    4    
    5     <xsl:import href="graph2json-d3.xsl" />
    6    
    7                         <xsl:output method="xml" encoding="utf-8"                           
    8                         indent="yes"
    9                             />
     1<?xml version="1.0" encoding="UTF-8"?>
     2<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="myFunctions" version="2.0" xml:space="default">
     3<!--    <xsl:import href="graph2json-d3.xsl"/>-->
     4    <xsl:output method="xml" encoding="utf-8" indent="yes"/>
    105<!--
    116<purpose>generate a graph (xml) of CMD-component reuse (based on smc:cmd-terms)
     
    1712<sample>
    1813-->
    19 
    20 
    21 <xsl:variable name="title" select="'mdrepo stats'" />
    22    
    23     <xsl:param name="profiles" select="''" />  <!--teiHeader-->
    24     <xsl:param name="format" select="'xml'" />  <!-- xml | json-d3 ;  todo: dot, json-jit?  -->
    25     <xsl:param name="rank-distance" select="50" />
    26    
    27     <xsl:param name="base-uri" select="base-uri(/)" />
    28     <xsl:param name="dcr-terms" select="doc(resolve-uri('dcr-terms.xml',$base-uri))" />
     14    <xsl:variable name="title" select="'mdrepo stats'"/>
     15    <xsl:param name="profiles" select="''"/>  <!--teiHeader-->
     16    <xsl:param name="format" select="'xml'"/>  <!-- xml | json-d3 ;  todo: dot, json-jit?  -->
     17    <xsl:param name="rank-distance" select="50"/>
     18    <xsl:param name="base-uri" select="base-uri(/)"/>
     19    <xsl:param name="dcr-terms" select="doc(resolve-uri('dcr-terms.xml',$base-uri))"/>
     20    <xsl:param name="rr-relations" select="doc(resolve-uri('rr-relations.xml',$base-uri))"/>
     21    <xsl:variable name="dcr-terms-copy">
     22        <xsl:apply-templates select="$dcr-terms" mode="copy"/>
     23    </xsl:variable>
     24<!--        <xsl:param name="dcr-terms" select="()"/>-->
    2925   
    3026<!--    <xsl:param name="cmd-terms-uri" select="doc(resolve-uri('cmd-terms-nested.xml',$base-uri))" />-->
    31         <xsl:param name="cmd-terms-uri" select="doc(resolve-uri('cmd-terms-nested.xml',$base-uri))" />
    32     <xsl:param name="cmd-terms" select="doc($cmd-terms-uri)" />
    33 
    34     <xsl:key name="cmd-terms-path" match="Term" use="@path"></xsl:key>
    35 
    36 <xsl:template match="/">
    37         <xsl:variable name="filtered-termsets" >
    38             <xsl:choose>
    39                 <xsl:when test="not($profiles='')">
    40                     <xsl:copy-of select="//Termset[contains($profiles,@id) or contains($profiles,@name)]"></xsl:copy-of>
    41                 </xsl:when>
    42                 <xsl:otherwise><xsl:copy-of select="//Termset"></xsl:copy-of></xsl:otherwise>
    43             </xsl:choose>
    44            
    45         </xsl:variable>
     27    <xsl:param name="cmd-terms-uri" select="resolve-uri('cmd-terms-nested.xml',$base-uri)"/>
     28    <xsl:param name="cmd-terms" select="doc($cmd-terms-uri)"/>
     29    <xsl:variable name="cmd-terms-copy">
     30        <xsl:apply-templates select="$cmd-terms/*" mode="copy"/>
     31    </xsl:variable>
     32   
     33<!--    <xsl:param name="cmd-terms" select="()"/>-->
     34    <xsl:key name="cmd-terms-path" match="Term" use="@path"/>
     35    <xsl:key name="dcr-terms" match="Concept" use="@id"/>
     36    <xsl:template match="/">
     37<!--        <xsl:value-of select="doc-available(resolve-uri('../data/cmd-terms-nested.xml',$base-uri))"></xsl:value-of>-->
     38        <xsl:variable name="filtered-termsets">
     39            <xsl:choose>
     40                <xsl:when test="not($profiles='')">
     41                    <xsl:copy-of select="//Termset[contains($profiles,@id) or contains($profiles,@name)]"/>
     42                </xsl:when>
     43                <xsl:otherwise>
     44                    <xsl:copy-of select="//Termset"/>
     45                </xsl:otherwise>
     46            </xsl:choose>
     47        </xsl:variable>
    4648       
    47         <!-- if instance data - merge with cmd-terms (to get the IDs) -->
    48     <xsl:variable name="enriched-termsets" >
    49         <xsl:choose>
    50             <xsl:when test="$filtered-termsets//Termset[@type='CMD_Profile']">
    51                 <xsl:copy-of select="$filtered-termsets"></xsl:copy-of>
    52             </xsl:when>
    53             <xsl:otherwise>
    54                 <xsl:apply-templates select="$filtered-termsets//Termset" mode="enrich" ></xsl:apply-templates>
    55            
    56             </xsl:otherwise>
    57         </xsl:choose>
    58        
    59     </xsl:variable>
    60        
    61         <xsl:variable name="nodes">
     49        <!-- if instance data - merge with cmd-terms (to get the IDs) -->
     50        <xsl:variable name="enriched-termsets">
     51            <xsl:choose>
     52                <xsl:when test="$filtered-termsets//Termset[@type='CMD_Profile']">
     53                    <xsl:copy-of select="$filtered-termsets"/>
     54                </xsl:when>
     55                <xsl:otherwise>
     56                    <xsl:apply-templates select="$filtered-termsets//Termset" mode="enrich"/>
     57                </xsl:otherwise>
     58            </xsl:choose>
     59        </xsl:variable>
     60        <xsl:variable name="nodes">
    6261            <!--<xsl:for-each select="$filtered-termsets//Termset/Term">
    6362           
    6463                <xsl:variable name="profile" select="$cmd-terms//Termset[@name=current()/@name]"></xsl:variable>
    6564<!-\-               DEBUG:-<xsl:value-of select="current()/@name"/><xsl:copy-of select="$profile"></xsl:copy-of>-\->
    66         -->   
    67                 <xsl:apply-templates select="$enriched-termsets//Term" mode="nodes">
     65        -->
     66            <xsl:apply-templates select="$enriched-termsets//Termset[@context]" mode="nodes-collections"/>
     67            <xsl:apply-templates select="$enriched-termsets//Termset" mode="nodes"/>
     68            <xsl:apply-templates select="$enriched-termsets//Term" mode="nodes">
    6869<!--                    <xsl:with-param name="cmd-terms" select="$profile"></xsl:with-param>-->
    69             </xsl:apply-templates>
    70             <xsl:apply-templates select="$enriched-termsets//Term" mode="nodes-datcats"/>
     70            </xsl:apply-templates>
     71            <xsl:apply-templates select="$enriched-termsets//Term" mode="nodes-datcats"/>
     72            <xsl:for-each-group select="$rr-relations//Concept" group-by="@id">
     73                <xsl:variable name="datcat-id" select="@id"/>
     74                <xsl:variable name="get-mnemonic">
     75                    <xsl:for-each select="$dcr-terms-copy">
     76                        <xsl:copy-of select="key('dcr-terms', $datcat-id)/Term[@type=('mnemonic','label')][1]"/>
     77                        <!--                /Concept/Term[@type='mnemonic']-->
     78                    </xsl:for-each>
     79                </xsl:variable>
     80                <xsl:variable name="datcat-name">
     81                    <!--            <xsl:variable name="get-mnemonic" select="$dcr-terms//Concept[@id=current()/@datcat]/Term[@type='mnemonic']"/>-->
     82                    <xsl:value-of select="if($get-mnemonic ne '') then $get-mnemonic else tokenize($datcat-id,'/')[last()]"/>
     83                </xsl:variable>
     84                <node id="{@id}" key="{my:normalize(@id)}" name="{$datcat-name}" type="DatCat">
     85                    <xsl:copy-of select="@*[not (name()=('count','type'))]"/>
     86                </node>
     87            </xsl:for-each-group>
    7188               
    7289<!--        </xsl:for-each>-->
    73         </xsl:variable>
    74     <xsl:variable name="edges">
    75         <xsl:apply-templates select="$enriched-termsets//Term" mode="edges"/>
    76         <xsl:apply-templates select="$enriched-termsets//Term" mode="edges-datcats" />
    77     </xsl:variable>
    78         <xsl:variable name="distinct-nodes"  >
     90        </xsl:variable>
     91        <xsl:variable name="edges">
     92            <!--<xsl:apply-templates select="$enriched-termsets//Termset[@context]/Term" mode="edges-collections"/>
     93            <xsl:apply-templates select="$enriched-termsets//Term" mode="edges"/>
     94            <xsl:apply-templates select="$enriched-termsets//Term" mode="edges-datcats"/>-->
     95            <xsl:apply-templates select="$enriched-termsets//Term" mode="edges-profiles-datcats"/>
     96            <xsl:apply-templates select="$rr-relations//Relation" mode="edges-rels"/>
     97        </xsl:variable>
     98        <xsl:variable name="distinct-nodes">
    7999            <xsl:for-each-group select="$nodes/*" group-by="@key">
    80                
    81                 <node position="{position()}" count="{(@count, count(current-group()))}" 
    82                       avg_level="{avg(current-group()/@level)}" sum_level="{sum(current-group()/@level)}">
    83                     <xsl:copy-of select="@*" />
     100                <node position="{position()}" count="{(sum(current-group()/@count[number(.)=number(.)]), count(current-group()))[1]}" avg_level="{avg(current-group()/@level)}" sum_level="{sum(current-group()/@level)}">
     101                    <xsl:copy-of select="@*[not (name()='count')]"/>
    84102                </node>
    85103            </xsl:for-each-group>
    86104        </xsl:variable>
    87    
    88     <xsl:variable name="distinct-edges">
    89      <xsl:for-each-group select="$edges/*" group-by="concat(@from, @to)">
    90          <xsl:variable name="count" select="count(current-group())"  />   
    91          <xsl:variable name="ix_from" select="$distinct-nodes/*[@key=current()/@from]/@position - 1 "  />
    92          <xsl:variable name="ix_to" select="$distinct-nodes/*[@key=current()/@to]/@position - 1"  />
    93          <edge ix_from="{$ix_from}"  ix_to="{$ix_to}" from="{@from}" to="{@to}" value="{$count}" />
    94      </xsl:for-each-group>
    95     </xsl:variable>
    96    
    97     <xsl:variable name="graph">
    98         <graph>
    99             <nodes count="{count($filtered-termsets//Term)}">
    100 <!--                <xsl:copy-of select="$enriched-termsets" />-->
    101             <xsl:copy-of select="$distinct-nodes" />
    102             </nodes>
    103             <edges>
    104             <xsl:copy-of select="$distinct-edges" />
    105             </edges>
    106         </graph>
    107     </xsl:variable>
    108    
    109     <xsl:choose>
    110         <xsl:when test="$format='json-d3'">
    111             <xsl:apply-templates select="$graph"></xsl:apply-templates>
    112         </xsl:when>
    113         <xsl:when test="$format='xml'">
    114             <xsl:copy-of select="$graph" />
    115         </xsl:when>
    116         <xsl:otherwise>
    117             unknown format: <xsl:value-of select="$format"></xsl:value-of>
    118         </xsl:otherwise>
    119     </xsl:choose>
    120            
    121 </xsl:template>
    122 
    123 
     105        <xsl:variable name="distinct-edges">
     106            <xsl:for-each-group select="$edges/*" group-by="concat(@from, @to)">
     107                <xsl:variable name="count" select="count(current-group())"/>
     108                <xsl:variable name="ix_from" select="$distinct-nodes/*[@key=current()/@from]/@position - 1 "/>
     109                <xsl:variable name="ix_to" select="$distinct-nodes/*[@key=current()/@to]/@position - 1"/>
     110                <edge ix_from="{$ix_from}" ix_to="{$ix_to}" from="{@from}" to="{@to}" value="{$count}"/>
     111            </xsl:for-each-group>
     112        </xsl:variable>
     113        <xsl:variable name="graph">
     114            <graph>
     115                <nodes count="{count($filtered-termsets//Term)}">
     116                   
     117<!--                                                            <xsl:copy-of select="$dcr-terms-copy"/>-->
     118                    <xsl:copy-of select="$distinct-nodes"/>
     119                </nodes>
     120                <edges>
     121                    <xsl:copy-of select="$distinct-edges"/>
     122                </edges>
     123            </graph>
     124        </xsl:variable>
     125        <xsl:choose>
     126            <xsl:when test="$format='json-d3'">
     127                <xsl:apply-templates select="$graph"/>
     128            </xsl:when>
     129            <xsl:when test="$format='xml'">
     130                <xsl:copy-of select="$graph"/>
     131            </xsl:when>
     132            <xsl:otherwise>
     133            unknown format: <xsl:value-of select="$format"/>
     134            </xsl:otherwise>
     135        </xsl:choose>
     136    </xsl:template>
     137    <xsl:template match="*|@*" mode="copy">
     138        <xsl:copy>
     139            <xsl:apply-templates select="*|@*|text()" mode="copy"/>
     140        </xsl:copy>
     141    </xsl:template>
     142    <xsl:template match="text()" mode="copy">
     143        <xsl:copy/>
     144    </xsl:template>
     145   
    124146<!--
    125147    <Termset name="Bedevaartbank" id="clarin.eu:cr1:p_1280305685223" type="CMD_Profile">
     
    127149        <Term type="CMD_Component" name="Database" datcat="" id="clarin.eu:cr1:c_1280305685207" elem="Database" parent="Bedevaartbank" path="Bedevaartbank.Database"/>
    128150-->
    129 
    130 <xsl:template match="Term[Term]" mode="nodes">
    131 <xsl:param name="cmd-terms" select="$cmd-terms"></xsl:param>   
     151    <xsl:template match="Term[not(parent::Termset)][Term]" mode="nodes">
     152        <xsl:param name="cmd-terms" select="$cmd-terms"/>   
     153        <!--<xsl:variable name="current_comp_key" select="my:normalize(concat(@id, '_', @name))" />-->
     154        <!--<xsl:variable name="equivalent-cmd-term"
     155        select="$cmd-terms//Term[@path=current()/@path]/@id" />
     156    -->
     157        <xsl:variable name="current_comp_key" select="my:normalize(@id)"/>
     158        <xsl:variable name="type">
     159            <xsl:choose>
     160                <xsl:when test="@parent=''">Profile</xsl:when>
     161                <xsl:otherwise>Component</xsl:otherwise>
     162            </xsl:choose>
     163        </xsl:variable>
     164        <xsl:variable name="level" select="count(ancestor::Term)"/>
     165        <node id="{@id}" key="{$current_comp_key}" name="{@name}" type="{$type}" level="{$level}" count="{@count}" path="{@path}">
     166            <!--       <xsl:value-of select="$equivalent_schema_term"></xsl:value-of>-->
     167        </node>
     168    </xsl:template>
     169   
     170    <!-- not root components = (mostly) profiles -->
     171    <xsl:template match="Term[not(parent::Termset)][Term]" mode="nodes">
     172        <xsl:param name="cmd-terms" select="$cmd-terms"/>   
    132173        <!--<xsl:variable name="current_comp_key" select="my:normalize(concat(@id, '_', @name))" />-->
    133174    <!--<xsl:variable name="equivalent-cmd-term"
    134175        select="$cmd-terms//Term[@path=current()/@path]/@id" />
    135176    -->
    136     <xsl:variable name="current_comp_key" select="my:normalize(@id)" />
    137     <xsl:variable name="type" >
    138          <xsl:choose>
    139            <xsl:when test="@parent=''">Profile</xsl:when>
    140                <xsl:otherwise>Component</xsl:otherwise>
    141         </xsl:choose>
    142     </xsl:variable>
    143     <xsl:variable name="level" select="count(ancestor::Term)" />
    144     <node id="{@id}" key="{$current_comp_key}" name="{@name}" type="{$type}" level="{$level}" count="{@count}" freq="{@count}"
    145         path="{@path}">
     177        <xsl:variable name="current_comp_key" select="my:normalize(@id)"/>
     178        <xsl:variable name="type" select="'Component'">
     179            <!--<xsl:choose>
     180                <xsl:when test="@parent=''">Profile</xsl:when>
     181                <xsl:otherwise>Component</xsl:otherwise>
     182            </xsl:choose>-->
     183        </xsl:variable>
     184        <xsl:variable name="level" select="count(ancestor::Term)"/>
     185        <node id="{@id}" key="{$current_comp_key}" name="{@name}" type="{$type}" level="{$level}" count="{@count}" path="{@path}">
    146186<!--       <xsl:value-of select="$equivalent_schema_term"></xsl:value-of>-->
    147     </node>
    148 </xsl:template>
    149 
     187        </node>
     188    </xsl:template>
     189   
     190    <!-- Termset = profiles + root component
     191    (data is inconsistent sometimes profile is the root component, sometimes a separate components (e.g. imdi-session)-->
     192    <xsl:template match="Termset" mode="nodes">
     193        <xsl:param name="cmd-terms" select="$cmd-terms"/>   
     194        <!--<xsl:variable name="current_comp_key" select="my:normalize(concat(@id, '_', @name))" />-->
     195        <!--<xsl:variable name="equivalent-cmd-term"
     196        select="$cmd-terms//Term[@path=current()/@path]/@id" />
     197    -->
     198        <xsl:variable name="current_profile_key" select="my:normalize(@id)"/>
     199       
     200        <node id="{@id}" key="{$current_profile_key}" name="{@name}" type="Profile" level="0" count="{@count}" path="{@path}">
     201            <!--       <xsl:value-of select="$equivalent_schema_term"></xsl:value-of>-->
     202        </node>
     203        <!-- if root component not profile generate a separte node for it -->
     204        <xsl:if test="xs:string(@id) ne Term/xs:string(@id)" >
     205            <xsl:for-each select="Term">           
     206                <node id="{@id}" key="{my:normalize(@id)}" name="{@name}" type="Component" level="1" count="{@count}" path="{@path}" />
     207            </xsl:for-each>
     208        </xsl:if>
     209     </xsl:template>
     210   
     211   
    150212<!--
    151213    <Term type="CMD_Element" name="applicationType"
     
    156218        path="AnnotationTool.applicationType"/>
    157219    -->
    158     <xsl:template match="Term[not(Term)]" mode="nodes">   
    159         <xsl:param name="cmd-terms" select="$cmd-terms"></xsl:param>   
     220    <xsl:template match="Term[not(Term)]" mode="nodes">
     221        <xsl:param name="cmd-terms" select="$cmd-terms"/>   
    160222        <!--<xsl:variable name="equivalent-cmd-term"
    161223            select="$cmd-terms//Term[@path=current()/@path]/@id" />
    162224-->
    163         <xsl:variable name="current_elem_key" select="my:normalize(@id)" />
    164        
    165         <xsl:variable name="level" select="count(ancestor::Term)" />
    166         <node id="{@id}" key="{$current_elem_key}" name="{@name}" type="Element" level="{$level}"/>
     225        <xsl:variable name="current_elem_key" select="my:normalize(@id)"/>
     226        <xsl:variable name="level" select="count(ancestor::Term)"/>
     227        <node id="{@id}" key="{$current_elem_key}" name="{@name}" type="Element" level="{$level}" count="{@count}"/>
    167228<!--        <xsl:message><xsl:value-of select="concat(@id, '-', ancestor::Term[1]/@id)"></xsl:value-of></xsl:message>-->
    168        
    169229    </xsl:template>
    170230   
     
    172232    <!--    process Terms (not only Elements!) once again, to get datcat-nodes -->
    173233    <xsl:template match="Term[@datcat][not(@datcat='')]" mode="nodes-datcats">
    174        
    175         <xsl:variable name="level" select="count(ancestor::Term) + 1" />
    176             <xsl:variable name="datcat-name"  >
    177                 <xsl:variable name="get-mnemonic" select="$dcr-terms//Concept[@id=current()/@datcat]/Term[@type='mnemonic']" />
    178                 <xsl:value-of select="if($get-mnemonic) then $get-mnemonic else tokenize(@datcat,'/')[last()]" />
    179             </xsl:variable>       
    180             <node id="{@datcat}" key="{my:normalize(@datcat)}" name="{$datcat-name}" type="DatCat" level="{$level}"/>
    181        
    182     </xsl:template>
    183    
    184    
    185    
     234        <xsl:variable name="level" select="count(ancestor::Term) + 1"/>
     235        <xsl:variable name="datcat-id" select="@datcat"/>
     236        <xsl:variable name="get-mnemonic">
     237            <xsl:for-each select="$dcr-terms-copy">
     238                <xsl:copy-of select="key('dcr-terms', $datcat-id)/Term[@type=('mnemonic','label')][1]"/>
     239<!--                /Concept/Term[@type='mnemonic']-->
     240            </xsl:for-each>
     241        </xsl:variable>
     242        <xsl:variable name="datcat-name">
     243<!--            <xsl:variable name="get-mnemonic" select="$dcr-terms//Concept[@id=current()/@datcat]/Term[@type='mnemonic']"/>-->
     244            <xsl:value-of select="if($get-mnemonic ne '') then $get-mnemonic else tokenize(@datcat,'/')[last()]"/>
     245        </xsl:variable>
     246<!--        <xsl:value-of select="$get-mnemonic"/>-->
     247        <node id="{$datcat-id}" key="{my:normalize($datcat-id)}" name="{$datcat-name}" type="DatCat" level="{$level}"/>
     248    </xsl:template>
     249    <xsl:template match="Termset[@context]" mode="nodes-collections">   
     250        <!--<xsl:variable name="current_comp_key" select="my:normalize(concat(@id, '_', @name))" />-->
     251        <!--<xsl:variable name="equivalent-cmd-term"
     252        select="$cmd-terms//Term[@path=current()/@path]/@id" />
     253    -->
     254        <xsl:variable name="coll_key" select="my:normalize(@context)"/>
     255        <xsl:variable name="type" select="'Collection'"/>
     256        <xsl:variable name="level" select="-1"/>
     257        <node id="{@context}" key="{$coll_key}" name="{translate(@context, '_', ' ')}" type="{$type}" level="{$level}" count="{sum(Term/@count)}" path="{@context}">
     258            <!--       <xsl:value-of select="$equivalent_schema_term"></xsl:value-of>-->
     259        </node>
     260    </xsl:template>
     261    <xsl:template match="Termset[@context]/Term" mode="edges-collections">
     262       
     263        <!-- cater for both: flat and nested input structure -->
     264        <xsl:variable name="parent_coll" select="(parent::Termset/@context)"/>
     265        <xsl:variable name="curr_profile_key" select="my:normalize(@id)"/>
     266        <edge from="{my:normalize($parent_coll)}" to="{$curr_profile_key}"/>
     267    </xsl:template>
     268   
     269    <!--<Relation type="sameAs">
     270        <Concept type="datcat" id="http://www.isocat.org/datcat/DC-2520" role="about"/>
     271        <Concept type="datcat" id="http://purl.org/dc/elements/1.1/description"/>
     272    </Relation>-->
     273    <xsl:template match="Relation" mode="edges-rels">
     274        <edge from="{my:normalize(Concept[1]/@id)}" to="{my:normalize(Concept[2]/@id)}" type="{@type}"/>
     275        <edge from="{my:normalize(Concept[2]/@id)}" to="{my:normalize(Concept[1]/@id)}" type="-{@type}"/>
     276    </xsl:template>
     277   
    186278<!--    process both Components and Elements, from the child point of view
    187279    i.e. find the parent -->
     
    190282       
    191283        <!-- cater for both: flat and nested input structure -->
    192         <xsl:variable name="parent" select="(parent::Term[@type='CMD_Component'][1] | preceding-sibling::Term[@type='CMD_Component'][@name=current()/@parent][1])[1]" />
    193         <xsl:variable name="current_comp_key" select="my:normalize(@id)" />
    194        
    195         <edge from="{my:normalize($parent/@id)}"
    196                 to="{$current_comp_key}" />
    197    
     284        <xsl:variable name="parent" select="(parent::Term[@type='CMD_Component'][1] | preceding-sibling::Term[@type='CMD_Component'][@name=current()/@parent][1])[1]"/>
     285        <xsl:variable name="current_comp_key" select="my:normalize(@id)"/>
     286        <edge from="{my:normalize($parent/@id)}" to="{$current_comp_key}"/>
    198287    </xsl:template>
    199288   
    200289    <!--    process Terms (not only Elements!) once again, to get links to datcats -->
    201290    <xsl:template match="Term[exists(@datcat) and not(@datcat='')]" mode="edges-datcats">
    202         <xsl:variable name="current_comp_key" select="my:normalize(@id)" />
    203        
    204         <edge from="{$current_comp_key}"
    205             to="{my:normalize(@datcat)}" />
    206        
    207     </xsl:template>
    208    
    209    
    210    
     291        <xsl:variable name="current_comp_key" select="my:normalize(@id)"/>
     292        <edge from="{$current_comp_key}" to="{my:normalize(@datcat)}"/>
     293    </xsl:template>
     294   
     295    <!-- alternatively process Terms to generate direct links between Profiles and Datcats -->
     296    <xsl:template match="Term[exists(@datcat) and not(@datcat='')]" mode="edges-profiles-datcats">
     297        <xsl:variable name="current_profile_key" select="my:normalize(ancestor::Termset/@id)"/>
     298        <edge from="{$current_profile_key}" to="{my:normalize(@datcat)}"/>
     299    </xsl:template>
    211300    <xsl:template match="Termset" mode="enrich">
    212301       
    213302        <!-- get the correct profile matching on the name of the top element -->
    214         <xsl:variable name="profile" select="$cmd-terms//Termset[@name=current()/Term/@name]"></xsl:variable>
     303        <xsl:variable name="profile" select="$cmd-terms-copy//Termset[@name=current()/Term/@name]"/>
    215304        <!--                DEBUG:-<xsl:value-of select="current()/@name"/><xsl:copy-of select="$profile"></xsl:copy-of>-->
    216305        <xsl:copy>
    217             <xsl:copy-of select="@*"></xsl:copy-of>
    218          <xsl:apply-templates select="Term" mode="enrich">
    219              <xsl:with-param name="cmd-terms" select="$profile"></xsl:with-param>
    220          </xsl:apply-templates>
     306            <xsl:copy-of select="@*"/>
     307            <xsl:apply-templates select="Term" mode="enrich">
     308                <xsl:with-param name="cmd-terms">
     309                    <xsl:apply-templates select="$profile/*" mode="copy"/>
     310                </xsl:with-param>
     311            </xsl:apply-templates>
    221312        </xsl:copy>
    222313    </xsl:template>
    223    
    224    <xsl:template match="Term" mode="enrich">   
    225       <xsl:param name="cmd-terms" select="$cmd-terms"></xsl:param>   
    226    
    227        <xsl:variable name="curr_path" select="@path" />
    228        <xsl:variable name="equivalent-cmd-term" >
    229 <!--           select="$cmd-terms//Term[@path=current()/@path]" -->
    230            <xsl:for-each select="$cmd-terms">
    231                <xsl:copy-of select="key('cmd-terms-path',$curr_path)"></xsl:copy-of>
    232            </xsl:for-each>
    233        </xsl:variable>
     314    <xsl:template match="Term" mode="enrich">
     315        <xsl:param name="cmd-terms" select="$cmd-terms"/>
     316        <xsl:variable name="curr_path" select="xs:string(@path)"/>
     317        <xsl:variable name="equivalent-cmd-term">
     318            <xsl:call-template name="get-equivalent-cmd-term">
     319                <xsl:with-param name="cmd-terms" select="$cmd-terms-copy"/>
     320                <xsl:with-param name="path" select="xs:string(@path)"/>
     321            </xsl:call-template>
     322        </xsl:variable>
    234323       
    235324<!--        <xsl:variable name="current_elem_key" select="my:normalize((@id,$equivalent-cmd-term)[1])" />-->
    236        
    237         <xsl:copy>
    238             <xsl:attribute name="curr_path" select="$curr_path" />
    239             <xsl:copy-of select="@*"></xsl:copy-of>
    240 <!--            <xsl:copy-of select="$equivalent-cmd-term/*" />-->
    241             <xsl:copy-of select="$equivalent-cmd-term/*/(@type,@parent,@id)"></xsl:copy-of>
    242             <xsl:apply-templates select="Term" mode="enrich"></xsl:apply-templates>
    243         </xsl:copy>
     325        <!--            <xsl:attribute name="curr_path" select="$curr_path"/>-->
     326        <Term>
     327            <xsl:copy-of select="@*"/>
     328            <xsl:copy-of select="$equivalent-cmd-term/*/(@type,@parent,@id,@datcat)"/>
     329            <!--          type="{$equivalent-cmd-term/*/@type}" id="{$equivalent-cmd-term/*/@id}"  <xsl:copy-of select="$equivalent-cmd-term/*/(@parent,@id)"/><xsl:copy-of select="@*"/>-->
     330<!--            <xsl:value-of select="$equivalent-cmd-term" />-->
     331            <xsl:apply-templates select="Term" mode="enrich"/>
     332        </Term>
    244333<!--        <xsl:variable name="level" select="count(ancestor::Term)" />
    245334        <node id="{(@id,$equivalent-cmd-term)}" key="{$current_elem_key}" name="{@name}" type="Element" level="{$level}"/>
    246335        <!-\-        <xsl:message><xsl:value-of select="concat(@id, '-', ancestor::Term[1]/@id)"></xsl:value-of></xsl:message>-\->
    247 -->       
    248        
    249     </xsl:template>
    250 
    251 <xsl:function name="my:normalize">
    252 <xsl:param name="value" />             
    253                 <xsl:value-of select="translate($value,'*/-.'',$@={}:[]()#>&lt; ','XZ__')" />           
    254 </xsl:function>
    255 
    256 <xsl:function name="my:simplify">
    257 <xsl:param name="value" />             
    258                 <xsl:value-of select="replace($value,'http://www.clarin.eu/cmd/components/','cmd:')" />         
    259 </xsl:function>
    260 
    261 
    262 <xsl:template match="text()"/> 
    263 
     336-->
     337    </xsl:template>
     338    <xsl:template name="get-equivalent-cmd-term">
     339        <xsl:param name="cmd-terms" select="$cmd-terms"/>
     340        <xsl:param name="path" select="xs:string(@path)"/>
     341        <xsl:for-each select="$cmd-terms">
     342            <xsl:copy-of select="key('cmd-terms-path',$path)"/>
     343        </xsl:for-each>
     344    </xsl:template>
     345    <xsl:function name="my:normalize">
     346        <xsl:param name="value"/>
     347        <xsl:value-of select="translate($value,'*/-.'',$@={}:[]()#&gt;&lt; ','XZ__')"/>
     348    </xsl:function>
     349    <xsl:function name="my:simplify">
     350        <xsl:param name="value"/>
     351        <xsl:value-of select="replace($value,'http://www.clarin.eu/cmd/components/','cmd:')"/>
     352    </xsl:function>
     353    <xsl:template match="text()"/>
    264354</xsl:stylesheet>
Note: See TracChangeset for help on using the changeset viewer.