source: SMC/trunk/SMC/src/scripts/smc_commons.xsl @ 1607

Last change on this file since 1607 was 1607, checked in by vronk, 13 years ago

intermediate commit, still chaos

File size: 6.7 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3    xmlns:xs="http://www.w3.org/2001/XMLSchema"
4    xmlns:my="myFunctions"
5    exclude-result-prefixes="xs"
6    version="2.0">
7   
8    <xsl:include href="smc_params.xsl"/>
9    <xsl:include href="smc_functions.xsl"/>
10    <xsl:include href="cmd_includes.xsl"/>   
11    <xsl:include href="dcr_rdf2terms.xsl"/>
12   
13    <!-- use either input (precedence) or the config-file as the termsets configuration -->
14    <xsl:variable name="termsets_config">
15        <xsl:choose>
16            <xsl:when test="exists(/Termsets)">
17                <xsl:copy-of select="/Termsets"></xsl:copy-of>
18            </xsl:when>
19            <xsl:otherwise>
20                <xsl:copy-of select="document($termset_config_file)"></xsl:copy-of>
21            </xsl:otherwise>
22        </xsl:choose>       
23    </xsl:variable>
24   
25<!--    needed in cmd_includes.xsl --> 
26   <xsl:variable name="cmd_components_uri" select="my:config('cmd-components','url')" />
27   <xsl:variable name="cmd_profiles_uri" select="my:config('cmd-profiles','url')" />
28
29<!-- intermediate datasets bound into variables,to prevent calling the function every time --> 
30   
31   <xsl:variable name="dcr-terms" select="my:getData('dcr-terms')" />
32   <xsl:variable name="cmd-terms" select="my:getData('cmd-terms')" />
33   <xsl:variable name="dcr-cmd-map" select="my:getData('dcr-cmd-map')" />
34   
35<!-- load all dcrs from the configuration and transform them into Termsets
36       (uses mode=dcr-templates in dcr_rdf2terms.xsl)   
37   -->
38    <xsl:template name="load-dcr">
39        <Termsets type="dcr">
40          <xsl:for-each select="$termsets_config//*[type='dcr']" >
41              <xsl:variable name="dcr_termset" select="document(url)" />           
42                  <xsl:apply-templates select="$dcr_termset" mode="dcr" >
43                      <xsl:with-param name="set" select="key"></xsl:with-param>
44                  </xsl:apply-templates>
45             
46          </xsl:for-each>
47        </Termsets>
48    </xsl:template>
49
50<!--
51    invert the profiles-termsets + match with data from DCRs = create map datcat -> cmd-elements[]
52-->     
53<xsl:template name="dcr-cmd-map">
54    <Termset type="dcr-cmd-map" >       
55        <xsl:for-each-group select="$cmd-terms//Term[not(@datcat='')]" group-by="@datcat">
56            <Concept id="{@datcat}" type="datcat">
57                <xsl:copy-of select="$dcr-terms//Concept[@id=current()/@datcat]/Term" />
58               
59                <xsl:for-each select="current-group()">
60                    <xsl:variable name="parent_profile" select="ancestor::Termset[@type='CMD_Profile']/@id" />
61                    <Term set="cmd" type="full-path" schema="{$parent_profile}" id="{@id}"><xsl:value-of select="@path" /></Term>
62                    <!--<xsl:copy-of select="."></xsl:copy-of>-->
63                </xsl:for-each>
64            </Concept>                         
65        </xsl:for-each-group>
66    </Termset>
67</xsl:template>                 
68
69<!-- list dcr-termsets + cmd (+ cmd-profiles)
70TODO: missing: isocat@langs, RR-sets -->   
71<xsl:template name="termsets">
72    <Termsets type="list">
73        <!-- add dcr-termsets directly from config -->
74        <xsl:for-each select="$termsets_config//*[type='dcr']" >
75            <Termset>
76                <xsl:copy-of select="*" />
77            </Termset>                       
78        </xsl:for-each>
79        <Termset type="cmd">
80          <xsl:for-each select="$cmd-terms//Termset" >
81              <key>cmd-profiles</key>
82              <id><xsl:value-of select="@id"></xsl:value-of></id>
83              <name>CMD Profiles</name>
84              <Termset>
85                  <key><xsl:value-of select="@name"></xsl:value-of></key>
86                  <id><xsl:value-of select="@id"></xsl:value-of></id>
87                  <name><xsl:value-of select="@name"></xsl:value-of></name>
88              </Termset>                       
89          </xsl:for-each>
90        </Termset>
91    </Termsets>
92</xsl:template>
93
94<!--
95    return a property of a Termset from the configuration.
96-->   
97    <xsl:function name="my:config">
98        <xsl:param name="id"></xsl:param>
99        <xsl:param name="property"></xsl:param>
100        <xsl:value-of select="$termsets_config//*[id=$id]/*[name()=$property]"></xsl:value-of>
101    </xsl:function>
102   
103<!-- overload method with one param and cache=use as default -->   
104    <xsl:function name="my:getData">
105        <xsl:param name="key"></xsl:param>
106        <xsl:copy-of select="my:getData($key,'use')"></xsl:copy-of>
107    </xsl:function>
108 
109    <!--
110 serves individual datasets (cmd-profiles, dcr-termsets...)
111    primitive cache mechanism -
112    if data of given key is already stored, serve it,
113    otherwise build a new (but don't store in cache - within this function)
114    regard the cache-param - beware of the param-value in recursive calls (currently 'use' is fixed for deeper calls) 
115 -->
116       
117    <xsl:function name="my:getData">
118        <xsl:param name="key"></xsl:param>
119        <xsl:param name="cache"></xsl:param>
120       
121        <xsl:variable name="cached_data_file" select="concat($cache_dir, $key, '.xml')"></xsl:variable>
122        <xsl:message>
123            <xsl:value-of select="$cached_data_file" />: <xsl:value-of select="doc-available($cached_data_file)" />
124        </xsl:message>
125        <xsl:choose>
126            <xsl:when test="doc-available($cached_data_file) and $cache='use'">
127                <xsl:message>reading in: <xsl:value-of select="$cached_data_file" />                   
128                </xsl:message>
129                <xsl:copy-of select="document($cached_data_file)"></xsl:copy-of>
130            </xsl:when>
131            <xsl:when test="$key='cmd-profiles-raw'">
132                <xsl:copy-of select="document(my:config('cmd-profiles','url'))" />                     
133            </xsl:when>
134            <xsl:when test="$key='cmd-resolved'">
135                <xsl:apply-templates select="my:getData('cmd-profiles')" mode="include" />               
136            </xsl:when>
137            <xsl:when test="$key='cmd-terms'">
138                <xsl:copy-of select="my:profiles2termsets(my:getData('cmd-resolved')//profileDescription)" />
139            </xsl:when>
140            <xsl:when test="$key='dcr-terms'">
141                <xsl:call-template name="load-dcr" />                                                           
142            </xsl:when>
143            <xsl:when test="$key='termsets'">
144                <xsl:call-template name="termsets" />                                                           
145            </xsl:when>
146            <xsl:when test="$key='dcr-cmd-map'">
147                <xsl:call-template name="dcr-cmd-map" />
148            </xsl:when>                     
149            <xsl:otherwise>     
150                <diagnostics>unknown data: <xsl:value-of select="$key" /></diagnostics>
151            </xsl:otherwise>
152        </xsl:choose>
153       
154    </xsl:function>
155   
156   
157</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.