Changeset 3439 for SMC


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

added getData template, able to write to cache (+ getData function for convenience), load-profiles template to fill profiles cache);
moved documentation from comments to xd:elements

File:
1 edited

Legend:

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

    r2437 r3439  
    88    <xsl:include href="dcr_rdf2terms.xsl"/>
    99    <xsl:include href="dcr_dcif2terms.xsl"/>
    10    
    11     <!-- use either input (precedence) or the config-file as the termsets configuration -->
     10   
     11    <xsl:output method="xml" indent="yes" exclude-result-prefixes="#all" name="xml"/>
     12   
     13    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
     14        <xd:desc>
     15            <xd:p>use either input (precedence) or the config-file as the termsets configuration</xd:p>
     16        </xd:desc>
     17    </xd:doc>
    1218    <xsl:variable name="termsets_config">
    1319        <xsl:choose>
     
    2329<!--    needed in cmd_includes.xsl -->
    2430   <xsl:variable name="cmd_components_uri" select="my:config('cmd-components','url')" />
    25    <xsl:variable name="cmd_profiles_uri" select="my:config('cmd-profiles','url')" />
     31   <xsl:variable name="cmd_profiles_uri" select="my:config('cmd-profiles','url_prefix')" />
    2632   
    2733<!-- intermediate datasets bound into variables,to prevent calling the function every time -->
     
    3541   <xsl:variable name="isocat-languages" select="my:getData('isocat-languages')" />
    3642   
    37  <!-- serves individual datasets (cmd-profiles, dcr-termsets...)
    38         primitive cache mechanism -
    39         if data of given key is already stored, serve it,
    40         otherwise build a new (but don't store in cache - within this function)
    41         regard the cache-param - beware of the param-value in recursive calls (currently 'use' is fixed for deeper calls)     -->
     43    <!--  -->
     44   
     45    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
     46        <xd:desc>
     47            <xd:p>either serves a dataset or invokes its generation and stores to cache, based on the cache parameter</xd:p>
     48            <xd:p>passes down to my:getData() function for actual generation of the dataset</xd:p>
     49        </xd:desc>
     50        <xd:param name="key">dataset key</xd:param>
     51        <xd:param name="id">optional profile or component identifier to retrieve a single profile or component</xd:param>
     52        <xd:param name="cache">use: returns the requested dataset, refresh: writes the dataset to cache (overwriting)</xd:param>
     53    </xd:doc>
     54    <xsl:template name="getData">
     55        <xsl:param name="key" select="$data_key"></xsl:param>
     56        <xsl:param name="id" select="$id"></xsl:param>
     57        <xsl:param name="cache" select="$cache"></xsl:param>
     58       
     59        <xsl:variable name="cache_path"  select="my:cachePath($key,$id)" />
     60        <!--<xsl:message>document-uri1: <xsl:value-of select="document-uri(/)"></xsl:value-of></xsl:message>-->
     61        <xsl:variable name="result" select="my:getData($key,$id,$cache)"></xsl:variable>
     62       
     63        <xsl:message><xsl:value-of select="$cache_path" /> available <xsl:value-of select="doc-available($cache_path)" /></xsl:message>
     64<!--        <xsl:message>cachePath: <xsl:value-of select="$cache_path"></xsl:value-of></xsl:message>-->
     65            <xsl:if test="$cache='refresh' and not(doc-available($cache_path))">
     66                     
     67             <xsl:result-document href="{$cache_path}" format="xml" >
     68                 <xsl:copy-of select="$result" />
     69             </xsl:result-document>
     70            </xsl:if>
     71       
     72       
     73        <!-- only output to main result if cache is use (otherwise only write out to cache) -->
     74        <xsl:if test="$cache='use' and not(doc-available($cache_path))">
     75            <xsl:copy-of select="$result"></xsl:copy-of>
     76        </xsl:if>
     77       
     78    </xsl:template>
     79   
     80 <!--
     81         -->
     82    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
     83        <xd:desc>
     84            <xd:p>serves individual datasets (cmd-profiles, dcr-termsets...)</xd:p>           
     85            <xd:p>primitive cache mechanism -
     86                if data of given key is already stored, serve it,
     87                otherwise build a new (but don't store in cache - within this function)               
     88             </xd:p>
     89        </xd:desc>
     90        <xd:param name="key">dataset key</xd:param>
     91        <xd:param name="id">optional profile or component identifier to retrieve a single profile or component</xd:param>
     92        <xd:param name="cache">recognized value: use beware of the param-value in recursive calls (currently 'use' is fixed for deeper calls)</xd:param>
     93    </xd:doc>
    4294  <xsl:function name="my:getData">
    4395        <xsl:param name="key"></xsl:param>
    44         <xsl:param name="cache"></xsl:param>
    45         
    46       <xsl:variable name="cached_data_file" select="concat($cache_dir, if (ends-with($cache_dir,'/') or ends-with($cache_dir,'\')) then '' else '/',
    47                                                             $key, '.xml')"></xsl:variable>
     96        <xsl:param name="id"></xsl:param>
     97       <xsl:param name="cache"></xsl:param>
     98       
     99      <xsl:variable name="cached_data_file" select="my:cachePath($key,$id)"></xsl:variable>
    48100                <xsl:message>cache: <xsl:value-of select="$cache" /></xsl:message>
    49101                <xsl:message><xsl:value-of select="$cached_data_file" /> available <xsl:value-of select="doc-available($cached_data_file)" /></xsl:message>
     102     
    50103        <xsl:choose>
    51104            <xsl:when test="doc-available($cached_data_file) and $cache='use'">
     
    57110                <xsl:copy-of select="document(my:config('cmd-profiles','url'))" />               
    58111            </xsl:when>
     112            <xsl:when test="$key='profiles' or $key='component'">
     113                <xsl:copy-of select="my:getRawData($key, $id)" />               
     114            </xsl:when>
    59115            <xsl:when test="$key='cmd-resolved'">
    60116                <xsl:apply-templates select="my:getData('cmd-profiles-raw')" mode="include" />               
     
    95151            </xsl:otherwise>
    96152        </xsl:choose>   
     153     
     154   
    97155    </xsl:function>
    98156   
     
    100158    <xsl:function name="my:getData">
    101159        <xsl:param name="key"></xsl:param>
    102         <xsl:copy-of select="my:getData($key,$cache)"></xsl:copy-of>
    103     </xsl:function>
    104    
     160        <xsl:copy-of select="my:getData($key,'', $cache)"></xsl:copy-of>
     161    </xsl:function>
     162   
     163    <xsl:function name="my:getData">
     164        <xsl:param name="key"></xsl:param>
     165        <xsl:param name="id"></xsl:param>
     166        <xsl:copy-of select="my:getData($key,$id, $cache)"></xsl:copy-of>
     167    </xsl:function>
     168   
     169  <!-- get the raw xml for a specific piece of data (profile, component, later data category) from the source -->
     170    <xsl:function name="my:getRawData">
     171        <xsl:param name="key"></xsl:param>
     172        <xsl:param name="id"></xsl:param>
     173       
     174        <xsl:variable name="cached_data_file" select="my:cachePath($key,$id)"></xsl:variable>
     175<!--        <xsl:variable name="cached_data_file" select="concat($cache_dir, if (ends-with($cache_dir,'/') or ends-with($cache_dir,'\')) then '' else '/',
     176            $key, '/', my:normalize($id), '.xml')"></xsl:variable>-->
     177    <!--    <xsl:message>cache: <xsl:value-of select="$cache" /></xsl:message>
     178        <xsl:message><xsl:value-of select="$cached_data_file" /> available <xsl:value-of select="doc-available($cached_data_file)" /></xsl:message>
     179    -->   
     180       
     181        <!--<xsl:variable name="resolved_fn" select="concat($cmd_components_uri, @ComponentId)" />
     182        <xsl:variable name="compid" select="@ComponentId" />
     183       
     184        -->
     185        <xsl:variable name="resolved_uri" select="if (doc-available($cached_data_file)) then $cached_data_file else concat($cmd_profiles_uri , $id, '/xml')" />
     186       
     187        <xsl:message><xsl:value-of select="$key" />:</xsl:message>
     188        <xsl:message>resolved_uri:<xsl:value-of select="$resolved_uri" /></xsl:message>
     189        <xsl:if test="doc-available($resolved_uri)">
     190            <xsl:copy-of select="doc($resolved_uri)" />
     191                <!--            <xsl:apply-templates select="document($resolved_uri)" mode="include" />-->
     192        </xsl:if>
     193       
     194    </xsl:function>
     195   
     196
    105197<!-- load all dcrs from the configuration and transform them into Termsets
    106198       (uses mode=dcr-templates in dcr_rdf2terms.xsl)       -->
     
    117209    </xsl:template>
    118210
    119        
    120 <!-- invert the profiles-termsets + match with data from DCRs = create map datcat -> cmd-elements[] -->
     211    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
     212        <xd:desc>
     213            <xd:p>stores all profiles in the cache, by calling getData-template with $cache=refresh param</xd:p>
     214        </xd:desc>
     215    </xd:doc>
     216    <xsl:template name="load-profiles">
     217       
     218<!--        <xsl:variable name="profiles" select="document(my:config('cmd-profiles','url'))"></xsl:variable>-->
     219        <xsl:variable name="profiles" select="my:getData('cmd-profiles-raw')"></xsl:variable>
     220       
     221<!-- ???        <xsl:apply-templates select="$profiles" mode="include" />-->
     222       
     223        <xsl:for-each select="$profiles//profileDescription[id]">
     224            <xsl:call-template name="getData">
     225                <xsl:with-param name="key" select="'profiles'"></xsl:with-param>
     226                <xsl:with-param name="id" select="id"></xsl:with-param>
     227                <xsl:with-param name="cache" select="'refresh'"></xsl:with-param>
     228            </xsl:call-template>
     229        </xsl:for-each>
     230       
     231    </xsl:template>
     232       
     233    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
     234        <xd:desc>
     235            <xd:p>invert the profiles-termsets + match with data from DCRs = create map datcat -> cmd-elements[]</xd:p>
     236        </xd:desc>
     237    </xd:doc>
    121238<xsl:template name="dcr-cmd-map">
    122239    <Termset type="dcr-cmd-map" >       
     
    132249        </xsl:for-each-group>
    133250    </Termset>
    134 </xsl:template>                 
    135 
    136 <!-- list dcr-termsets + cmd (+ cmd-profiles)
    137 TODO: missing: isocat@langs, RR-sets -->   
     251</xsl:template>                   
     252
     253    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
     254        <xd:desc>
     255            <xd:p>list dcr-termsets + cmd (+ cmd-profiles)</xd:p>
     256            <xd:p>TODO: missing: isocat@langs, RR-sets</xd:p>
     257        </xd:desc>
     258    </xd:doc>
    138259<xsl:template name="termsets">   
    139260    <Termsets type="list">
     
    172293</xsl:template>
    173294
    174 <!-- load relation sets from the configuration and transform into Termset/Relation/Concepet
    175         (uses mode=rr-templates in dcr_rdf2terms.xsl)       -->
     295    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
     296        <xd:desc>
     297            <xd:p>load relation sets from the configuration and transform into Termset/Relation/Concepet
     298                (uses mode=rr-templates in dcr_rdf2terms.xsl) </xd:p>
     299        </xd:desc>
     300    </xd:doc>
    176301    <xsl:template name="load-rr-relations">
    177302        <Termsets type="rr">
     
    185310    </xsl:template>
    186311
    187 <!-- take the rr-relations and expand them with data from dcr-cmd-terms,
    188     to get rr-expanded terms      -->
     312    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
     313        <xd:desc>
     314            <xd:p>take the rr-relations and expand them with data from dcr-cmd-terms,
     315                to get rr-expanded terms</xd:p>
     316        </xd:desc>
     317    </xd:doc>
    189318    <xsl:template name="rr-terms">       
    190319            <xsl:apply-templates select="$rr-relations" mode="rr-expand" ></xsl:apply-templates>             
     
    197326        </xsl:copy>
    198327    </xsl:template>
    199     <!-- expand rr-concepts-->
     328   
     329    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
     330        <xd:desc>
     331            <xd:p>expand rr-concepts</xd:p>
     332        </xd:desc>
     333    </xd:doc>
    200334    <xsl:template match="Concept" mode="rr-expand">
    201335        <xsl:variable name="concept-id" select="@id" />               
     
    205339        </xsl:copy>       
    206340    </xsl:template>
    207    
    208 <!-- return a property of a Termset from the configuration. -->   
     341       
     342    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
     343        <xd:desc>
     344            <xd:p>return a property of a Termset from the configuration.</xd:p>
     345        </xd:desc>
     346        <xd:param name="key">key identifying the dataset item</xd:param>
     347        <xd:param name="property">element-name of the requested property</xd:param>
     348    </xd:doc>
    209349    <xsl:function name="my:config">
    210350        <xsl:param name="key"></xsl:param>
Note: See TracChangeset for help on using the changeset viewer.