source: MDService2/branches/MDService_simple3/src/xsl/fcs/commons_v1.xsl @ 1814

Last change on this file since 1814 was 1814, checked in by vronk, 12 years ago

correction in handling scan:fcs.resource and its usage in contexts-selectlist

File size: 11.7 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sru="http://www.loc.gov/zing/srw/" xmlns:fcs="http://clarin.eu/fcs/1.0" version="1.0">
3
4<!--
5<purpose>generic functions for SRU-result handling</purpose>
6<history>
7        <change on="2011-12-04" type="created" by="vr">based on cmd_functions.xsl but retrofitted back to 1.0</change>
8</history>
9
10-->
11    <xsl:include href="params.xsl"/>
12    <xsl:include href="html_snippets.xsl"/>
13
14<!-- <xsl:param name="mode" select="'html'" /> -->
15    <xsl:param name="dict_file" select="'dict.xml'"/>
16    <xsl:variable name="dict" select="document($dict_file)"/>
17    <xsl:variable name="contexts" select="document($contexts_url)"/>
18   
19        <!-- common starting point for all stylesheet; cares for unified html-envelope
20                and passes back to the individual stylesheets for the content (via template: continue-root) -->
21    <xsl:template match="/">
22                <!--<xsl:message>root_document-uri:<xsl:value-of select="$root_uri"/>
23                        </xsl:message>
24                        <xsl:message>format:<xsl:value-of select="$format"/>
25                        </xsl:message>-->
26        <xsl:choose>
27            <xsl:when test="contains($format,'htmlpage')">
28                <xsl:call-template name="html"/>
29            </xsl:when>
30            <xsl:when test="contains($format,'htmljspage')">
31                <xsl:call-template name="htmljs"/>
32            </xsl:when>
33            <xsl:when test="contains($format,'htmlsimple')">
34                <xsl:call-template name="htmlsimple"/>
35            </xsl:when>
36            <xsl:otherwise>
37                <xsl:call-template name="continue-root"/>
38            </xsl:otherwise>
39        </xsl:choose>
40    </xsl:template>
41    <xsl:template name="html">
42        <html xmlns="http://www.w3.org/1999/xhtml">
43            <head>
44                <xsl:call-template name="html-head"/>
45                <xsl:call-template name="callback-header"/>
46            </head>
47            <body>
48                <xsl:call-template name="page-header"/>
49                <h1>
50                    <xsl:value-of select="$title"/>
51                </h1>
52                <xsl:call-template name="continue-root"/>
53            </body>
54        </html>
55    </xsl:template>
56    <xsl:template name="htmljs">
57        <html xmlns="http://www.w3.org/1999/xhtml">
58            <head>
59                <xsl:call-template name="html-head"/>
60                <xsl:call-template name="callback-header"/>
61            </head>
62            <body>
63                <xsl:call-template name="page-header"/>
64                <h1>
65                    <xsl:value-of select="$title"/>
66                </h1>
67                <xsl:call-template name="query-input"/>
68                <xsl:call-template name="query-list"/>
69                <xsl:call-template name="detail-space"/>
70                <xsl:call-template name="public-space"/>
71                <xsl:call-template name="user-space"/>
72                                <!--  <xsl:call-template name="continue-root"/>-->
73            </body>
74        </html>
75    </xsl:template>
76       
77        <!-- a html-envelope for a simple (noscript) view -->
78    <xsl:template name="htmlsimple">
79        <html xmlns="http://www.w3.org/1999/xhtml">
80            <head>
81                <title>
82                    <xsl:value-of select="$title"/>
83                </title>
84                <link href="{$scripts_url}/style/cmds-ui.css" type="text/css" rel="stylesheet"/>                               
85                                <!-- <xsl:call-template name="callback-header"/> -->
86            </head>
87            <xsl:call-template name="page-header"/>
88            <body>               
89                                <!-- <h1><xsl:value-of select="$title"/></h1> -->
90                <xsl:call-template name="continue-root"/>
91            </body>
92        </html>
93    </xsl:template>
94    <xsl:template name="callback-header"/>
95
96   
97    <!-- generates a select-option list of available contexts 
98    -->
99    <xsl:template name="contexts-select">
100       
101        <select name="x-context">       
102            <xsl:for-each select="$contexts//sru:terms/sru:term">
103                <xsl:variable name="ancestors-prefix">
104                    <xsl:for-each select="ancestor::sru:term">
105                        <xsl:text>.</xsl:text>
106                    </xsl:for-each>
107                </xsl:variable>
108                <option value="{sru:value}">
109                    <xsl:if test="sru:value/text() = $x-context">
110                        <xsl:attribute name="selected">selected</xsl:attribute>
111                    </xsl:if>
112                    <xsl:value-of select="concat($ancestors-prefix, sru:displayTerm)"/>
113                </option>
114            </xsl:for-each>
115        </select>
116    </xsl:template>
117   
118       
119        <!-- shall be usable to form consistently all urls within xsl
120        -->
121    <xsl:template name="formURL">
122        <xsl:param name="action" select="'searchRetrieve'"/>
123        <xsl:param name="format" select="$format"/>
124        <xsl:param name="q" select="$q"/>
125        <xsl:param name="startRecord" select="$startRecord"/>
126        <xsl:param name="maximumRecords" select="$maximumRecords"/>
127        <xsl:variable name="param_q">
128            <xsl:if test="$q != ''">
129                <xsl:value-of select="concat('&amp;query=',$q)"/>
130            </xsl:if>
131        </xsl:variable>
132        <xsl:variable name="param_format">
133            <xsl:if test="$format != ''">
134                <xsl:value-of select="concat('&amp;x-format=',$format)"/>
135            </xsl:if>
136        </xsl:variable>
137        <xsl:variable name="param_x-context">
138<!--            if action=explain, handle-q param as x-context-->
139            <xsl:choose>
140                <xsl:when test="$action='explain'">
141                    <xsl:value-of select="concat('&amp;x-context=',$q)"/>
142                </xsl:when>
143                <xsl:when test="$x-context != '' ">
144                    <xsl:value-of select="concat('&amp;x-context=',$x-context)"/>
145                </xsl:when>
146                <xsl:otherwise/>
147            </xsl:choose>
148        </xsl:variable>
149        <xsl:variable name="param_startRecord">
150            <xsl:if test="$startRecord != ''">
151                <xsl:value-of select="concat('&amp;startRecord=',$startRecord)"/>
152            </xsl:if>
153        </xsl:variable>
154        <xsl:variable name="param_maximumRecords">
155            <xsl:if test="$maximumRecords != ''">
156                <xsl:value-of select="concat('&amp;maximumRecords=',$maximumRecords)"/>
157            </xsl:if>
158        </xsl:variable>
159        <xsl:choose>
160            <xsl:when test="$action='explain'">
161                <xsl:value-of select="concat($base_url, '?operation=',$action, $param_x-context, $param_format)"/>
162            </xsl:when>
163            <xsl:otherwise>
164                <xsl:value-of select="concat($base_url, '?operation=',$action, $param_q, $param_x-context, $param_startRecord, $param_maximumRecords, $param_format)"/>
165            </xsl:otherwise>
166        </xsl:choose>               
167         
168        <!--        <xsl:choose>
169            <xsl:when test="$action=''">
170                <xsl:value-of select="concat($base_dir, '?q=', $q, '&repository=', $repository)"/>
171            </xsl:when>
172            <xsl:when test="$q=''">
173                <xsl:value-of select="concat($base_dir, '/',$action, '/', $format)"/>
174            </xsl:when>
175            <xsl:otherwise>
176                <xsl:choose>
177                    <xsl:when test="$action='record'">
178                        <xsl:value-of select="concat($base_dir, '/',$action, '/', $format, '?query=', $q, $param_repository)"/>
179                    </xsl:when>
180                    <xsl:otherwise>
181                        <xsl:value-of select="concat($base_dir, '?operation=',$action, $param_q, $param_repository, $param_startRecord, $param_maximumRecords, $param_format)"/>
182                    </xsl:otherwise>
183                </xsl:choose>
184            </xsl:otherwise>
185        </xsl:choose>
186-->
187    </xsl:template>
188    <xsl:template name="format-field">
189        <xsl:param name="elems"/>
190        <xsl:choose>
191            <xsl:when test="$elems/*">
192                <xsl:apply-templates select="$elems" mode="format-xmlelem"/>
193            </xsl:when>
194            <xsl:when test="count($elems) &gt; 1">
195                <ul>
196                    <xsl:for-each select="$elems">
197                        <li>
198                            <xsl:call-template name="format-value"/>
199                        </li>
200                    </xsl:for-each>
201                </ul>
202            </xsl:when>
203            <xsl:otherwise>
204                <xsl:call-template name="format-value">
205                    <xsl:with-param name="value" select="$elems"/>
206                </xsl:call-template>
207            </xsl:otherwise>
208        </xsl:choose>
209    </xsl:template>
210    <xsl:template name="format-value">
211        <xsl:param name="value" select="."/>
212                <!-- cnt_value:<xsl:value-of select="count($value)" />  -->
213        <xsl:choose>
214            <xsl:when test="starts-with($value[1], 'http:') ">
215                <a target="_blank" class="external" href="{$value}">
216                    <xsl:value-of select="$value"/>
217                </a>
218            </xsl:when>
219            <xsl:otherwise>
220                <xsl:value-of select="$value"/>
221            </xsl:otherwise>
222        </xsl:choose>
223    </xsl:template>
224       
225        <!--generic html-view for xml-elements -->
226    <xsl:template match="*" mode="format-xmlelem">
227        <xsl:if test=".//text() or @*">
228            <xsl:variable name="has_text">
229                <xsl:choose>
230                    <xsl:when test="normalize-space(text()[1])='Unspecified'">unspecified</xsl:when>
231                    <xsl:when test="not(normalize-space(.//text())='')">text</xsl:when>
232                    <xsl:otherwise>empty</xsl:otherwise>
233                </xsl:choose>
234            </xsl:variable>
235            <xsl:variable name="has_children">
236                <xsl:choose>
237                    <xsl:when test="*">has-children</xsl:when>
238                    <xsl:otherwise/>
239                </xsl:choose>
240            </xsl:variable>
241            <div class="cmds-xmlelem {$has_children} value-{$has_text}">
242                <span class="label">
243                    <xsl:value-of select="name()"/>:</span>
244                <span class="value">
245                    <xsl:call-template name="format-value">
246                        <xsl:with-param name="value" select="text()[.!='']"/>
247                    </xsl:call-template>
248                </span>
249                <xsl:apply-templates select="*" mode="format-xmlelem"/>
250                <xsl:if test="@*">
251                    <div class="attributes">
252                        <xsl:apply-templates select="@*" mode="format-attr"/>
253                    </div>
254                </xsl:if>
255            </div>
256        </xsl:if>
257    </xsl:template>
258    <xsl:template match="@*" mode="format-attr">
259        <span class="label">@<xsl:value-of select="name()"/>: </span>
260        <span class="value">
261            <xsl:call-template name="format-value"/><!--<xsl:value-of select="." /> -->
262        </span>;
263        </xsl:template>
264       
265        <!--  previously known as comppath -->
266    <xsl:template name="xml-context">
267        <xsl:param name="child"/>
268        <xsl:variable name="collect">
269            <xsl:for-each select="$child/ancestor::CMD_Component|$child/ancestor::Term">
270                <xsl:value-of select="@name"/>.</xsl:for-each>
271            <xsl:value-of select="$child/@name"/>
272        </xsl:variable>
273        <xsl:value-of select="$collect"/>
274    </xsl:template>
275    <xsl:template name="dict">
276        <xsl:param name="key"/>
277        <xsl:param name="fallback" select="$key"/>
278        <xsl:choose>
279            <xsl:when test="$dict/list/item[@key=$key]">
280                <xsl:value-of select="$dict/list/item[@key=$key]"/>
281            </xsl:when>
282            <xsl:when test="$dict/list/item[.=$key]">
283                <xsl:value-of select="$dict/list/item[.=$key]/@key"/>
284            </xsl:when>
285            <xsl:otherwise>
286                <xsl:value-of select="$fallback"/>
287            </xsl:otherwise>
288        </xsl:choose>
289    </xsl:template>
290</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.