source: MDService2/branches/MDService_simple3/src/xsl/sru2view.xsl @ 1637

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

$repository_name removed

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