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

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