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

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

debug mdset_pazpar.xsl

File size: 15.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        <xsl:import href="cmd_commons.xsl"/>
21        <xsl:import href="util_xml_ay.xsl"/>
22
23<xsl:output method="xml" />
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<div class="result">
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</div>
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       
159        <span class="label" >hits: </span><span class="value hilight"><xsl:value-of select="$numberOfRecords" /></span>;
160        <span class="label" >from:</span><span><input type="text" class="value start_record paging-input"><xsl:attribute name="value">
161    <xsl:value-of select="$startItem"/>
162  </xsl:attribute>
163        </input></span>
164        <span class="label" >max:</span><span><input type="text" class="value maximum_records paging-input" ><xsl:attribute name="value">
165    <xsl:value-of select="if(number($cnt_hits) &lt; number($maximumItems)) then $cnt_hits else $maximumItems"/>   
166        </xsl:attribute></input></span>
167                <!--
168  <span class="cmd cmd_reload" /> 
169<!-\-   <button class="reload">reload</button>-\->
170        <span class="cmd cmd_prev">     
171        <xsl:choose>
172                <xsl:when test="$startItem = '1'">
173                        <xsl:attribute name="disabled">disabled</xsl:attribute>
174                </xsl:when>
175                </xsl:choose>
176        </span>
177        <span class="cmd cmd_next">     
178        <xsl:choose>
179                <xsl:when test="$maximumItems &gt;= $numberOfRecords">
180                        <xsl:attribute name="disabled">disabled</xsl:attribute>
181                </xsl:when>
182                </xsl:choose>
183        </span>
184        <span class="cmd cmd_detail" />
185        <!-\-  <div class='ui-context-dialog ui-widget-content columns-wrapper'>  -\->
186                <div class='ui-widget-content columns-wrapper'>
187                        <div class='cmds'><span class="cmd cmd_reload" /><span class="cmd cmd_save" /><span class="cmd cmd_savenew" /></div>
188                        <div class='query-columns'>
189                        <label>Columns</label>
190                                <xsl:call-template name="columns" />
191                        </div>
192                </div>
193                -->
194               
195                <label>Columns</label>
196                        <xsl:call-template name="columns" />           
197    </div>
198    <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>
199</xsl:template> 
200
201<xsl:template name="columns">
202        <table>
203        <tr><td valign="top">
204        <div class="columns-selected" > 
205        <!--
206                <span class="label">selected columns</span>
207                <ul class="query-columnslist">
208                        <xsl:for-each select="$columns/*">
209                                <li><xsl:value-of select="@label"/><span class='cmd cmd_del'/></li>
210                        </xsl:for-each>
211                </ul>
212         -->
213        </div>
214        </td><td valign="top">
215                <div>
216                        <span class="label" >format:</span>
217                        <select class="value-format">
218                       
219                        <option value="htmltable">
220                                <xsl:choose>
221                                <xsl:when test="contains($format, 'htmltable')">
222                                        <xsl:attribute name="selected">selected</xsl:attribute>
223                                </xsl:when>
224                                </xsl:choose><xsl:text>table</xsl:text>         
225                        </option>
226                        <option value="htmllist">
227                                <xsl:choose>
228                                <xsl:when test="contains($format, 'htmllist')">
229                                        <xsl:attribute name="selected">selected</xsl:attribute>
230                                </xsl:when>
231                                </xsl:choose><xsl:text>list</xsl:text>
232                        </option>
233                        </select>
234                </div>
235        <xsl:if test="extraResponseData/usedProfiles" >
236                <div class="used-profiles">
237                        <span class="label">used profiles in whole result</span>
238                        <ul>
239                                <xsl:for-each select="extraResponseData/usedProfiles/profile" >
240                                        <li><a href="{@id}" ><xsl:value-of select="@name"/></a><span class="note">|<xsl:value-of select="@count"/>|</span></li>
241                                </xsl:for-each>
242                        </ul>
243                </div>
244        </xsl:if>
245        </td></tr>     
246        <xsl:variable name="resultSummary" >           
247                <!-- wrap in <Terms> to make digestible for model2matrix -->
248                <xsl:variable name="terms" >
249                        <Terms>
250                        <!-- TODO: if already provided by mdrepo, use that, otherwise DIY -->           
251                        <xsl:choose>
252                                <xsl:when test="extraResponseData/resultSummary"><xsl:copy-of select="extraResponseData/resultSummary/Term" /></xsl:when>
253                                <xsl:otherwise>
254                                        <xsl:call-template name="xml-ay">
255                                                <xsl:with-param name="dataset" select="$records"></xsl:with-param>
256                                        </xsl:call-template>
257                                </xsl:otherwise>
258                        </xsl:choose>
259                        </Terms>
260                </xsl:variable>
261                <!-- <xsl:apply-templates select="$terms" mode="matrix" />-->
262                <xsl:copy-of select="$terms"></xsl:copy-of>
263        </xsl:variable>         
264                <!--<xsl:message><xsl:copy-of select="$resultSummary"></xsl:copy-of></xsl:message>-->
265       
266        <tr><td colspan="2">   
267        <div class="result-summary">   
268                <span class="label">structure summary of shown result</span>   
269                <!--  calling template in terms2view.xsl -->           
270                <xsl:apply-templates select="$resultSummary" mode="terms-tree" />               
271        </div> 
272        </td></tr>
273        </table>
274</xsl:template>
275
276
277<xsl:template match="records" mode="table">
278   
279        <table class="show">           
280                <thead><tr><th>pos</th>         
281                        <xsl:for-each select="$columns/*">
282                                <th title="{@key}" ><xsl:value-of select="@label"/></th>
283                        </xsl:for-each>                         
284                </tr></thead>
285                <tbody>         
286                        <xsl:apply-templates select="CMD" mode="table" />                       
287                </tbody>
288        </table>
289
290</xsl:template>
291
292        <xsl:template name="record-table">
293               
294                <table class="show">           
295                        <thead><tr><th>pos</th>         
296                                <xsl:for-each select="$columns/*">
297                                        <th title="{@key}" ><xsl:value-of select="@label"/></th>
298                                </xsl:for-each>                         
299                        </tr></thead>
300                        <tbody>         
301                                <xsl:apply-templates select="$records" mode="tablerow" />                       
302                        </tbody>
303                </table>
304               
305        </xsl:template>
306       
307        <xsl:template name="record-list" >
308   
309        <table class="show">           
310                <thead><tr><th>pos</th><th>record</th>                                         
311                </tr></thead>
312                <tbody>         
313                        <xsl:apply-templates select="$records" mode="listitem" />                       
314                </tbody>
315        </table>
316
317</xsl:template>
318       
319       
320
321<!-- FIXME:   there should be a @match=`record` template to make it SRU-compatible -->
322
323<xsl:template match="*" mode="tablerow">
324
325        <xsl:variable name="curr_record" select="." />
326        <xsl:variable name="fields" >
327                <xsl:for-each select="$columns/*">
328                                <!-- <td ><xsl:value-of select="$curr_cmd//*[name()=current()]" /></td> -->
329        <!--    <xsl:message><xsl:copy-of select="."></xsl:copy-of> </xsl:message> -->
330                                         <xsl:variable name="curr_col_xpath" select="@xpath" />
331                                <td>                   
332                                        <xsl:for-each select="$curr_record">
333                                                <xsl:call-template name="format-field" >
334                                                        <xsl:with-param name="elems" select="saxon:evaluate(concat('.//', $curr_col_xpath))" />
335                                                </xsl:call-template>                                   
336                                       
337                                        </xsl:for-each>
338                                </td>
339                                </xsl:for-each>
340          </xsl:variable>
341
342        <xsl:call-template name="record-table-row" >
343                <xsl:with-param name="fields" select="$fields" />
344        </xsl:call-template>
345       
346</xsl:template>
347
348<xsl:template match="hit" mode="listitem">
349
350                <xsl:variable name="curr_record" select="." />                 
351                <xsl:variable name="cmd_sel_fields" >                   
352                        <xsl:for-each select="$columns/*">
353                                <xsl:variable name="curr_col_xpath" select="@xpath" />                                                 
354                                <xsl:for-each select="$curr_record">                           
355                                        <xsl:copy-of select="saxon:evaluate(concat('.//', $curr_col_xpath))" />
356                                </xsl:for-each>                         
357                        </xsl:for-each>
358                </xsl:variable>
359                <xsl:variable name="fields" >
360                        <div>
361                                <xsl:apply-templates select="$cmd_sel_fields" mode="format-xmlelem" />
362                        </div>
363                </xsl:variable>
364
365        <xsl:call-template name="record-table-row" >
366                <xsl:with-param name="fields" select="$fields" />
367        </xsl:call-template>
368                                                                                       
369</xsl:template>
370
371
372<xsl:template name="record-table-row">
373<xsl:param name="fields" />
374<!-- @field absolute_position compute records position over whole recordset, ie add `startItem` (important when paging)
375 -->
376        <xsl:variable name="absolute_position" select="if (number($startItem)=number($startItem)) then number($startItem) + position() - 1 else  position()" />
377       
378                <tr>
379                <td rowspan="2">
380                        <xsl:choose>
381                                <xsl:when test="exists(.//MdSelfLink)" >
382                                        <xsl:choose>
383                                                <xsl:when test="contains($format, 'htmlsimple')" >
384                                                <a class="internal" href="{concat('../../record/htmldetail/', my:encodePID(.//MdSelfLink), '?repository=', $repository_name)}" >
385                                                                <xsl:value-of select="$absolute_position" />
386                                                </a>                                           
387                                                </xsl:when>
388                                                <xsl:otherwise>
389                                                <a class="internal" href="{concat('record/htmldetail/', my:encodePID(.//MdSelfLink), '?repository=', $repository_name)}" >
390                                                                <xsl:value-of select="$absolute_position" />
391                                                </a>
392                                                </xsl:otherwise>
393                                        </xsl:choose>
394                                        <span class="cmd cmd_detail" ></span>                           
395                                        <span class="cmd cmd_save" ></span>                                             
396                                </xsl:when>
397                                <xsl:otherwise><xsl:value-of select="$absolute_position" /></xsl:otherwise>
398                        </xsl:choose>
399                </td>           
400                <td colspan="{count($columns/*)}" >
401                                <xsl:call-template name="getContext" />
402                        <div class="title" ><xsl:call-template name="getName" /></div>                 
403                </td>
404                </tr>
405                <tr>
406                        <xsl:copy-of select="$fields" />                                               
407                </tr>                                                                   
408</xsl:template>
409
410
411<xsl:template match="records" mode="simple">
412   
413    <form action="" method="get">
414                                <input type="text" name="q" ><xsl:attribute name="value"><xsl:value-of select="$q"/></xsl:attribute> </input>
415                               
416                                <input type="submit" value="Submit" > </input><br/>
417                                <label>startItem: </label><input type="text" name="startItem" ><xsl:attribute name="value"><xsl:value-of select="$startItem"/></xsl:attribute> </input><br/>
418                                <label> maxItems: </label><input type="text" name="maximumItems" ><xsl:attribute name="value"><xsl:value-of select="$maximumItems"/></xsl:attribute> </input>
419        </form>
420        <table class="show">           
421                <thead><tr><th>pos</th>         
422                        <xsl:for-each select="$columns/*">
423                                <th title="{@key}" ><xsl:value-of select="@label"/></th>
424                        </xsl:for-each>                         
425                </tr></thead>
426                <tbody> 
427                        <xsl:apply-templates select="CMD" mode="table" />                               
428                </tbody>
429        </table>
430
431</xsl:template>
432
433<xsl:template name="getContext" >
434                <!--    <div class="is-part-of collections" ><xsl:value-of select=".//IsPartOf" /> </div>-->
435        <div class="ispartof-list"><span class="label">in: </span>
436                <xsl:apply-templates select="location" /> >
437        </div>
438</xsl:template> 
439       
440<xsl:template match="location" >
441                <!-- <a class="internal" href="{concat($default_prefix, my:encodePID(.))}"><xsl:value-of select="." /></a> >-->
442                <a class="external" href="{@id}"><xsl:value-of select="@name" /></a> +
443</xsl:template>
444
445
446</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.