source: MDService2/branches/MDService_simple3/src/xsl/mdset2view.xsl @ 1555

Last change on this file since 1555 was 1555, checked in by gaba, 13 years ago
File size: 16.1 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  exclude-result-prefixes="saxon my xs" 
9>
10<!--
11<purpose> generate html view (probably various formats of a MDRepository response.</purpose>
12<params>
13<param name=""></param>
14</params>
15<history>      
16        <change on="2010-03-26" type="created" by="vr">based on cmdi/scripts/cmdinst2view.xsl</change> 
17</history>
18-->
19<xsl:import href="model2matrix.xsl"/>
20<xsl:import href="terms2view.xsl"/>
21
22<!--  method="xhtml" is saxon-specific! prevents  collapsing empty <script> tags, that makes browsers choke -->
23<xsl:output method="xhtml" media-type="application/xhtml+xml" indent="yes" encoding="UTF-8" 
24doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" /> 
25
26  <!--
27  if this is added  to the output-element, it terribly slows down requests with recordset being injected via document() function
28   (like: http://localhost:8080/MDService2/docs/htmlpagetest/queries2)
29  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> 
30  --> 
31
32<xsl:include href="cmd_commons.xsl"/>
33
34<!-- <xsl:param name="format" select="'table'" /> table|list|detail -->
35<xsl:param name="cols" >Id,Title,Location
36<!--
37<col label="id">Id</col>
38<col label="id">idno</col>
39<col label="name">Name</col>
40<col label="title">Title</col>
41<col label="title">title</col>
42<col label="loc" >Location</col>
43<col label="loc" >pubPlace</col>
44<col label="lang" >language</col>
45
46 -->
47</xsl:param>
48
49<xsl:param name="mode" select="'html'" />
50<xsl:param name="title" >
51        <xsl:text>MDRecordSet </xsl:text>
52</xsl:param>
53
54<xsl:variable name="columns" >
55<!-- <xsl:message>COLUMNS: <xsl:value-of select="$cols" /><xsl:value-of select="string-length($cols)" /></xsl:message>  -->
56        <xsl:variable name="colarray" select="tokenize($cols,',')"/>
57        <xsl:for-each select="$colarray" >
58                <col key="{.}" label="{replace(.,'^.*\.([^.]+)$','$1')}" xpath_osbolete="{replace(.,'\.','/')}" xpath="{my:index2xpath(.)}" />
59                <!-- if (contains(.,'.')) then reverse(.) else . -->
60        </xsl:for-each>
61        <xsl:if test="count($colarray)=0" >     
62                <xsl:copy-of select="$autocolumns"></xsl:copy-of>
63                <!-- <xsl:message>AUTOCOLUMNS: <xsl:copy-of select="$autocolumns" /><xsl:value-of select="count($autocolumns)" /></xsl:message> -->
64        </xsl:if>
65       
66</xsl:variable>
67
68<xsl:variable name="autocolumns" >
69        <xsl:variable name="precompute">
70                <xsl:for-each-group select="//Components//*[not(*)][exists(text())]" group-by="name()" >                       
71                        <xsl:sort select="sum(current-group()/string-length(string-join(text(),';')))" order="descending" />
72                        <!-- <xsl:message>precomputing: <xsl:value-of select="name()" />
73                                count: <xsl:value-of select="count(current-group())" /> sum:<xsl:value-of select="sum(current-group()/string-length(string-join(text(),';')))" /></xsl:message> -->
74                        <col key="{name()}" label="{name()}" xpath="{name()}" />
75                </xsl:for-each-group>
76        </xsl:variable>
77         <!-- <xsl:message>precompute: <xsl:copy-of select="$precompute" /><xsl:value-of select="count($precompute)" /></xsl:message>-->
78        <xsl:copy-of select="$precompute/*[position() &lt; $autocolumns_limit]"></xsl:copy-of> 
79</xsl:variable>
80
81<xsl:template name="continue-root" >
82
83<xsl:for-each select="searchRetrieveResponse" >
84<div>
85        <xsl:if test="not(contains($format, 'htmlsimple'))">
86                <xsl:call-template name="header" />
87        </xsl:if>
88        <xsl:call-template name="query-input" />
89       
90        <xsl:choose>
91                                <xsl:when test="contains($format,'htmltable')">
92                                        <xsl:apply-templates select="records" mode="table" />
93                                </xsl:when>                             
94                                <xsl:when test="contains($format,'htmllist')">
95                                        <xsl:apply-templates select="records" mode="list" />
96                                </xsl:when>                             
97                                <xsl:when test="contains($format, 'htmldetail')">
98                                        <xsl:apply-templates select="records" mode="detail" />
99                                </xsl:when>
100                                <xsl:when test="contains($format, 'htmlpage')">
101                                        <xsl:apply-templates select="records" mode="table" />
102                                </xsl:when>
103                                <xsl:when test="contains($format, 'htmlpagelist')">
104                                        <xsl:apply-templates select="records" mode="list" />
105                                </xsl:when>             
106                                <xsl:when test="contains($format, 'htmlsimple')">
107                                        <xsl:apply-templates select="records" mode="simple" />
108                                </xsl:when>             
109                                <xsl:otherwise>mdset2view: unrecognized format: <xsl:value-of select="$format" /></xsl:otherwise>
110        </xsl:choose>
111        </div>
112</xsl:for-each> 
113       
114</xsl:template> 
115       
116       
117<xsl:template match="*" >
118        <!-- <xsl:param name="lv" select="1" />-->
119        <!--<xsl:variable name="lv" select="count(ancestor::d)" /> -->
120        <!-- <xsl:if test="string-length(string-join(.//text(),'')) &gt; 1" > -->               
121                <xsl:variable name="has_text" >
122                        <xsl:choose>
123                        <!-- FIXME: text()[1] ? is that safe?-->
124                                <xsl:when test="normalize-space(text()[1])='Unspecified'">unspecified</xsl:when>
125                                <xsl:when test="not(normalize-space(text()[1])='')">text</xsl:when>                             
126                                <xsl:otherwise>empty</xsl:otherwise>
127                        </xsl:choose>
128                       
129                </xsl:variable>
130                <div class="elem {$has_text}" ><span class="elem_name"><xsl:value-of select="name()" />:</span>
131                <span class="elem_value"><xsl:value-of select="text()" /></span>
132                        <xsl:apply-templates select="*" />                                     
133                </div>
134       
135</xsl:template> 
136       
137        <!--
138sample header: 
139<numberOfRecords>524</numberOfRecords>
140    <echoedSearchRetrieveRequest>//Title[contains(.,'an')] /db/cmdi-mirror/silang_data 1 50</echoedSearchRetrieveRequest>
141    <diagnostics>50</diagnostics>
142    -->
143<xsl:template name="header">
144        <div class="result-header" >
145        <xsl:attribute name="max_value"><xsl:value-of select="numberOfRecords" /></xsl:attribute>
146        <xsl:variable name="cnt_hits" select="number(diagnostics)" />
147       
148        <form action="{my:formURL('search', 'htmlpage', $q)}" method="get">                                                     
149                       
150                <span class="label" >hits: </span><span class="value hilight"><xsl:value-of select="numberOfRecords" /></span>;
151                <span class="label" >from:</span><span><input type="text" name="startRecord" class="value start_record paging-input"><xsl:attribute name="value">
152                <xsl:value-of select="$startRecord"/>
153                        </xsl:attribute>
154                </input></span>
155       
156                <span class="label" >max:</span><span><input type="text" name="maximumRecords" class="value maximum_records paging-input" ><xsl:attribute name="value">
157                <xsl:value-of select="if(number($cnt_hits) &lt; number($maximumRecords)) then $cnt_hits else $maximumRecords"/>   
158                </xsl:attribute></input></span> 
159               
160                <xsl:if test="$repository_name != ''">
161                        <input type="hidden" name="repository"><xsl:attribute name="value">
162                        <xsl:value-of select="$repository_name"/>
163                                </xsl:attribute>
164                        </input>
165                </xsl:if>
166         
167                <input type="hidden" name="query"><xsl:attribute name="value">
168                        <xsl:value-of select="$q"/>
169                                </xsl:attribute>
170                </input>
171                       
172                 <input type="submit" value="" class="cmd cmd_reload">
173                </input>
174         <!--  number($startRecord - $pageRecordCount)<a href="{my:formsearchURL($q,'1','20',$repository_name)}"><span class="cmd cmd_reload" /></a> -->
175                <xsl:variable name="prev_startRecord">
176                        <xsl:choose>
177                                <xsl:when test="number($startRecord) - number($maximumRecords) > 0"> <xsl:value-of select="format-number(number($startRecord) - number($maximumRecords),'#')"></xsl:value-of></xsl:when>
178                                <xsl:otherwise><xsl:value-of select="1"></xsl:value-of></xsl:otherwise>
179                        </xsl:choose>
180                </xsl:variable>
181                <!--
182                <xsl:variable name="next_maximumRecords">
183                        <xsl:choose>
184                                <xsl:when test="number($maximumRecords) + number($pageRecordCount) > number(numberOfRecords)"> <xsl:value-of select="numberOfRecords"></xsl:value-of></xsl:when>
185                                <xsl:otherwise><xsl:value-of select="format-number(number($maximumRecords) + number($pageRecordCount),'#')"></xsl:value-of></xsl:otherwise>
186                        </xsl:choose>
187                </xsl:variable>
188                <xsl:variable name="prev_maximumRecords">
189                        <xsl:choose>
190                                <xsl:when test="number($prev_startRecord) + number($pageRecordCount) > number(numberOfRecords)"> <xsl:value-of select="numberOfRecords"></xsl:value-of></xsl:when>
191                                <xsl:otherwise><xsl:value-of select="format-number(number($prev_startRecord) + number($pageRecordCount),'#')"></xsl:value-of></xsl:otherwise>
192                        </xsl:choose>
193                </xsl:variable>
194                 -->
195                <xsl:variable name="next_startRecord">
196                        <xsl:choose>
197                                <xsl:when test="number($startRecord) + number($maximumRecords) > number(numberOfRecords)"> <xsl:value-of select="$startRecord"></xsl:value-of></xsl:when>
198                                <xsl:otherwise><xsl:value-of select="format-number(number($startRecord) + number($maximumRecords),'#')"></xsl:value-of></xsl:otherwise>
199                        </xsl:choose>
200                </xsl:variable>
201                <a href="{my:formsearchURL($q,$prev_startRecord,$maximumRecords,$repository_name)}">
202                        <span class="cmd cmd_prev">     
203                        <xsl:choose>
204                        <xsl:when test="$startRecord = '1'">
205                                <xsl:attribute name="disabled">disabled</xsl:attribute>
206                        </xsl:when>
207                        </xsl:choose>
208                        </span>
209                </a>
210                <a href="{my:formsearchURL($q,$next_startRecord,$maximumRecords,$repository_name)}">
211                        <span class="cmd cmd_next">     
212                        <xsl:choose>
213                                <xsl:when test="$maximumRecords &gt; numberOfRecords or $maximumRecords = numberOfRecords">
214                                        <xsl:attribute name="disabled">disabled</xsl:attribute>
215                                </xsl:when>
216                                </xsl:choose>
217                        </span>
218                </a>
219        </form>
220        <span class="cmd cmd_detail" /> 
221                <div class='ui-widget-content columns-wrapper'>
222                        <div class='cmds'><span class="cmd cmd_reload" /><span class="cmd cmd_save" /><span class="cmd cmd_savenew" /></div>
223                        <div class='query-columns'>
224                        <label>Columns</label>
225                                <xsl:call-template name="columns" />
226                        </div>
227                </div>   
228    </div>
229    <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>
230</xsl:template> 
231
232<xsl:template name="columns">
233        <table>
234        <tr><td valign="top">
235        <div class="columns-selected" > 
236        <!--
237                <span class="label">selected columns</span>
238                <ul class="query-columnslist">
239                        <xsl:for-each select="$columns/*">
240                                <li><xsl:value-of select="@label"/><span class='cmd cmd_del'/></li>
241                        </xsl:for-each>
242                </ul>
243         -->
244        </div>
245        </td><td valign="top">
246                <div>
247                        <span class="label" >format:</span>
248                        <select class="value-format">
249                       
250                        <option value="htmltable">
251                                <xsl:choose>
252                                <xsl:when test="contains($format, 'htmltable')">
253                                        <xsl:attribute name="selected">selected</xsl:attribute>
254                                </xsl:when>
255                                </xsl:choose><xsl:text>table</xsl:text>         
256                        </option>
257                        <option value="htmllist">
258                                <xsl:choose>
259                                <xsl:when test="contains($format, 'htmllist')">
260                                        <xsl:attribute name="selected">selected</xsl:attribute>
261                                </xsl:when>
262                                </xsl:choose><xsl:text>list</xsl:text>
263                        </option>
264                        </select>
265                </div>
266        <xsl:if test="extraResponseData/usedProfiles" >
267                <div class="used-profiles">
268                        <span class="label">used profiles in whole result</span>
269                        <ul>
270                                <xsl:for-each select="extraResponseData/usedProfiles/profile" >
271                                        <li><a href="{@id}" ><xsl:value-of select="@name"/></a><span class="note">|<xsl:value-of select="@count"/>|</span></li>
272                                </xsl:for-each>
273                        </ul>
274                </div>
275        </xsl:if>
276        </td></tr>     
277        <xsl:variable name="resultSummary" >           
278                <!-- wrap in <Terms> to make digestible for model2matrix -->
279                <xsl:variable name="terms" >
280                        <Terms>
281                        <!-- TODO: if already provided by mdrepo, use that, otherwise DIY -->           
282                        <xsl:choose>
283                                <xsl:when test="extraResponseData/resultSummary"><xsl:copy-of select="extraResponseData/resultSummary/Term" /></xsl:when>
284                                <xsl:otherwise>
285                                <!-- TODO! -->
286                                </xsl:otherwise>
287                        </xsl:choose>
288                        </Terms>
289                </xsl:variable>
290                <xsl:apply-templates select="$terms" mode="matrix" />
291        </xsl:variable>         
292        <!--  <xsl:message><xsl:value-of select="$resultSummary/*/name()" /> </xsl:message>-->
293       
294        <tr><td colspan="2">   
295        <div class="result-summary">   
296                <span class="label">structure summary of shown result</span>   
297                <!--  calling template in terms2view.xsl -->
298                <!--  <xsl:apply-templates select="$resultSummary" mode="terms-tree" />-->             
299        </div> 
300        </td></tr>
301        </table>
302</xsl:template>
303
304<xsl:template match="records" mode="table">
305   
306        <table class="show">           
307                <thead><tr><th>pos</th>         
308                        <xsl:for-each select="$columns/*">
309                                <th title="{@key}" ><xsl:value-of select="@label"/></th>
310                        </xsl:for-each>                         
311                </tr></thead>
312                <tbody>         
313                        <xsl:apply-templates select="CMD" mode="table" />                       
314                </tbody>
315        </table>
316
317</xsl:template>
318
319
320<xsl:template match="records" mode="list">
321   
322        <table class="show">           
323                <thead><tr><th>pos</th><th>record</th>                                         
324                </tr></thead>
325                <tbody>         
326                        <xsl:apply-templates select="CMD" mode="list" />                       
327                </tbody>
328        </table>
329
330</xsl:template>
331
332<!-- FIXME:   there should be a @match=`record` template to make it SRU-compatible -->
333
334<xsl:template match="CMD" mode="table">
335
336        <xsl:variable name="curr_record" select="." />
337        <xsl:variable name="fields" >
338                <xsl:for-each select="$columns/*">
339                                <!-- <td ><xsl:value-of select="$curr_cmd//*[name()=current()]" /></td> -->
340        <!--    <xsl:message><xsl:copy-of select="."></xsl:copy-of> </xsl:message> -->
341                                         <xsl:variable name="curr_col_xpath" select="@xpath" />
342                                <td>                   
343                                        <xsl:for-each select="$curr_record">
344                                                <xsl:call-template name="format-field" >
345                                                        <xsl:with-param name="elems" select="saxon:evaluate(concat('.//', $curr_col_xpath))" />
346                                                </xsl:call-template>                                   
347                                       
348                                        </xsl:for-each>
349                                </td>
350                                </xsl:for-each>
351          </xsl:variable>
352
353        <xsl:call-template name="record-table-row" >
354                <xsl:with-param name="fields" select="$fields" />
355        </xsl:call-template>
356       
357</xsl:template>
358
359<xsl:template match="CMD" mode="list">
360
361                <xsl:variable name="curr_record" select="." />                 
362                <xsl:variable name="cmd_sel_fields" >
363                        <xsl:for-each select="$columns/*">
364                                <xsl:variable name="curr_col_xpath" select="@xpath" />                                                 
365                                <xsl:for-each select="$curr_record">                           
366                                        <xsl:copy-of select="saxon:evaluate(concat('.//', $curr_col_xpath))" />
367                                </xsl:for-each>                         
368                        </xsl:for-each>
369                </xsl:variable>
370                <xsl:variable name="fields" >
371                        <div>
372                                <xsl:apply-templates select="$cmd_sel_fields" mode="format-xmlelem" />
373                        </div>
374                </xsl:variable>
375
376        <xsl:call-template name="record-table-row" >
377                <xsl:with-param name="fields" select="$fields" />
378        </xsl:call-template>
379                                                                                       
380</xsl:template>
381
382
383<xsl:template name="record-table-row">
384<xsl:param name="fields" />
385<!-- @field absolute_position compute records position over whole recordset, ie add `startRecord` (important when paging)
386 -->
387        <xsl:variable name="absolute_position" select="if (number($startRecord)=number($startRecord)) then number($startRecord) + position() - 1 else  position()" />
388       
389                <tr>
390                <td rowspan="2">
391                        <xsl:choose>
392                                <xsl:when test="exists(.//MdSelfLink)" >
393                                        <xsl:choose>
394                                                <xsl:when test="contains($format, 'htmlsimple')" >
395                                                <a class="internal" href="{concat('../../record/htmldetail/', my:encodePID(.//MdSelfLink), '?repository=', $repository_name)}" >
396                                                                <xsl:value-of select="$absolute_position" />
397                                                </a>                                           
398                                                </xsl:when>
399                                                <xsl:otherwise>
400                                                <a class="internal" href="{concat('record/htmldetail/', my:encodePID(.//MdSelfLink), '?repository=', $repository_name)}" >
401                                                                <xsl:value-of select="$absolute_position" />
402                                                </a>
403                                                </xsl:otherwise>
404                                        </xsl:choose>
405                                        <span class="cmd cmd_detail" ></span>                           
406                                        <span class="cmd cmd_save" ></span>                                             
407                                </xsl:when>
408                                <xsl:otherwise><xsl:value-of select="$absolute_position" /></xsl:otherwise>
409                        </xsl:choose>
410                </td>           
411                <td colspan="{count($columns/*)}" >
412                                <xsl:call-template name="getContext" />
413                        <div class="title" ><xsl:call-template name="getName" /></div>                 
414                </td>
415                </tr>
416                <tr>
417                        <xsl:copy-of select="$fields" />                                               
418                </tr>                                                                   
419</xsl:template>
420
421
422<xsl:template match="records" mode="simple">
423   
424    <form action="" method="get">
425                                <input type="text" name="q" ><xsl:attribute name="value"><xsl:value-of select="$q"/></xsl:attribute> </input>                           
426                                <input type="submit" value="Submit" > </input><br/>                             
427        </form>
428        <xsl:call-template name="header" />     
429        <table class="show">           
430                <thead><tr><th>pos</th>         
431                        <xsl:for-each select="$columns/*">
432                                <th title="{@key}" ><xsl:value-of select="@label"/></th>
433                        </xsl:for-each>                         
434                </tr></thead>
435                <tbody> 
436                        <xsl:apply-templates select="CMD" mode="table" />                               
437                </tbody>
438        </table>
439
440</xsl:template>
441
442</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.