source: MDService2/trunk/MDService2/src/xsl/cmd_functions.xsl @ 1029

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

changes to columns, terms (unfinished) ; .ui-context-dialog

File size: 9.4 KB
Line 
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<!--
6<purpose>generic functions for MDService2</purpose>
7<history>
8        <change on="2010-12-29" type="created" by="vr">extracted from cmd_commons.xsl</change>
9</history>
10
11-->
12<xsl:include href="params.xsl"/>
13
14<!-- <xsl:param name="mode" select="'html'" /> -->
15
16<xsl:param name="dict_file" select="'dict.xml'" />
17<xsl:variable name="dict" select="document($dict_file)" />
18<xsl:variable name="terms_setup" select="document($terms_setup_uri)" />
19<xsl:variable name="terms_flat" select="document($terms_flat_uri)" />
20
21
22<!-- params for include-processing
23moved to params.xsl
24        <xsl:param name="components_uri" select="'http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/components/'" />         
25        <xsl:param name="prefix_replace" select="'file:///C:/Users/master/3lingua/clarin/CMDI/_repo2/metadata/toolkit/components'" />
26-->
27
28<!--  should be obsoleted by model2matrix.xsl
29but it is not..
30-->
31<xsl:variable name="term_matrix" >
32               
33                <xsl:for-each select="//CMD_Element" >
34                                        <xsl:variable name="context" select="my:context(.)" >
35                                        </xsl:variable>
36                        <Term  elem="{@name}" datcat="{@ConceptLink}" profile="{ancestor::profileDescription[1]/name}" 
37                                                        parent="{ancestor::CMD_Component[1]/@name}"  context="{$context}" >
38                                                                <xsl:copy-of select="." />
39                        </Term>
40                </xsl:for-each>
41       
42</xsl:variable>
43<!--
44<xsl:template match="Term" mode="matrix" >
45               
46                <xsl:for-each select=".//Term" >
47                        <xsl:variable name="context" select="my:context(.)" >
48                                        </xsl:variable>
49                        <Term  elem="{@name}" datcat="{my:term2datcat(@name)}" profile="{ancestor::profileDescription[1]/name}"
50                                                        parent="{ancestor::Term[1]/@name}"  context="{$context}" >
51                                                                <xsl:copy-of select="." />
52                        </Term>
53                </xsl:for-each>
54       
55</xsl:template>
56
57 -->
58 
59<xsl:function name="my:profilematrix" >
60    <xsl:param name="term"/>
61   
62    <xsl:variable name="profile" select="my:profile($term,true())" />
63    <Terms name="{$profile/name}"  id="{$profile/id}">
64        <xsl:for-each select="$profile//CMD_Component|$profile//CMD_Element" >
65                                        <xsl:variable name="context" select="my:context(.)" />                                         
66                                       
67                                        <xsl:variable name="id"  >
68                                                        <xsl:choose>
69                                                                <xsl:when test="@ComponentId">
70                                                                        <xsl:value-of select="@ComponentId" />
71                                                                </xsl:when>
72                                                                <xsl:otherwise>
73                                                                        <xsl:value-of select="ancestor::CMD_Component[@ComponentId][1]/@ComponentId" /><xsl:text>#</xsl:text>
74                                                                        <xsl:for-each select="ancestor::CMD_Component[not(descendant-or-self::CMD_Component[@ComponentId])]" >
75                                                                        <xsl:value-of select="@name" />.</xsl:for-each><xsl:value-of select="@name" />
76                                                                </xsl:otherwise>
77                                                        </xsl:choose>                                                   
78                                        </xsl:variable>
79                        <Term  name="{@name}" datcat="{@ConceptLink}" id="{$id}" 
80                                                        parent="{ancestor::CMD_Component[1]/@name}" context="{$context}" 
81                                                        >
82                                                                <!--  <xsl:copy-of select="." /> -->
83                        </Term>
84                </xsl:for-each>
85        </Terms>
86   
87</xsl:function>
88
89<xsl:function name="my:profile" >
90    <xsl:param name="term"/>
91    <xsl:param name="resolve" /> <!--  true|false-->
92   
93    <xsl:message>cmdprofiles_uri: <xsl:value-of select="$cmdprofiles_uri" /></xsl:message>
94   
95    <xsl:variable name="profile" select="doc($cmdprofiles_uri)//profileDescription[name=$term]" />
96   
97    <xsl:choose>
98      <xsl:when test="$resolve=true()">
99                <xsl:apply-templates select="$profile" mode="include" />
100      </xsl:when>
101      <xsl:otherwise>
102                <xsl:copy-of select="$profile" />
103      </xsl:otherwise>
104    </xsl:choose>
105   
106       
107</xsl:function>
108
109<!--
110<xsl:function name="my:term2datcat">
111    <xsl:param name="term"/>                             
112    <xsl:value-of select="$term_matrix/*[@elem=$term]/@datcat" />                                       
113</xsl:function>
114-->
115
116        <xsl:function name="my:dict">
117     <xsl:param name="key"/>                             
118     <xsl:value-of select="my:dict($key, $key)" />                                     
119   </xsl:function>
120   
121        <xsl:function name="my:dict">
122     <xsl:param name="key"/>                           
123     <xsl:param name="fallback"/>     
124                <xsl:choose>
125                        <xsl:when test="$dict/list/item[@key=$key]" >
126                                <xsl:value-of select="$dict/list/item[@key=$key]" />
127                        </xsl:when>                     
128                        <xsl:when test="$dict/list/item[.=$key]" >
129                                <xsl:value-of select="$dict/list/item[.=$key]/@key" />
130                        </xsl:when>                     
131                        <xsl:otherwise>
132                        <xsl:value-of select="$fallback" />
133                        </xsl:otherwise>
134                </xsl:choose>
135   </xsl:function>
136               
137        <xsl:function name="my:extractID" >             
138                <xsl:param name="uri" />
139               
140                <xsl:choose>
141                        <xsl:when test="contains($uri,$isocat_base_uri)">
142                                <xsl:value-of select="substring-after($uri, $isocat_base_uri)" />
143                        </xsl:when>
144                        <xsl:when test="contains($uri,$components_id_prefix)">
145                        <!--   <xsl:value-of select="substring-after($uri,$components_id_prefix)" /> -->
146                                <xsl:value-of select="substring-after($uri, $components_id_prefix)" />
147                        </xsl:when>
148                        <xsl:otherwise><xsl:value-of select="$uri" /></xsl:otherwise>
149                </xsl:choose>           
150        </xsl:function>
151       
152       
153        <xsl:function name="my:shortURL" >
154                <xsl:param name="url" />
155                <!--   <xsl:value-of select="replace($url, 'http://www.isocat.org/datcat/','isocat:')" /> -->
156                <xsl:variable name="matching_termset"  select="$terms_setup/Termsets/Termset[starts-with($url,@url_prefix)]" />
157                 <xsl:message>shortURL: <xsl:copy-of select="$matching_termset" />:: <xsl:value-of select="$matching_termset[1]/@url_prefix" />
158                                <xsl:copy-of select="$url" /> 
159                </xsl:message>                 
160                <xsl:value-of select="if ($matching_termset/@url_prefix and $matching_termset/@url_prefix!='' and $url!='') then replace($url, $matching_termset[1]/@url_prefix, concat(string-join($matching_termset/@id,','),':')) else $url" />             
161        </xsl:function> 
162       
163        <!--  rewrite specific URLs (linking to target services) to redirect them locally (via MDService)
164        should work for: dcif:dataCategory@pid, pcompone
165        -->
166        <xsl:function name="my:rewriteURL" >
167                <xsl:param name="url" />       
168                <xsl:choose>
169                                <xsl:when test="contains($url,$isocat_base_uri)">
170                                                <xsl:value-of select="replace($url, $isocat_uri_match, $isocat_uri_replace)" />
171                                </xsl:when>     
172                                <xsl:otherwise><xsl:value-of select="concat($detail_complist_prefix, my:extractID($url))" /></xsl:otherwise>
173                        </xsl:choose>           
174        </xsl:function> 
175               
176                <!--  previously known as comppath -->
177        <xsl:function name="my:context" >
178                <xsl:param name="child" />
179                <xsl:variable name="collect" >
180                                <xsl:for-each select="$child/ancestor::CMD_Component|$child/ancestor::Term" >
181                                                <xsl:value-of select="@name" />.</xsl:for-each><xsl:value-of select="$child/@name" />
182                </xsl:variable>
183                <xsl:value-of select="$collect" />     
184        </xsl:function> 
185
186        <xsl:function name="my:encodePID" >
187                <xsl:param name="pid" />                               
188                <xsl:value-of select="encode-for-uri(replace(replace($pid,'/','%2F'),'\.','%2E'))" />   
189        </xsl:function> 
190   
191<!--
192<xsl:function name="my:numberFormat">
193<xsl:param name="unit" />
194        <xsl:choose>
195                <xsl:when test="$unit='count' or $unit='count-distinct'" ><xsl:value-of select="$format_count" /></xsl:when>
196                <xsl:when test="$unit='kg'" ><xsl:value-of select="$format_kg" /></xsl:when>
197                <xsl:when test="$unit='t'" ><xsl:value-of select="$format_t" /></xsl:when>
198                <xsl:when test="$unit='m3'" ><xsl:value-of select="$format_m3" /></xsl:when>
199                <xsl:when test="$unit='per' or $unit='percent'" ><xsl:value-of select="$format_per" /></xsl:when>
200                <xsl:when test="$unit='sum'" ><xsl:value-of select="$format_kg" /></xsl:when>
201                <xsl:otherwise><xsl:value-of select="$format_default" /></xsl:otherwise>               
202        </xsl:choose>
203</xsl:function>
204-->
205
206<xsl:function name="my:index2xpath">
207<xsl:param name="p_ix" />
208
209        <xsl:variable name="ix_string" select="replace($p_ix,'_',' ')" />
210
211        <xsl:variable name="ix_resolved" >
212                <xsl:choose>
213                                <xsl:when test="contains($ix_string,':')">
214                                        <xsl:variable name="prefix" select="substring-before($ix_string,':')" />                               
215                                        <xsl:variable name="termset" select="$terms_setup/Termsets/Termset[@id=$prefix]" />                             
216                                       
217                                        <xsl:message>index2xpath.matching_termset:<xsl:copy-of select="$termset"/>
218                                                                        ix_string:<xsl:value-of select="$ix_string"/>
219                                        </xsl:message>
220                                        <xsl:choose>
221                                        <!-- magic happening here  -->
222                                                <xsl:when test="$termset[@type='dcr' or @type='rr']">
223                                                        <xsl:variable name="expanded_context" select="$terms_flat//context[@path=$ix_string]"></xsl:variable>
224                                                                <xsl:variable name="expanded_query" >
225                                                                        <xsl:text>(</xsl:text>
226                                                                        <xsl:for-each select="distinct-values($expanded_context//context[@elem]/@path)">
227                                                                                <xsl:variable name="prefix" select="substring-before(.,':')" />
228                                                                                <xsl:variable name="termset" select="$terms_setup/Termsets/Termset[@id=$prefix]" />                                                                     
229                                                                                <xsl:value-of select="concat($termset/@name,'//',substring-after(.,':'))" />
230                                                                                <xsl:if test="position()!=last()"><xsl:text>|</xsl:text></xsl:if>
231                                                                        </xsl:for-each>
232                                                                        <xsl:text>)</xsl:text>
233                                                                </xsl:variable>
234                                                                <xsl:message>expanded-context:<xsl:value-of select="$expanded_query" /></xsl:message>
235                                                        <xsl:value-of select="$expanded_query" />
236                                                </xsl:when>
237                                                <xsl:otherwise>
238                                                        <xsl:value-of select="concat($termset/@name,'//',substring-after($ix_string,':'))" />   
239                                                </xsl:otherwise>
240                                        </xsl:choose>
241                                         
242                                </xsl:when>
243                                <xsl:otherwise><xsl:value-of select="$ix_string" />
244                                </xsl:otherwise>
245                        </xsl:choose>
246                </xsl:variable>
247        <xsl:value-of select="translate($ix_resolved, '.', '/')" ></xsl:value-of>       
248</xsl:function>
249
250</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.