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

Last change on this file since 1074 was 1074, checked in by gaba, 13 years ago

paging- first version

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