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 | |
---|
19 | <xsl:output method="html" /> |
---|
20 | |
---|
21 | <xsl:include href="cmd_commons.xsl"/> |
---|
22 | |
---|
23 | <xsl:param name="startRecord">1</xsl:param> |
---|
24 | <xsl:param name="maximumRecords">50</xsl:param> |
---|
25 | |
---|
26 | <!-- <xsl:param name="format" select="'table'" /> table|list|detail --> |
---|
27 | <xsl:param name="cols" >Id,Title,Location |
---|
28 | <!-- |
---|
29 | <col label="id">Id</col> |
---|
30 | <col label="id">idno</col> |
---|
31 | <col label="name">Name</col> |
---|
32 | <col label="title">Title</col> |
---|
33 | <col label="title">title</col> |
---|
34 | <col label="loc" >Location</col> |
---|
35 | <col label="loc" >pubPlace</col> |
---|
36 | <col label="lang" >language</col> |
---|
37 | |
---|
38 | --> |
---|
39 | </xsl:param> |
---|
40 | |
---|
41 | <xsl:param name="mode" select="'html'" /> |
---|
42 | <xsl:param name="title" > |
---|
43 | <xsl:text>MDRecordSet </xsl:text> |
---|
44 | </xsl:param> |
---|
45 | |
---|
46 | <xsl:variable name="columns" > |
---|
47 | <xsl:message>COLUMNS: <xsl:value-of select="$cols" /><xsl:value-of select="string-length($cols)" /></xsl:message> |
---|
48 | <xsl:variable name="colarray" select="tokenize($cols,',')"/> |
---|
49 | <xsl:for-each select="$colarray" > |
---|
50 | <col key="{.}" label="{replace(.,'^.*\.([^.]+)$','$1')}" xpath="{replace(.,'\.','/')}" /> |
---|
51 | <!-- if (contains(.,'.')) then reverse(.) else . --> |
---|
52 | </xsl:for-each> |
---|
53 | <xsl:if test="count($colarray)=0" > |
---|
54 | <xsl:copy-of select="$autocolumns"></xsl:copy-of> |
---|
55 | <xsl:message>AUTOCOLUMNS: <xsl:copy-of select="$autocolumns" /><xsl:value-of select="count($autocolumns)" /></xsl:message> |
---|
56 | </xsl:if> |
---|
57 | |
---|
58 | </xsl:variable> |
---|
59 | |
---|
60 | <xsl:variable name="autocolumns" > |
---|
61 | <xsl:variable name="precompute"> |
---|
62 | <xsl:for-each-group select="//Components//*[not(*)][exists(text())]" group-by="name()" > |
---|
63 | <xsl:sort select="sum(current-group()/string-length(string-join(text(),';')))" order="descending" /> |
---|
64 | <!-- <xsl:message>precomputing: <xsl:value-of select="name()" /> |
---|
65 | count: <xsl:value-of select="count(current-group())" /> sum:<xsl:value-of select="sum(current-group()/string-length(string-join(text(),';')))" /></xsl:message> --> |
---|
66 | <col key="{name()}" label="{name()}" xpath="{name()}" /> |
---|
67 | </xsl:for-each-group> |
---|
68 | </xsl:variable> |
---|
69 | <!-- <xsl:message>precompute: <xsl:copy-of select="$precompute" /><xsl:value-of select="count($precompute)" /></xsl:message>--> |
---|
70 | <xsl:copy-of select="$precompute/*[position() < $autocolumns_limit]"></xsl:copy-of> |
---|
71 | </xsl:variable> |
---|
72 | |
---|
73 | <xsl:template name="continue-root" > |
---|
74 | |
---|
75 | <xsl:for-each select="searchRetrieveResponse" > |
---|
76 | <xsl:call-template name="header" /> |
---|
77 | <xsl:choose> |
---|
78 | <xsl:when test="contains($format,'htmltable')"> |
---|
79 | <xsl:apply-templates select="records" mode="table" /> |
---|
80 | </xsl:when> |
---|
81 | <xsl:when test="contains($format,'htmllist')"> |
---|
82 | <xsl:apply-templates select="records" mode="list" /> |
---|
83 | </xsl:when> |
---|
84 | <xsl:when test="contains($format, 'htmldetail')"> |
---|
85 | <xsl:apply-templates select="records" mode="detail" /> |
---|
86 | </xsl:when> |
---|
87 | <xsl:when test="contains($format, 'htmlpage')"> |
---|
88 | <xsl:apply-templates select="records" mode="detail" /> |
---|
89 | </xsl:when> |
---|
90 | <xsl:otherwise>mdset2view: unrecognized format: <xsl:value-of select="$format" /></xsl:otherwise> |
---|
91 | </xsl:choose> |
---|
92 | </xsl:for-each> |
---|
93 | |
---|
94 | </xsl:template> |
---|
95 | |
---|
96 | |
---|
97 | <xsl:template match="*" > |
---|
98 | <!-- <xsl:param name="lv" select="1" />--> |
---|
99 | <!--<xsl:variable name="lv" select="count(ancestor::d)" /> --> |
---|
100 | <xsl:if test="string-length(.//text()) > 1" > |
---|
101 | <xsl:variable name="has_text" > |
---|
102 | <xsl:choose> |
---|
103 | <xsl:when test="normalize-space(text())='Unspecified'">unspecified</xsl:when> |
---|
104 | <xsl:when test="not(normalize-space(text())='')">text</xsl:when> |
---|
105 | <xsl:otherwise>empty</xsl:otherwise> |
---|
106 | </xsl:choose> |
---|
107 | |
---|
108 | </xsl:variable> |
---|
109 | <div class="elem {$has_text}" ><span class="elem_name"><xsl:value-of select="name()" />:</span> |
---|
110 | <span class="elem_value"><xsl:value-of select="text()" /></span> |
---|
111 | <xsl:apply-templates select="*" /> |
---|
112 | </div> |
---|
113 | </xsl:if> |
---|
114 | </xsl:template> |
---|
115 | |
---|
116 | <!-- |
---|
117 | sample header: |
---|
118 | <numberOfRecords>524</numberOfRecords> |
---|
119 | <echoedSearchRetrieveRequest>//Title[contains(.,'an')] /db/cmdi-mirror/silang_data 1 50</echoedSearchRetrieveRequest> |
---|
120 | <diagnostics>50</diagnostics> |
---|
121 | --> |
---|
122 | <xsl:template name="header"> |
---|
123 | <div class="result-header" > |
---|
124 | <xsl:attribute name="max_value"><xsl:value-of select="numberOfRecords" /></xsl:attribute> |
---|
125 | <xsl:variable name="cnt_hits" select="number(diagnostics)" /> |
---|
126 | <span class="label" >hits: </span><span class="value hilight"><xsl:value-of select="numberOfRecords" /></span>; |
---|
127 | <span class="label" >from:</span><span><input type="text" class="value start_record paging-input"><xsl:attribute name="value"> |
---|
128 | <xsl:value-of select="$startRecord"/> |
---|
129 | </xsl:attribute> |
---|
130 | </input></span> |
---|
131 | <span class="label" >max:</span><span><input type="text" class="value maximum_records paging-input" ><xsl:attribute name="value"> |
---|
132 | <xsl:value-of select="if(number($cnt_hits) < number($maximumRecords)) then $cnt_hits else $maximumRecords"/> |
---|
133 | </xsl:attribute></input></span> |
---|
134 | <span class="cmd cmd_reload" /> |
---|
135 | <!-- <button class="reload">reload</button>--> |
---|
136 | <span class="cmd cmd_prev"> |
---|
137 | <xsl:choose> |
---|
138 | <xsl:when test="$startRecord = '1'"> |
---|
139 | <xsl:attribute name="disabled">disabled</xsl:attribute> |
---|
140 | </xsl:when> |
---|
141 | </xsl:choose> |
---|
142 | </span> |
---|
143 | <span class="cmd cmd_next"> |
---|
144 | <xsl:choose> |
---|
145 | <xsl:when test="$maximumRecords > numberOfRecords or $maximumRecords = numberOfRecords"> |
---|
146 | <xsl:attribute name="disabled">disabled</xsl:attribute> |
---|
147 | </xsl:when> |
---|
148 | </xsl:choose> |
---|
149 | </span> |
---|
150 | </div> |
---|
151 | <div class="note" ><span class="label" >echo: </span><span class="value"><xsl:value-of select="echoedSearchRetrieveRequest" /></span>;</div> |
---|
152 | </xsl:template> |
---|
153 | |
---|
154 | <xsl:template match="records" mode="table"> |
---|
155 | |
---|
156 | <table class="show"> |
---|
157 | <thead><tr><th>pos</th> |
---|
158 | <!-- |
---|
159 | <xsl:for-each select="$cols/col" > |
---|
160 | <xsl:for-each select="distinct-values($cols/col/@label)" > |
---|
161 | <th><xsl:value-of select="." /></th> |
---|
162 | </xsl:for-each> |
---|
163 | --> |
---|
164 | <xsl:for-each select="$columns/*"> |
---|
165 | <th title="{@key}" ><xsl:value-of select="@label"/></th> |
---|
166 | </xsl:for-each> |
---|
167 | <th><span class="edit-columns"> edit...</span> </th> |
---|
168 | </tr></thead> |
---|
169 | <tbody> |
---|
170 | <xsl:apply-templates select="CMD" mode="table" /> |
---|
171 | </tbody> |
---|
172 | </table> |
---|
173 | |
---|
174 | </xsl:template> |
---|
175 | |
---|
176 | <xsl:template match="CMD" mode="table"> |
---|
177 | <tr> |
---|
178 | <td> |
---|
179 | <xsl:choose> |
---|
180 | <xsl:when test="exists(.//MdSelfLink)" > |
---|
181 | <a class="internal" href="{concat('record/htmldetail/', my:encodePID(.//MdSelfLink))}" > |
---|
182 | <xsl:value-of select="position()" /> |
---|
183 | </a> |
---|
184 | <span class="cmd cmd_detail" ></span> |
---|
185 | <span class="cmd cmd_save" ></span> |
---|
186 | </xsl:when> |
---|
187 | <xsl:otherwise><xsl:value-of select="position()" /></xsl:otherwise> |
---|
188 | </xsl:choose> |
---|
189 | </td> |
---|
190 | <xsl:variable name="curr_cmd" select="." /> |
---|
191 | <!-- <xsl:for-each select="$cols/col" > |
---|
192 | <td ><xsl:value-of select="$curr_cmd//*[name()=current()]" /></td> |
---|
193 | <xsl:for-each select="distinct-values($cols/col/@label)" > |
---|
194 | <td > |
---|
195 | <xsl:value-of select="$curr_cmd//*[name()=current()]" /> |
---|
196 | <xsl:for-each select="$cols/col[@label=current()]" > |
---|
197 | <xsl:variable name="curr_col_xpath" select="text()" /> |
---|
198 | |
---|
199 | <xsl:message><xsl:value-of select="$curr_col_xpath" /></xsl:message> |
---|
200 | |
---|
201 | <xsl:for-each select="$curr_cmd" > |
---|
202 | <xsl:value-of select="saxon:evaluate(concat('.//', $curr_col_xpath))" /> |
---|
203 | </xsl:for-each> |
---|
204 | </xsl:for-each> |
---|
205 | </td> |
---|
206 | </xsl:for-each> |
---|
207 | --> |
---|
208 | |
---|
209 | <xsl:for-each select="$columns/*"> |
---|
210 | <!-- <td ><xsl:value-of select="$curr_cmd//*[name()=current()]" /></td> --> |
---|
211 | <xsl:variable name="curr_col_xpath" select="@xpath" /> |
---|
212 | <td> |
---|
213 | <xsl:for-each select="$curr_cmd"> |
---|
214 | <xsl:call-template name="format-field" > |
---|
215 | <xsl:with-param name="elems" select="saxon:evaluate(concat('.//', $curr_col_xpath))" /> |
---|
216 | </xsl:call-template> |
---|
217 | |
---|
218 | </xsl:for-each> |
---|
219 | </td> |
---|
220 | </xsl:for-each> |
---|
221 | </tr> |
---|
222 | </xsl:template> |
---|
223 | |
---|
224 | |
---|
225 | </xsl:stylesheet> |
---|