source: MDService2/trunk/MDService2/src/xsl/terms2view.xsl @ 1076

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

reduced logging messages,
changes to CQL-handling in js and XCQL2Xpath-mapping;
reworked docs, introduced example queries

File size: 16.9 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<xsl:stylesheet  version="2.0"
3  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4  xmlns:xs="http://www.w3.org/2001/XMLSchema"    xmlns:my="myFunctions"
5>
6<!--
7<purpose> generate all the views for terms-matrix</purpose>
8<params>
9<param name=""></param>
10</params>
11<history>
12        <change on="2010-10-11" type="created" by="vr">from model2view.xsl</change>             
13</history>
14-->
15<xsl:import href="cmd_commons.xsl"/>
16
17<!--  <xsl:output method="xml" />  --> 
18
19<!-- <xsl:param name="size_lowerbound">0</xsl:param>
20<xsl:param name="max_depth">0</xsl:param>
21<xsl:param name="freq_limit">20</xsl:param>
22<xsl:param name="show">file</xsl:param> 
23<xsl:param name="detail_uri_prefix" select="'?q='"/> 
24<xsl:param name="mode" select="'htmldiv'" /> -->
25
26<xsl:param name="sort">x</xsl:param> <!-- s=size|n=name|t=time|x=default -->
27<xsl:param name="name_col_width" >50%</xsl:param>
28<xsl:param name="title" select="'Terms'" />
29
30<xsl:decimal-format name="european" decimal-separator=',' grouping-separator='.' />
31
32<xsl:template name="continue-root">
33        <div>   
34                <xsl:choose>                   
35                 <xsl:when test="$format='terms2htmltable'" >
36                        <xsl:call-template name="header"/>   
37                        <xsl:call-template name="table"/>
38                           
39                </xsl:when>
40                <xsl:when test="$format='terms2htmlpage'" >
41                        <xsl:call-template name="header"/>
42                            <div id="terms-matrix">
43                                <xsl:apply-templates mode="terms-tree" />                               
44                                </div>                                                                                         
45                        </xsl:when>                             
46                <xsl:when test="$format='terms2htmllist'" >                     
47                        <xsl:apply-templates select=".//Termset" mode="list"/>   
48                </xsl:when>
49                <xsl:when test="$format='terms2flat'" >                                                                 
50                                <xsl:call-template name="terms-flat"/>                                                     
51                </xsl:when> 
52                <xsl:when test="$format='terms2autocomplete'" >
53                        <xsl:variable name="terms_flat" >                                       
54                                <xsl:call-template name="terms-flat"/>
55                        </xsl:variable>                         
56                        <xsl:apply-templates select="$terms_flat" mode="autocomplete"/>                             
57                </xsl:when> 
58                <xsl:when test="$format='terms2htmlselect'" >
59                                        <select id="terms-select">             
60                                                        <xsl:apply-templates select=".//Termset" mode="select"/>                                                       
61                                        </select>
62                                        <a href="{my:formURL('terms','htmlpage','all')}">overview</a>                                                           
63                        </xsl:when>
64                <xsl:otherwise>
65                        <xsl:apply-templates select=".//Termset" mode="list"/>   
66                </xsl:otherwise>
67         </xsl:choose>
68    </div>       
69       
70</xsl:template> 
71
72
73<xsl:template name="header">
74        <h2>MDService Terms</h2>       
75        <table>
76                <tbody>
77                        <tr><td>count Termsets</td><td align="right"><xsl:value-of select="count(//Termset)"/></td></tr>                                                                                               
78                </tbody>
79        </table>
80</xsl:template>         
81
82<xsl:template name="table">
83        <table>
84                <caption>Terms Usage</caption>
85                <thead><tr><th>name/path</th><th>count elems</th><th>count text</th><th>count distinct text</th>
86                <th>context</th><th>corresp comp</th><th>datcat</th></tr></thead>
87                <tbody>         
88                        <xsl:apply-templates select="*" mode="table" />                 
89                </tbody>
90        </table>
91
92</xsl:template>
93
94<xsl:template match="Term" mode="table">
95                                <tr><td>
96                                <!-- <a href="?q={@path}" > -->
97                                        <span class="cmd cmd_add">      </span>
98                                        <span class="column-elem"><xsl:value-of select="translate(@path,'/','.')"/></span>
99                                        <!-- </a> -->
100                                        </td>
101                                                <td align="right"><xsl:value-of select="@count"/></td>
102                                                <td align="right"><xsl:value-of select="@count_text"/></td>                                             
103                                                <td align="right"><xsl:value-of select="@count_distinct_text"/></td>                                           
104                                                <td><xsl:value-of select="@context"/></td>
105                                                <td><xsl:value-of select="@corresponding_component"/></td>
106                                                <td><xsl:value-of select="@datcat"/></td>
107                                               
108                                </tr>                                                   
109                                <xsl:apply-templates select="*" mode="table" />                 
110</xsl:template>
111
112<xsl:template match="Termset" mode="list">
113        <div class="terms">     
114                <span class="detail-caller"><xsl:value-of select="@name"/></span>
115                <xsl:call-template name="attr-detail-div" />
116                <!--  format:<xsl:value-of select="$format" /> -->
117                <!--<xsl:variable name="translated_term" select="translate(replace(/*/Term[1]/@path,'//',''),'/','.')" />
118                 <input id="query_terms" value="{$translated_term}" /> -->             
119                <ul class="treeview">
120                        <xsl:apply-templates select="Term[@path]" mode="list" />                       
121                </ul>   
122        </div>
123</xsl:template>
124
125<xsl:template match="Term" mode="list" >
126<xsl:param name="options" select="''" />
127                <!--  <xsl:variable name="translated_path" select="translate(replace(@path,'//',''),'/','.')" /> -->
128                <!--  filter out empty datcats  -->
129                <xsl:if test="@elem or descendant::*[@elem] or $options='all'" >
130                                <li><div class="cmds-elem-plus"><span class="detail-caller"><!-- <a href="{concat($detail_model_prefix,@context)}" >  -->
131                                        <xsl:value-of select="@path"/></span>
132                                        <span class="note">|<xsl:value-of select="@count"/>|</span>
133                                        <!--  /<xsl:value-of select="@count_text"/>/<xsl:value-of select="@count_distinct_text"/> -->                                   
134                                        <span class="data comppath"><xsl:value-of select="@path" /></span>               
135                                        <span class="cmd cmd_filter"><xsl:text> </xsl:text></span>
136                                        <span class="cmd cmd_detail" ><xsl:text> </xsl:text></span>
137                                        <span class="cmd cmd_columns" ><xsl:text> </xsl:text></span>
138                                        <xsl:call-template name="attr-detail-div" />
139                                                <!--  <div class="detail">
140                                                        <xsl:for-each select="@*" >
141                                                                <div class="cmds-elem-prop"><span class="label"><xsl:value-of select="name()" />: </span>
142                                                                        <span class="value"><xsl:value-of select="." /></span></div>
143                                                        </xsl:for-each>
144                                                </div> -->
145                                        </div>
146                                        <ul><xsl:apply-templates select="Term" mode="list" >
147                                                        <xsl:with-param name="options" select="$options"></xsl:with-param>
148                                                </xsl:apply-templates>
149                                        </ul>                           
150                                </li>   
151                </xsl:if>               
152</xsl:template>
153
154
155<!--
156both Termsets and Termset can be root level
157sample
158  <Termsets xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="myFunctions">
159   <Termset name="TextCorpusProfile" colls="root" depth="8" created="2011-01-03T19:59:21.366+01:00" type="model" id="tcp" url="" format="terms|cmdrepo">
160 -->
161<xsl:template match="Termsets|Termset" mode="terms-tree" >
162<xsl:param name="parentid" select="'x'" />
163<xsl:param name="lv" select="0" />
164       
165        <xsl:variable name="xid" select="concat($parentid,position())" />
166       
167        <!--  special handling for datcat and relcat termsets -->
168        <xsl:variable name="self" >
169                <xsl:if test="@type='dcr' or @type='rr'">
170                        <tr id="{$xid}" >               
171                                <td class="treecol" ><xsl:value-of select="@name" /></td>
172                                <td colspan="3" ></td>
173                     </tr>
174                </xsl:if>
175        </xsl:variable>
176       
177        <xsl:variable name="children" >
178                <xsl:apply-templates select="*" mode="terms-tree">                     
179                        <xsl:sort order="ascending" select="@name" />
180                        <xsl:with-param name="parentid" select="$xid" />
181                        <xsl:with-param name="lv" select="$lv+1" />                                                                                                                                     
182                </xsl:apply-templates>
183        </xsl:variable>
184       
185       
186        <xsl:choose>
187                <xsl:when test="$lv=0" >
188                        <table class="terms-tree show" >
189                                <thead class="ui-widget-header ui-state-default">
190                                <tr><th class="treecol" rowspan="2" >Name</th><th colspan="3">Count</th><th rowspan="2">Ratio</th></tr>
191                                <tr><th>Elems</th><th>Text</th><th>Distinct</th></tr>
192                                </thead>                                       
193                                <tbody>                                 
194                                        <xsl:copy-of select="$self" />
195                                        <xsl:copy-of select="$children" />
196                                </tbody>
197                        </table>
198                </xsl:when>
199                <xsl:otherwise>
200                                <xsl:copy-of select="$self" />
201                                <xsl:copy-of select="$children" />
202                </xsl:otherwise>       
203        </xsl:choose>
204                                       
205</xsl:template>                                 
206
207<xsl:template match="Term" mode="terms-tree" >
208<xsl:param name="parentid" select="'x'" />
209<xsl:param name="lv" select="0" />
210
211        <xsl:variable name="xid" >
212                <xsl:choose>
213                <xsl:when test="$lv=0"><xsl:value-of select="concat($parentid,position())" /></xsl:when>
214                <xsl:otherwise><xsl:value-of select="concat($parentid,'-', position())" /></xsl:otherwise>
215                </xsl:choose> 
216        </xsl:variable>
217       
218        <tr id="{$xid}" >
219          <xsl:if test="not(parent::Termset) or parent::Termset[@type='dcr' or @type='rr']" >
220                <xsl:attribute name="class" select="concat('child-of-',$parentid)" />
221          </xsl:if>
222                <td class="treecol" ><span class="cmd cmd_add" > </span>
223                                <span class="column-elem"><xsl:value-of select="@path" /></span></td>           
224                <td class="number"><xsl:value-of select="@count" /></td>
225                <!--  has children don't show the text-count - they are empty on non-terminals
226                        or better/experimental: show sum of the descendants
227                 -->
228                <td class="number"><!--   <xsl:if test="not(Term)"><xsl:value-of select="@count_text" /></xsl:if>-->
229                                <xsl:value-of select="format-number(if (not(Term)) then @count_text else sum(descendant::Term/@count_text),'#.##0','european' )" />
230                </td>
231                <td class="number">
232                        <xsl:if test="not(Term)"><a class="detail-caller" href="{my:formURL('values', 'htmllist', @path)}" ><xsl:value-of select="@count_distinct_text" /></a></xsl:if>
233                        <xsl:if test="Term"><xsl:value-of select="format-number(sum(descendant::Term/@count_distinct_text),'#.##0','european' )" /></xsl:if>
234                </td>
235                <td class="number">                     
236                        <xsl:if test="not(Term)">
237                                <xsl:variable name="count_elems" select="parent::Term/@count" />
238                                <xsl:variable name="inf_content_ratio" select="if (@count_distinct_text!=0) then (@count_text div $count_elems) * (@count_text div @count_distinct_text) else ''" />
239                                <xsl:value-of select="format-number(number($inf_content_ratio),'#.##0,00','european' )" />
240                        </xsl:if>
241                       
242                </td>
243                <!-- <td><xsl:value-of select="@path" />,<xsl:value-of select="@context" /></td>                       
244                <td><xsl:value-of select="@corresponding_component" />,<xsl:value-of select="@datcat" /></td>
245                 --> 
246     </tr> 
247                <xsl:if test="Term and ($lv&lt;$max_depth or $max_depth=0)">
248                       
249                                <xsl:choose>
250                                        <xsl:when test="$sort='s'">                             
251                                                <xsl:apply-templates select="Term" mode="terms-tree">
252                                                        <xsl:with-param name="parentid" select="$xid" />
253                                                        <xsl:with-param name="lv" select="$lv+1" />                     
254                                                                <xsl:sort order="descending" select="@count_distinct_text" data-type="number" />
255                                                </xsl:apply-templates>         
256                                        </xsl:when>
257                                        <xsl:when test="$sort='n'">                             
258                                        <xsl:apply-templates select="Term" mode="terms-tree">
259                                                        <xsl:with-param name="parentid" select="$xid" />
260                                                        <xsl:with-param name="lv" select="$lv+1" />
261                                                                <xsl:sort order="ascending" select="@name" />
262                                                </xsl:apply-templates>
263                                        </xsl:when>
264                                        <xsl:otherwise>
265                                        <!--  testwise: show only non empty Terms-->
266                                                <xsl:variable name="count_elems" select="@count" />
267                                                <xsl:apply-templates select="Term" mode="terms-tree">
268                                                                <xsl:sort select="if (@count_distinct_text!=0) then @count_text div $count_elems * (@count_text div @count_distinct_text) else 0"  order="descending" data-type="number" />
269                                                                <xsl:with-param name="parentid" select="$xid" />
270                                                                <xsl:with-param name="lv" select="$lv+1" />                                                                                                                     
271                                                </xsl:apply-templates>         
272                                        </xsl:otherwise>
273                                </xsl:choose>                                   
274                                       
275                </xsl:if>
276       
277</xsl:template>
278
279<xsl:template match="Termset" mode="select">
280       
281        <xsl:variable name="count" select="if (Term/@count) then concat(' |',Term/@count,'|') else '' " />
282        <xsl:variable name="call-value" select="if (@type='model' or not(@id)) then @name else @id" />
283        <option value="{$call-value}" ><xsl:value-of select="@name" /><xsl:value-of select="$count" /></option>                                 
284</xsl:template>
285
286<xsl:template match="Term" mode="autocomplete">
287        <xsl:copy>
288                <xsl:copy-of select="@*" />
289                <div class="term-contexts">
290                        <ul>
291                                <xsl:apply-templates mode="autocomplete" />
292                        </ul>
293                </div>
294        </xsl:copy>                                     
295</xsl:template>
296
297<xsl:template match="context" mode="autocomplete">
298        <li class="context cmds-elem-plus">
299                <span class="autocomplete-select-caller">
300                <!--
301                <a href="{concat($detail_model_prefix,@path)}" >
302                                <xsl:value-of select="@path"/></a>
303                 --> <xsl:value-of select="@path"/>
304                                </span>
305                                       
306                <xsl:call-template name="attr-detail-div" />
307                <ul>
308                        <xsl:apply-templates select="context" mode="autocomplete" />
309                </ul>
310        </li>                                   
311</xsl:template>
312
313
314<xsl:template name="terms-flat">
315       
316                <!--  group union of model, dcr and rr Terms --> 
317                <xsl:for-each-group select=".//Termset[@type='model']//Term | .//Termset[@type='dcr']/Term | .//Termset[@type='rr']//Term[@type='rel']" group-by="lower-case(@name)" >
318<!--            <xsl:for-each-group select="//Term[exists(@name)][parent::Termset]" group-by="lower-case(@name)" >-->
319                        <xsl:sort select="lower-case(@name)" />
320                        <!--  <xsl:if test="exists(current-group()[not(@type='datcat')])" >  -->
321                                <Term name="{@name}">
322                                        <xsl:for-each select="current-group()[not(@type='datcat' or @type='rel')]" >
323                                                <context><!-- <xsl:value-of select="ancestor::Termset[1]/@id" />:  -->
324                                                        <xsl:copy-of select="@*" />
325                                                <xsl:value-of select="@path" /></context>
326                                        </xsl:for-each>
327                                        <xsl:for-each select="current-group()[@type='datcat'][parent::Termset]" >
328                                                <xsl:variable name="datcat" select="." />
329                                                <context><xsl:copy-of select="@*" /><xsl:value-of select="ancestor::Termset[1]/@id" />:<xsl:value-of select="@name" />
330                                                <xsl:for-each-group select="$datcat/Term" group-by="@path" >
331                                                        <context><xsl:copy-of select="@*" /><xsl:copy-of select="@*" /><xsl:value-of select="@path" /></context>
332                                                </xsl:for-each-group>
333                                                </context>                             
334                                        </xsl:for-each>
335                                       
336                                        <xsl:for-each select="current-group()[@type='rel']" >
337                                                <xsl:variable name="datcat" select="if(parent::Term[@type='rel']) then parent::Term[@type='rel'] else . " />
338                                                                <context><xsl:copy-of select="@*" /><!-- <xsl:value-of select="ancestor::Termset[1]/@id" />: --><xsl:value-of select="@path" />
339<!--                                            <xsl:for-each-group select="$datcat//Term[@type!='datcat']" group-by="@path" >-->
340                                                               
341                                                        <xsl:for-each select="$datcat//Term[@type='datcat']" > <!-- [Term/@path] -->
342                                                                <context><xsl:copy-of select="@*" /><xsl:value-of select="@path" />
343                                                                <xsl:for-each-group select="Term[@path]" group-by="@path" >
344                                                                                <context><xsl:copy-of select="@*" /><xsl:value-of select="@path" /></context>
345                                                                </xsl:for-each-group>
346                                                                </context>
347                                                        </xsl:for-each>
348                                                </context>                             
349                                        </xsl:for-each>
350                                </Term>
351<!--                    </xsl:if>-->
352                </xsl:for-each-group>
353</xsl:template>
354
355<xsl:template name="list-datcats">
356        <xsl:param name="matrix" select="."></xsl:param>
357        <table>
358                <caption>DatCats |<xsl:value-of select="count(distinct-values($matrix//Term/@datcat))" />| <span class="note">* Click on numbers to see detail </span></caption>
359                                <thead><tr><th rowspan="2">id</th><th rowspan="2">name</th>
360                                        <th colspan="3" >count </th><th rowspan="2">elems</th></tr>
361                                        <tr><th>profile*</th><th >all*</th><th>elems</th> </tr>         </thead>
362                <tbody>         
363                                <xsl:for-each-group select="$matrix//Term" group-by="@datcat">
364                                        <xsl:sort select="lower-case(@datcat)" order="ascending"/>                                     
365                                                <tr><td valign="top"><xsl:value-of select="my:shortURL(@datcat)"/></td>
366                                                <td valign="top"><xsl:value-of select="my:rewriteURL(@datcat)"/></td>
367                                                <td valign="top" align="right">
368                                                        <span class="detail-caller" ><xsl:value-of select="count(distinct-values(current-group()/@name))"/></span>
369                                                        <div class="detail" >
370                                                                        <div class="box_heading"><xsl:value-of select="my:rewriteURL(@datcat)"/></div>
371                                                                        <ul>
372                                                                                <xsl:for-each select="distinct-values(current-group()/@name)" >
373                                                                                        <li><xsl:value-of select="." /></li>
374                                                                                </xsl:for-each>
375                                                                        </ul>
376                                                                </div>                                                 
377                                                </td>
378                                                <td valign="top" align="right">
379                                                        <span class="term_detail_caller" ><xsl:value-of select="count(current-group())"/></span>
380                                                        <div class="term_detail" >
381                                                                        <div class="box_heading"><xsl:value-of select="my:rewriteURL(@datcat)"/></div>
382                                                                        <ul>
383                                                                                <xsl:for-each-group select="current-group()" group-by="@name" >
384                                                                                        <li><xsl:value-of select="@name" />
385                                                                                                        <ul>
386                                                                                                                <xsl:for-each select="current-group()/@context" >
387                                                                                                                                <li><xsl:value-of select="." /></li>
388                                                                                                                </xsl:for-each>
389                                                                                                        </ul>
390                                                                                        </li>
391                                                                                </xsl:for-each-group>
392                                                                        </ul>
393                                                                </div>                                                 
394                                                </td>
395                                                <td valign="top" align="right"><xsl:value-of select="count(distinct-values(current-group()/@elem))"/></td>                                             
396                                                       
397                                                <td width="40%">                                               
398                                                                <xsl:for-each select="distinct-values(current-group()/@elem)">
399                                                                        <xsl:sort select="." />
400                                                                        <xsl:value-of select="."/>,
401                                                                </xsl:for-each>
402                                                </td>                                                                                           
403                                                </tr>                                   
404                                </xsl:for-each-group>
405                </tbody>
406        </table>
407        </xsl:template>
408
409<xsl:template name="callback-header" >
410        <style type="text/css">
411                .cmd_add {display:none}
412        </style>
413       
414        <script type="text/javascript" >
415                $(function(){
416                        $(".terms-tree").treeTable({initialState:"collapsed"});
417                        $("a.detail-caller").click(function(event) {
418                                        event.preventDefault();
419                                        $(this).after('<div class="ui-context-dialog cmds-ui-closable cmd cmd_get" ></div>');                                   
420                                        detail = $(this).parent().children('.ui-context-dialog');                               
421                                                                       
422                                        detail.load($(this).attr('href'), function(event) {
423                                                                $(this).removeClass('cmd_get cmd');
424                                                                handleUIBlock($(this).children('.cmds-ui-block'));
425                                                                addPaging($(this).children('.cmds-ui-block'));
426                                                                $(this).show();
427                                                                });
428                                });             
429                });
430        </script>
431
432</xsl:template>
433
434</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.