source: MDService2/branches/MDService_simple3/src/xsl/fcs/result2view_v1.xsl @ 1918

Last change on this file since 1918 was 1918, checked in by gaba, 12 years ago

autocomplete - explain.xml

File size: 7.7 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:diag="http://www.loc.gov/zing/srw/diagnostic/" xmlns:saxon="http://saxon.sf.net/" xmlns:sru="http://www.loc.gov/zing/srw/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fcs="http://clarin.eu/fcs/1.0" xmlns:exsl="http://exslt.org/common" version="1.0" exclude-result-prefixes="saxon xs exsl diag sru fcs">
3<!--   
4    <purpose> generate html view of a sru-result-set  (eventually in various formats).</purpose>
5<history> 
6<change on="2011-12-06" type="created" by="vr">based on cmdi/scripts/mdset2view.xsl retrofitted for XSLT 1.0</change>  
7</history>
8-->   
9    <!--  method="xhtml" is saxon-specific! prevents  collapsing empty <script> tags, that makes browsers choke -->
10    <xsl:output method="xml" media-type="text/xhtml" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
11    <xsl:include href="commons_v1.xsl"/>
12    <xsl:include href="data2view.xsl"/>
13    <xsl:param name="mode" select="'html'"/>
14    <xsl:param name="title">
15        <xsl:text>Result Set</xsl:text>
16    </xsl:param>
17    <xsl:variable name="cols">
18        <col>all</col>
19    </xsl:variable>
20    <xsl:template name="continue-root">
21        <xsl:for-each select="sru:searchRetrieveResponse">
22            <xsl:apply-templates select="sru:diagnostics"/>
23            <div>
24                <xsl:if test="contains($format, 'htmlpage')">
25                    <xsl:call-template name="header"/>
26                </xsl:if>
27                                <xsl:apply-templates select="sru:records" mode="list"/>   
28                                <!-- switch mode depending on the $format-parameter -->       
29                <!--<xsl:choose>
30                    <xsl:when test="contains($format,'htmltable')">
31                        <xsl:apply-templates select="records" mode="table"/>
32                    </xsl:when>
33                    <xsl:when test="contains($format,'htmllist')">
34                        <xsl:apply-templates select="records" mode="list"/>
35                    </xsl:when>
36                    <xsl:when test="contains($format, 'htmlpagelist')">
37                        <xsl:apply-templates select="records" mode="list"/>
38                    </xsl:when>
39                    <xsl:otherwise>mdset2view: unrecognized format: <xsl:value-of select="$format"/>
40                    </xsl:otherwise>
41                </xsl:choose>-->
42            </div>
43        </xsl:for-each>
44    </xsl:template>
45    <xsl:template name="header">
46        <div class="result-header" data-numberOfRecords="{$numberOfRecords}">
47            <xsl:if test="contains($format, 'page')">
48                <xsl:call-template name="query-input"/>
49            </xsl:if>
50            <span class="label">showing </span>
51            <span class="value hilight">
52                <xsl:value-of select="sru:extraResponseData/fcs:returnedRecords"/>
53            </span>
54            <span class="label">out of </span>
55            <span class="value hilight">
56                <xsl:value-of select="$numberOfRecords"/>
57            </span>
58            <span class="label">hits</span>
59            <div class="note">
60                <xsl:for-each select="(sru:echoedSearchRetrieveRequest/*|sru:extraResponseData/*)">
61                    <span class="label">
62                        <xsl:value-of select="name()"/>: </span>
63                    <span class="value">
64                        <xsl:value-of select="."/>
65                    </span>;
66                </xsl:for-each>
67                <!--<span class="label">duration: </span>
68                <span class="value">
69                    <xsl:value-of select="sru:extraResponseData/fcs:duration"/>
70                    </span>;-->
71            </div>
72        </div>
73    </xsl:template>
74    <xsl:template match="sru:records" mode="list">
75        <table class="show">
76            <thead>
77                <tr>
78                    <th>pos</th>
79                    <th>record</th>
80                </tr>
81            </thead>
82            <tbody>
83                <xsl:apply-templates select="sru:record" mode="list"/>
84            </tbody>
85        </table>
86    </xsl:template>
87    <xsl:template match="sru:record" mode="list">
88        <xsl:variable name="curr_record" select="."/>
89        <xsl:variable name="fields">
90            <div>
91                <xsl:apply-templates select="*" mode="record-data"/>
92            </div>
93        </xsl:variable>
94        <xsl:call-template name="record-table-row">
95            <xsl:with-param name="fields" select="$fields"/>
96        </xsl:call-template>
97    </xsl:template>
98    <xsl:template name="record-table-row">
99        <xsl:param name="fields"/>
100<!-- @field absolute_position compute records position over whole recordset, ie add `startRecord` (important when paging)
101 -->
102        <xsl:variable name="absolute_position">
103            <xsl:choose>
104        <!--      CHECK: Does this check if $startRecord is a number, or is it an error?          -->
105                <xsl:when test="number($startRecord)=number($startRecord)">
106                    <xsl:value-of select="number($startRecord) + position() - 1"/>
107                </xsl:when>
108                <xsl:otherwise>
109                    <xsl:value-of select="position()"/>
110                </xsl:otherwise>
111            </xsl:choose>
112        </xsl:variable>
113        <xsl:variable name="rec_uri">
114            <xsl:choose>
115                <xsl:when test=".//sru:recordIdentifier">
116                    <xsl:value-of select=".//sru:recordIdentifier"/>
117                </xsl:when>
118                <xsl:when test=".//fcs:Resource/@ref">
119                    <xsl:value-of select=".//fcs:Resource/@ref"/>
120                </xsl:when>
121                <xsl:otherwise>
122                    <!-- TODO: this won't work yet, the idea is to deliver only the one record as a fall-back
123                        (i.e. when there is no other view, no further link) supplied for the Resource) -->
124                    <xsl:call-template name="formURL">
125                        <xsl:with-param name="action" select="'record'"/>
126                        <xsl:with-param name="q" select="$absolute_position"/>
127                    </xsl:call-template>
128                </xsl:otherwise>
129            </xsl:choose>
130        </xsl:variable>
131        <tr>
132            <td rowspan="2" valign="top">
133                <xsl:choose>
134                    <xsl:when test="$rec_uri">
135                           <!-- it was: htmlsimple, htmltable -link-to-> htmldetail; otherwise -> htmlpage -->
136<!--                        <a class="internal" href="{my:formURL('record', $format, my:encodePID(.//recordIdentifier))}">-->
137                        <a class="internal" href="{$rec_uri}">
138                            <xsl:value-of select="$absolute_position"/>
139                        </a>                         
140<!--                        <span class="cmd cmd_save"/>-->
141                    </xsl:when>
142                    <xsl:otherwise>
143<!-- FIXME: generic link somewhere anyhow! -->
144                        <xsl:value-of select="$absolute_position"/>
145                    </xsl:otherwise>
146                </xsl:choose>
147            </td>
148            <td>
149                <!--
150                    TODO: handle context
151                    <xsl:call-template name="getContext"/>-->
152                <div class="title">
153                    <xsl:call-template name="getTitle"/>
154                </div>
155            </td>
156        </tr>
157        <tr>
158            <td>
159                <xsl:copy-of select="$fields"/>
160            </td>
161        </tr>
162    </xsl:template>
163    <xsl:template match="sru:diagnostics">
164        <div class="error">
165            <xsl:apply-templates/>
166        </div>
167    </xsl:template>
168    <xsl:template match="diag:diagnostic">
169        <xsl:value-of select="diag:message"/> (<xsl:value-of select="diag:uri"/>)
170    </xsl:template>
171</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.