source: MDService2/trunk/MDService2/src/xsl/mdset2view.xsl @ 1038

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

query - columns, autocolumns

File size: 10.3 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<xsl:stylesheet
3  version="2.0"
4  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5  xmlns:xs="http://www.w3.org/2001/XMLSchema"
6  xmlns:saxon="http://saxon.sf.net/"
7  xmlns:my="myFunctions" 
8>
9<!--
10<purpose> generate html view (probably various formats of a MDRepository response.</purpose>
11<params>
12<param name=""></param>
13</params>
14<history>      
15        <change on="2010-03-26" type="created" by="vr">based on cmdi/scripts/cmdinst2view.xsl</change> 
16</history>
17-->
18<xsl:import href="model2matrix.xsl"/>
19<xsl:import href="terms2view.xsl"/>
20
21<xsl:output method="html" />
22
23<xsl:include href="cmd_commons.xsl"/>
24
25
26<xsl:param name="startRecord">1</xsl:param>
27<xsl:param name="maximumRecords">50</xsl:param>
28
29<!-- <xsl:param name="format" select="'table'" /> table|list|detail -->
30<xsl:param name="cols" >Id,Title,Location
31<!--
32<col label="id">Id</col>
33<col label="id">idno</col>
34<col label="name">Name</col>
35<col label="title">Title</col>
36<col label="title">title</col>
37<col label="loc" >Location</col>
38<col label="loc" >pubPlace</col>
39<col label="lang" >language</col>
40
41 -->
42</xsl:param>
43
44<xsl:param name="mode" select="'html'" />
45<xsl:param name="title" >
46        <xsl:text>MDRecordSet </xsl:text>
47</xsl:param>
48
49<xsl:variable name="columns" >
50<xsl:message>COLUMNS: <xsl:value-of select="$cols" /><xsl:value-of select="string-length($cols)" /></xsl:message>
51        <xsl:variable name="colarray" select="tokenize($cols,',')"/>
52        <xsl:for-each select="$colarray" >
53                <col key="{.}" label="{replace(.,'^.*\.([^.]+)$','$1')}" xpath_osbolete="{replace(.,'\.','/')}" xpath="{my:index2xpath(.)}" />
54                <!-- if (contains(.,'.')) then reverse(.) else . -->
55        </xsl:for-each>
56        <xsl:if test="count($colarray)=0" >     
57                <xsl:copy-of select="$autocolumns"></xsl:copy-of>
58                <xsl:message>AUTOCOLUMNS: <xsl:copy-of select="$autocolumns" /><xsl:value-of select="count($autocolumns)" /></xsl:message>
59        </xsl:if>
60       
61</xsl:variable>
62
63<xsl:variable name="autocolumns" >
64        <xsl:variable name="precompute">
65                <xsl:for-each-group select="//Components//*[not(*)][exists(text())]" group-by="name()" >                       
66                        <xsl:sort select="sum(current-group()/string-length(string-join(text(),';')))" order="descending" />
67                        <!-- <xsl:message>precomputing: <xsl:value-of select="name()" />
68                                count: <xsl:value-of select="count(current-group())" /> sum:<xsl:value-of select="sum(current-group()/string-length(string-join(text(),';')))" /></xsl:message> -->
69                        <col key="{name()}" label="{name()}" xpath="{name()}" />
70                </xsl:for-each-group>
71        </xsl:variable>
72         <!-- <xsl:message>precompute: <xsl:copy-of select="$precompute" /><xsl:value-of select="count($precompute)" /></xsl:message>-->
73        <xsl:copy-of select="$precompute/*[position() &lt; $autocolumns_limit]"></xsl:copy-of> 
74</xsl:variable>
75
76<xsl:template name="continue-root" >
77
78<xsl:for-each select="searchRetrieveResponse" >
79        <xsl:call-template name="header" />
80        <xsl:choose>
81                                <xsl:when test="contains($format,'htmltable')">
82                                        <xsl:apply-templates select="records" mode="table" />
83                                </xsl:when>                             
84                                <xsl:when test="contains($format,'htmllist')">
85                                        <xsl:apply-templates select="records" mode="list" />
86                                </xsl:when>                             
87                                <xsl:when test="contains($format, 'htmldetail')">
88                                        <xsl:apply-templates select="records" mode="detail" />
89                                </xsl:when>
90                                <xsl:when test="contains($format, 'htmlpage')">
91                                        <xsl:apply-templates select="records" mode="detail" />
92                                </xsl:when>                             
93                                <xsl:otherwise>mdset2view: unrecognized format: <xsl:value-of select="$format" /></xsl:otherwise>
94        </xsl:choose>
95</xsl:for-each> 
96       
97</xsl:template> 
98       
99       
100<xsl:template match="*" >
101        <!-- <xsl:param name="lv" select="1" />-->
102        <!--<xsl:variable name="lv" select="count(ancestor::d)" /> -->
103        <xsl:if test="string-length(.//text()) &gt; 1" >
104                <xsl:variable name="has_text" >
105                        <xsl:choose>
106                                <xsl:when test="normalize-space(text())='Unspecified'">unspecified</xsl:when>
107                                <xsl:when test="not(normalize-space(text())='')">text</xsl:when>                               
108                                <xsl:otherwise>empty</xsl:otherwise>
109                        </xsl:choose>
110                       
111                </xsl:variable>
112                <div class="elem {$has_text}" ><span class="elem_name"><xsl:value-of select="name()" />:</span>
113                <span class="elem_value"><xsl:value-of select="text()" /></span>
114                        <xsl:apply-templates select="*" />                                     
115                </div> 
116        </xsl:if>
117</xsl:template> 
118       
119        <!--
120sample header: 
121<numberOfRecords>524</numberOfRecords>
122    <echoedSearchRetrieveRequest>//Title[contains(.,'an')] /db/cmdi-mirror/silang_data 1 50</echoedSearchRetrieveRequest>
123    <diagnostics>50</diagnostics>
124    -->
125<xsl:template name="header">
126        <div class="result-header" >
127        <xsl:attribute name="max_value"><xsl:value-of select="numberOfRecords" /></xsl:attribute>
128        <xsl:variable name="cnt_hits" select="number(diagnostics)" />
129       
130        <span class="label" >hits: </span><span class="value hilight"><xsl:value-of select="numberOfRecords" /></span>;
131        <span class="label" >from:</span><span><input type="text" class="value start_record paging-input"><xsl:attribute name="value">
132    <xsl:value-of select="$startRecord"/>
133  </xsl:attribute>
134        </input></span>
135        <span class="label" >max:</span><span><input type="text" class="value maximum_records paging-input" ><xsl:attribute name="value">
136    <xsl:value-of select="if(number($cnt_hits) &lt; number($maximumRecords)) then $cnt_hits else $maximumRecords"/>   
137  </xsl:attribute></input></span>
138  <span class="cmd cmd_reload" />
139<!--    <button class="reload">reload</button>-->
140        <span class="cmd cmd_prev">     
141        <xsl:choose>
142                <xsl:when test="$startRecord = '1'">
143                        <xsl:attribute name="disabled">disabled</xsl:attribute>
144                </xsl:when>
145                </xsl:choose>
146        </span>
147        <span class="cmd cmd_next">     
148        <xsl:choose>
149                <xsl:when test="$maximumRecords &gt; numberOfRecords or $maximumRecords = numberOfRecords">
150                        <xsl:attribute name="disabled">disabled</xsl:attribute>
151                </xsl:when>
152                </xsl:choose>
153        </span>
154        <span class="cmd cmd_columns" />       
155        <div class='ui-context-dialog ui-widget-content columns-wrapper'>
156                <div class='query-columns'>
157                                <xsl:call-template name="columns" />
158                </div><span class='cmd cmd_del'></span><span class="cmd cmd_reload" /></div>
159    </div>
160       <div class="note" ><span class="label" >echo: </span><span class="value"><xsl:value-of select="echoedSearchRetrieveRequest" /></span>;<span class="label" >duration: </span><span class="value"><xsl:value-of select="extraResponseData/duration" /></span>;</div>
161</xsl:template> 
162
163<xsl:template name="columns">   
164                <ul class="query-columnslist">
165                        <xsl:for-each select="$columns/*">
166                                <li><xsl:value-of select="@label"/><span class='cmd cmd_del'/></li>
167                        </xsl:for-each>
168                </ul>
169        <xsl:if test="extraResponseData/usedProfiles" >
170                <span class="label">used profiles in whole result</span>
171                <ul>
172                        <xsl:for-each select="extraResponseData/usedProfiles/profile" >
173                                <li><a href="{@id}" ><xsl:value-of select="@name"/></a><span class="note">|<xsl:value-of select="@count"/>|</span></li>
174                        </xsl:for-each>
175                </ul>
176        </xsl:if>
177        <xsl:variable name="resultSummary" >
178               
179                <!-- wrap in <Terms> to make digestible for model2matrix -->
180                <xsl:variable name="terms" >
181                        <Terms>
182                        <!-- if already provided by mdrepo, use that, otherwise DIY -->         
183                        <xsl:choose>
184                                <xsl:when test="extraResponseData/resultSummary"><xsl:copy-of select="extraResponseData/resultSummary/Term" /></xsl:when>
185                                <xsl:otherwise>
186                                <!-- TODO! -->
187                                </xsl:otherwise>
188                        </xsl:choose>
189                        </Terms>
190                </xsl:variable>
191                <xsl:apply-templates select="$terms" mode="matrix" />
192        </xsl:variable>         
193        <span class="label">structure summary of shown result</span>
194        <xsl:message><xsl:value-of select="$resultSummary/*/name()" /> </xsl:message>
195                <ul class="treeview">
196                        <xsl:for-each select="$resultSummary" >
197                                <!--  calling template in terms2view.xsl -->
198                                <xsl:call-template name="table" >
199                                </xsl:call-template>
200                        </xsl:for-each>
201                <!--    <xsl:apply-templates select="$resultSummary/*/Term" mode="list" >
202                                <xsl:with-param name="options" select="'all'"></xsl:with-param>
203                        </xsl:apply-templates> -->                     
204                </ul>   
205<!--            <xsl:for-each select="$resultSummary" >
206                                <li><a href="{@id}" ><xsl:value-of select="@name"/></a><span class="note">|<xsl:value-of select="@count"/>|</span></li>
207                        </xsl:for-each>
208         -->                   
209       
210</xsl:template>
211
212<xsl:template match="records" mode="table">
213   
214        <table class="show">           
215                <thead><tr><th>pos</th>
216                <!--
217                         <xsl:for-each select="$cols/col" >
218                        <xsl:for-each select="distinct-values($cols/col/@label)" >
219                                        <th><xsl:value-of select="." /></th>
220                        </xsl:for-each>         
221                 -->
222                        <xsl:for-each select="$columns/*">
223                                <th title="{@key}" ><xsl:value-of select="@label"/></th>
224                        </xsl:for-each>                         
225                </tr></thead>
226                <tbody>         
227                        <xsl:apply-templates select="CMD" mode="table" />                       
228                </tbody>
229        </table>
230
231</xsl:template>
232
233<xsl:template match="CMD" mode="table">
234                <tr>
235                <td>
236                        <xsl:choose>
237                                <xsl:when test="exists(.//MdSelfLink)" >
238                                <a class="internal" href="{concat('record/htmldetail/', my:encodePID(.//MdSelfLink))}" >
239                                                <xsl:value-of select="position()" />
240                                </a>
241                                <span class="cmd cmd_detail" ></span>                           
242                                <span class="cmd cmd_save" ></span>                                             
243                                </xsl:when>
244                                <xsl:otherwise><xsl:value-of select="position()" /></xsl:otherwise>
245                        </xsl:choose>
246                </td>
247                <xsl:variable name="curr_cmd" select="." />
248                <!-- <xsl:for-each select="$cols/col" >
249                                        <td ><xsl:value-of select="$curr_cmd//*[name()=current()]" /></td>
250                                <xsl:for-each select="distinct-values($cols/col/@label)" >
251                                        <td >
252                                         <xsl:value-of select="$curr_cmd//*[name()=current()]" /> 
253                                                 <xsl:for-each select="$cols/col[@label=current()]" >
254                                                 <xsl:variable name="curr_col_xpath" select="text()" />
255                                                       
256                                                        <xsl:message><xsl:value-of select="$curr_col_xpath" /></xsl:message>
257                                                 
258                                                        <xsl:for-each select="$curr_cmd" >
259                                                                        <xsl:value-of select="saxon:evaluate(concat('.//', $curr_col_xpath))" />
260                                                        </xsl:for-each>
261                                                </xsl:for-each>
262                                        </td>
263                                </xsl:for-each>
264                  -->
265
266                        <xsl:for-each select="$columns/*">
267                        <!-- <td ><xsl:value-of select="$curr_cmd//*[name()=current()]" /></td> -->
268                        <xsl:message><xsl:copy-of select="."></xsl:copy-of> </xsl:message>
269                                 <xsl:variable name="curr_col_xpath" select="@xpath" />
270                        <td>                   
271                                <xsl:for-each select="$curr_cmd">
272                                        <xsl:call-template name="format-field" >
273                                                <xsl:with-param name="elems" select="saxon:evaluate(concat('.//', $curr_col_xpath))" />
274                                        </xsl:call-template>                                   
275                               
276                                </xsl:for-each>
277                        </td>
278                        </xsl:for-each>
279                </tr>                                                                   
280</xsl:template>
281
282
283</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.