source: MDService2/trunk/MDService2/src/xsl/sru2view.xsl @ 1469

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

intial version of stylesheet for sru.
very basic, just to try. not stable

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