source: MDService2/trunk/MDService2/src/xsl/mdset_pazpar2view.xsl @ 1485

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

provide header info

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