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