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 | |
---|
21 | <xsl:output method="html" /> |
---|
22 | |
---|
23 | <xsl:include href="cmd_commons.xsl"/> |
---|
24 | |
---|
25 | |
---|
26 | <xsl:param name="startItem">1</xsl:param> |
---|
27 | <xsl:param name="maximumItems">50</xsl:param> |
---|
28 | |
---|
29 | <!-- <xsl:param name="format" select="'table'" /> table|list|detail --> |
---|
30 | <xsl:param name="cols" >Id,Title,Location |
---|
31 | <!-- |
---|
32 | <col label="id">Id</col> |
---|
33 | <col label="id">idno</col> |
---|
34 | <col label="name">Name</col> |
---|
35 | <col label="title">Title</col> |
---|
36 | <col label="title">title</col> |
---|
37 | <col label="loc" >Location</col> |
---|
38 | <col label="loc" >pubPlace</col> |
---|
39 | <col label="lang" >language</col> |
---|
40 | |
---|
41 | --> |
---|
42 | </xsl:param> |
---|
43 | |
---|
44 | <xsl:param name="mode" select="'html'" /> |
---|
45 | <xsl:param name="title" > |
---|
46 | <xsl:text>MDRecordSet </xsl:text> |
---|
47 | </xsl:param> |
---|
48 | |
---|
49 | <xsl:variable name="columns" > |
---|
50 | <!-- <xsl:message>COLUMNS: <xsl:value-of select="$cols" /><xsl:value-of select="string-length($cols)" /></xsl:message> --> |
---|
51 | <xsl:variable name="colarray" select="tokenize($cols,',')"/> |
---|
52 | <xsl:for-each select="$colarray" > |
---|
53 | <col key="{.}" label="{replace(.,'^.*\.([^.]+)$','$1')}" xpath_osbolete="{replace(.,'\.','/')}" xpath="{my:index2xpath(.)}" /> |
---|
54 | <!-- if (contains(.,'.')) then reverse(.) else . --> |
---|
55 | </xsl:for-each> |
---|
56 | <xsl:if test="count($colarray)=0" > |
---|
57 | <xsl:copy-of select="$autocolumns"></xsl:copy-of> |
---|
58 | <!-- <xsl:message>AUTOCOLUMNS: <xsl:copy-of select="$autocolumns" /><xsl:value-of select="count($autocolumns)" /></xsl:message> --> |
---|
59 | </xsl:if> |
---|
60 | |
---|
61 | </xsl:variable> |
---|
62 | |
---|
63 | <xsl:variable name="autocolumns" > |
---|
64 | <xsl:variable name="precompute"> |
---|
65 | <xsl:for-each-group select="//Components//*[not(*)][exists(text())]" group-by="name()" > |
---|
66 | <xsl:sort select="sum(current-group()/string-length(string-join(text(),';')))" order="descending" /> |
---|
67 | <!-- <xsl:message>precomputing: <xsl:value-of select="name()" /> |
---|
68 | count: <xsl:value-of select="count(current-group())" /> sum:<xsl:value-of select="sum(current-group()/string-length(string-join(text(),';')))" /></xsl:message> --> |
---|
69 | <col key="{name()}" label="{name()}" xpath="{name()}" /> |
---|
70 | </xsl:for-each-group> |
---|
71 | </xsl:variable> |
---|
72 | <!-- <xsl:message>precompute: <xsl:copy-of select="$precompute" /><xsl:value-of select="count($precompute)" /></xsl:message>--> |
---|
73 | <xsl:copy-of select="$precompute/*[position() < $autocolumns_limit]"></xsl:copy-of> |
---|
74 | </xsl:variable> |
---|
75 | |
---|
76 | <xsl:template name="continue-root" > |
---|
77 | |
---|
78 | <xsl:for-each select="searchRetrieveResponse" > |
---|
79 | <xsl:call-template name="header" /> |
---|
80 | <xsl:choose> |
---|
81 | <xsl:when test="contains($format,'htmltable')"> |
---|
82 | <xsl:apply-templates select="records" mode="table" /> |
---|
83 | </xsl:when> |
---|
84 | <xsl:when test="contains($format,'htmllist')"> |
---|
85 | <xsl:apply-templates select="records" mode="list" /> |
---|
86 | </xsl:when> |
---|
87 | <xsl:when test="contains($format, 'htmldetail')"> |
---|
88 | <xsl:apply-templates select="records" mode="detail" /> |
---|
89 | </xsl:when> |
---|
90 | <xsl:when test="contains($format, 'htmlpage')"> |
---|
91 | <xsl:apply-templates select="records" mode="detail" /> |
---|
92 | </xsl:when> |
---|
93 | <xsl:otherwise>mdset2view: unrecognized format: <xsl:value-of select="$format" /></xsl:otherwise> |
---|
94 | </xsl:choose> |
---|
95 | </xsl:for-each> |
---|
96 | |
---|
97 | </xsl:template> |
---|
98 | |
---|
99 | |
---|
100 | <xsl:template match="*" > |
---|
101 | <!-- <xsl:param name="lv" select="1" />--> |
---|
102 | <!--<xsl:variable name="lv" select="count(ancestor::d)" /> --> |
---|
103 | <xsl:if test="string-length(.//text()) > 1" > |
---|
104 | <xsl:variable name="has_text" > |
---|
105 | <xsl:choose> |
---|
106 | <xsl:when test="normalize-space(text())='Unspecified'">unspecified</xsl:when> |
---|
107 | <xsl:when test="not(normalize-space(text())='')">text</xsl:when> |
---|
108 | <xsl:otherwise>empty</xsl:otherwise> |
---|
109 | </xsl:choose> |
---|
110 | |
---|
111 | </xsl:variable> |
---|
112 | <div class="elem {$has_text}" ><span class="elem_name"><xsl:value-of select="name()" />:</span> |
---|
113 | <span class="elem_value"><xsl:value-of select="text()" /></span> |
---|
114 | <xsl:apply-templates select="*" /> |
---|
115 | </div> |
---|
116 | </xsl:if> |
---|
117 | </xsl:template> |
---|
118 | |
---|
119 | <!-- |
---|
120 | sample header: |
---|
121 | <numberOfRecords>524</numberOfRecords> |
---|
122 | <echoedSearchRetrieveRequest>//Title[contains(.,'an')] /db/cmdi-mirror/silang_data 1 50</echoedSearchRetrieveRequest> |
---|
123 | <diagnostics>50</diagnostics> |
---|
124 | --> |
---|
125 | <xsl:template name="header"> |
---|
126 | <div class="result-header" > |
---|
127 | <xsl:attribute name="max_value"><xsl:value-of select="numberOfRecords" /></xsl:attribute> |
---|
128 | <xsl:variable name="cnt_hits" select="number(diagnostics)" /> |
---|
129 | |
---|
130 | <span class="label" >hits: </span><span class="value hilight"><xsl:value-of select="numberOfRecords" /></span>; |
---|
131 | <span class="label" >from:</span><span><input type="text" class="value start_record paging-input"><xsl:attribute name="value"> |
---|
132 | <xsl:value-of select="$startItem"/> |
---|
133 | </xsl:attribute> |
---|
134 | </input></span> |
---|
135 | <span class="label" >max:</span><span><input type="text" class="value maximum_records paging-input" ><xsl:attribute name="value"> |
---|
136 | <xsl:value-of select="if(number($cnt_hits) < number($maximumItems)) then $cnt_hits else $maximumItems"/> |
---|
137 | </xsl:attribute></input></span> |
---|
138 | <span class="cmd cmd_reload" /> |
---|
139 | <!-- <button class="reload">reload</button>--> |
---|
140 | <span class="cmd cmd_prev"> |
---|
141 | <xsl:choose> |
---|
142 | <xsl:when test="$startItem = '1'"> |
---|
143 | <xsl:attribute name="disabled">disabled</xsl:attribute> |
---|
144 | </xsl:when> |
---|
145 | </xsl:choose> |
---|
146 | </span> |
---|
147 | <span class="cmd cmd_next"> |
---|
148 | <xsl:choose> |
---|
149 | <xsl:when test="$maximumItems > numberOfRecords or $maximumItems = numberOfRecords"> |
---|
150 | <xsl:attribute name="disabled">disabled</xsl:attribute> |
---|
151 | </xsl:when> |
---|
152 | </xsl:choose> |
---|
153 | </span> |
---|
154 | <span class="cmd cmd_columns" /> |
---|
155 | <div class='ui-context-dialog ui-widget-content columns-wrapper'> |
---|
156 | <div class='query-columns'> |
---|
157 | <xsl:call-template name="columns" /> |
---|
158 | </div><span class='cmd cmd_del'></span><span class="cmd cmd_reload" /></div> |
---|
159 | </div> |
---|
160 | <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> |
---|
161 | </xsl:template> |
---|
162 | |
---|
163 | <xsl:template name="columns"> |
---|
164 | <table> |
---|
165 | <tr><td valign="top"> |
---|
166 | <div class="columns-selected" > |
---|
167 | <span class="label">selected columns</span> |
---|
168 | <ul class="query-columnslist"> |
---|
169 | <xsl:for-each select="$columns/*"> |
---|
170 | <li><xsl:value-of select="@label"/><span class='cmd cmd_del'/></li> |
---|
171 | </xsl:for-each> |
---|
172 | </ul> |
---|
173 | </div> |
---|
174 | </td><td valign="top"> |
---|
175 | <div> |
---|
176 | <span class="label" >format:</span> |
---|
177 | <select class="value-format"> |
---|
178 | |
---|
179 | <option value="htmltable"> |
---|
180 | <xsl:choose> |
---|
181 | <xsl:when test="contains($format, 'htmltable')"> |
---|
182 | <xsl:attribute name="selected">selected</xsl:attribute> |
---|
183 | </xsl:when> |
---|
184 | </xsl:choose><xsl:text>table</xsl:text> |
---|
185 | </option> |
---|
186 | <option value="htmllist"> |
---|
187 | <xsl:choose> |
---|
188 | <xsl:when test="contains($format, 'htmllist')"> |
---|
189 | <xsl:attribute name="selected">selected</xsl:attribute> |
---|
190 | </xsl:when> |
---|
191 | </xsl:choose><xsl:text>list</xsl:text> |
---|
192 | </option> |
---|
193 | </select> |
---|
194 | </div> |
---|
195 | <xsl:if test="extraResponseData/usedProfiles" > |
---|
196 | <div class="used-profiles"> |
---|
197 | <span class="label">used profiles in whole result</span> |
---|
198 | <ul> |
---|
199 | <xsl:for-each select="extraResponseData/usedProfiles/profile" > |
---|
200 | <li><a href="{@id}" ><xsl:value-of select="@name"/></a><span class="note">|<xsl:value-of select="@count"/>|</span></li> |
---|
201 | </xsl:for-each> |
---|
202 | </ul> |
---|
203 | </div> |
---|
204 | </xsl:if> |
---|
205 | </td></tr> |
---|
206 | <xsl:variable name="resultSummary" > |
---|
207 | <!-- wrap in <Terms> to make digestible for model2matrix --> |
---|
208 | <xsl:variable name="terms" > |
---|
209 | <Terms> |
---|
210 | <!-- if already provided by mdrepo, use that, otherwise DIY --> |
---|
211 | <xsl:choose> |
---|
212 | <xsl:when test="extraResponseData/resultSummary"><xsl:copy-of select="extraResponseData/resultSummary/Term" /></xsl:when> |
---|
213 | <xsl:otherwise> |
---|
214 | <!-- TODO! --> |
---|
215 | </xsl:otherwise> |
---|
216 | </xsl:choose> |
---|
217 | </Terms> |
---|
218 | </xsl:variable> |
---|
219 | <xsl:apply-templates select="$terms" mode="matrix" /> |
---|
220 | </xsl:variable> |
---|
221 | <!-- <xsl:message><xsl:value-of select="$resultSummary/*/name()" /> </xsl:message> --> |
---|
222 | |
---|
223 | <tr><td colspan="2"> |
---|
224 | <div class="result-summary"> |
---|
225 | <span class="label">structure summary of shown result</span> |
---|
226 | <!-- calling template in terms2view.xsl --> |
---|
227 | <xsl:apply-templates select="$resultSummary" mode="terms-tree" /> |
---|
228 | </div> |
---|
229 | </td></tr> |
---|
230 | </table> |
---|
231 | </xsl:template> |
---|
232 | |
---|
233 | <xsl:template match="records" mode="table"> |
---|
234 | |
---|
235 | <table class="show"> |
---|
236 | <thead><tr><th>pos</th> |
---|
237 | <xsl:for-each select="$columns/*"> |
---|
238 | <th title="{@key}" ><xsl:value-of select="@label"/></th> |
---|
239 | </xsl:for-each> |
---|
240 | </tr></thead> |
---|
241 | <tbody> |
---|
242 | <xsl:apply-templates select="CMD" mode="table" /> |
---|
243 | </tbody> |
---|
244 | </table> |
---|
245 | |
---|
246 | </xsl:template> |
---|
247 | |
---|
248 | <xsl:template match="CMD" mode="table"> |
---|
249 | <tr> |
---|
250 | <td> |
---|
251 | <xsl:choose> |
---|
252 | <xsl:when test="exists(.//MdSelfLink)" > |
---|
253 | <a class="internal" href="{concat('record/htmldetail/', my:encodePID(.//MdSelfLink), '?repository=', $repository_id)}" > |
---|
254 | <xsl:value-of select="position()" /> |
---|
255 | </a> |
---|
256 | <span class="cmd cmd_detail" ></span> |
---|
257 | <span class="cmd cmd_save" ></span> |
---|
258 | </xsl:when> |
---|
259 | <xsl:otherwise><xsl:value-of select="position()" /></xsl:otherwise> |
---|
260 | </xsl:choose> |
---|
261 | </td> |
---|
262 | <xsl:variable name="curr_cmd" select="." /> |
---|
263 | <!-- <xsl:for-each select="$cols/col" > |
---|
264 | <td ><xsl:value-of select="$curr_cmd//*[name()=current()]" /></td> |
---|
265 | <xsl:for-each select="distinct-values($cols/col/@label)" > |
---|
266 | <td > |
---|
267 | <xsl:value-of select="$curr_cmd//*[name()=current()]" /> |
---|
268 | <xsl:for-each select="$cols/col[@label=current()]" > |
---|
269 | <xsl:variable name="curr_col_xpath" select="text()" /> |
---|
270 | |
---|
271 | <xsl:message><xsl:value-of select="$curr_col_xpath" /></xsl:message> |
---|
272 | |
---|
273 | <xsl:for-each select="$curr_cmd" > |
---|
274 | <xsl:value-of select="saxon:evaluate(concat('.//', $curr_col_xpath))" /> |
---|
275 | </xsl:for-each> |
---|
276 | </xsl:for-each> |
---|
277 | </td> |
---|
278 | </xsl:for-each> |
---|
279 | --> |
---|
280 | |
---|
281 | <xsl:for-each select="$columns/*"> |
---|
282 | <!-- <td ><xsl:value-of select="$curr_cmd//*[name()=current()]" /></td> --> |
---|
283 | <!-- <xsl:message><xsl:copy-of select="."></xsl:copy-of> </xsl:message> --> |
---|
284 | <xsl:variable name="curr_col_xpath" select="@xpath" /> |
---|
285 | <td> |
---|
286 | <xsl:for-each select="$curr_cmd"> |
---|
287 | <xsl:call-template name="format-field" > |
---|
288 | <xsl:with-param name="elems" select="saxon:evaluate(concat('.//', $curr_col_xpath))" /> |
---|
289 | </xsl:call-template> |
---|
290 | |
---|
291 | </xsl:for-each> |
---|
292 | </td> |
---|
293 | </xsl:for-each> |
---|
294 | </tr> |
---|
295 | </xsl:template> |
---|
296 | |
---|
297 | |
---|
298 | <xsl:template match="records" mode="list"> |
---|
299 | |
---|
300 | <table class="show"> |
---|
301 | <thead><tr><th>pos</th><th>record</th> |
---|
302 | </tr></thead> |
---|
303 | <tbody> |
---|
304 | <xsl:apply-templates select="CMD" mode="list" /> |
---|
305 | </tbody> |
---|
306 | </table> |
---|
307 | |
---|
308 | </xsl:template> |
---|
309 | |
---|
310 | <xsl:template match="CMD" mode="list"> |
---|
311 | <tr> |
---|
312 | <td> |
---|
313 | <xsl:choose> |
---|
314 | <xsl:when test="exists(.//MdSelfLink)" > |
---|
315 | <a class="internal" href="{concat('record/htmldetail/', my:encodePID(.//MdSelfLink))}" > |
---|
316 | <xsl:value-of select="position()" /> |
---|
317 | </a> |
---|
318 | <span class="cmd cmd_detail" ></span> |
---|
319 | <span class="cmd cmd_save" ></span> |
---|
320 | </xsl:when> |
---|
321 | <xsl:otherwise><xsl:value-of select="position()" /></xsl:otherwise> |
---|
322 | </xsl:choose> |
---|
323 | </td> |
---|
324 | |
---|
325 | <xsl:variable name="curr_cmd" select="." /> |
---|
326 | |
---|
327 | <xsl:variable name="cmd_sel_fields" > |
---|
328 | <xsl:for-each select="$columns/*"> |
---|
329 | <xsl:variable name="curr_col_xpath" select="@xpath" /> |
---|
330 | <xsl:for-each select="$curr_cmd"> |
---|
331 | <xsl:copy-of select="saxon:evaluate(concat('.//', $curr_col_xpath))" /> |
---|
332 | </xsl:for-each> |
---|
333 | </xsl:for-each> |
---|
334 | </xsl:variable> |
---|
335 | <td> |
---|
336 | <div> |
---|
337 | <xsl:apply-templates select="$cmd_sel_fields" mode="format-xmlelem" /> |
---|
338 | </div> |
---|
339 | </td> |
---|
340 | </tr> |
---|
341 | </xsl:template> |
---|
342 | |
---|
343 | |
---|
344 | |
---|
345 | </xsl:stylesheet> |
---|