source: sandbox/expresso-solr/solr/example/example-DIH/solr/db/conf/xslt/luke.xsl @ 7588

Revision 7588, 14.5 KB checked in by adir, 11 years ago (diff)

Ticket #000 - Adicionando a integracao de buscas com Solr na base a ser isnerida na comunidade

Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3    Licensed to the Apache Software Foundation (ASF) under one or more
4    contributor license agreements.  See the NOTICE file distributed with
5    this work for additional information regarding copyright ownership.
6    The ASF licenses this file to You under the Apache License, Version 2.0
7    (the "License"); you may not use this file except in compliance with
8    the License.  You may obtain a copy of the License at
9   
10    http://www.apache.org/licenses/LICENSE-2.0
11   
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17-->
18
19
20<!--
21  Display the luke request handler with graphs
22 -->
23<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
24    xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" version="1.0">
25    <xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
26        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" encoding="UTF-8"/>
27
28    <xsl:variable name="title">Solr Luke Request Handler Response</xsl:variable>
29
30    <xsl:template match="/">
31        <html xmlns="http://www.w3.org/1999/xhtml">
32            <head>
33                <title>
34                    <xsl:value-of select="$title"/>
35                </title>
36                <!-- <xsl:call-template name="svg_ie_workaround"/> -->
37                <xsl:call-template name="css"/>
38                <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"/>
39            </head>
40            <body>
41                <h1>
42                    <xsl:value-of select="$title"/>
43                </h1>
44                <div class="doc">
45                    <ul>
46                        <xsl:if test="response/lst[@name='index']">
47                            <li>
48                                <a href="#index">Index Statistics</a>
49                            </li>
50                        </xsl:if>
51                        <xsl:if test="response/lst[@name='fields']">
52                            <li>
53                                <a href="#fields">Field Statistics</a>
54                            </li>
55                            <li>
56                                <ul>
57                                    <xsl:for-each select="response/lst[@name='fields']/lst">
58                                        <li>
59                                            <a href="#{@name}">
60                                                <xsl:value-of select="@name"/>
61                                            </a>
62                                        </li>
63                                    </xsl:for-each>
64                                </ul>
65                            </li>
66                        </xsl:if>
67                        <xsl:if test="response/lst[@name='doc']">
68                            <li>
69                                <a href="#doc">Document statistics</a>
70                            </li>
71                        </xsl:if>
72                    </ul>
73                </div>
74                <xsl:if test="response/lst[@name='index']">
75                    <h2><a name="index"/>Index statistics</h2>
76                    <xsl:apply-templates select="response/lst[@name='index']"/>
77                </xsl:if>
78                <xsl:if test="response/lst[@name='fields']">
79                    <h2><a name="fields"/>Field statistics</h2>
80                    <xsl:apply-templates select="response/lst[@name='fields']"/>
81                </xsl:if>
82                <xsl:if test="response/lst[@name='doc']">
83                    <h2><a name="doc"/>Document statistics</h2>
84                    <xsl:apply-templates select="response/lst[@name='doc']"/>
85                </xsl:if>
86            </body>
87        </html>
88    </xsl:template>
89
90    <xsl:template match="lst">
91        <xsl:if test="parent::lst">
92            <tr>
93                <td colspan="2">
94                    <div class="doc">
95                        <xsl:call-template name="list"/>
96                    </div>
97                </td>
98            </tr>
99        </xsl:if>
100        <xsl:if test="not(parent::lst)">
101            <div class="doc">
102                <xsl:call-template name="list"/>
103            </div>
104        </xsl:if>
105    </xsl:template>
106
107    <xsl:template name="list">
108        <xsl:if test="count(child::*)>0">
109            <table>
110                <thead>
111                    <tr>
112                        <th colspan="2">
113                            <p>
114                                <a name="{@name}"/>
115                            </p>
116                            <xsl:value-of select="@name"/>
117                        </th>
118                    </tr>
119                </thead>
120                <tbody>
121                    <xsl:choose>
122                        <xsl:when
123                            test="@name='histogram' and not(system-property('xsl:vendor')='Microsoft')">
124                            <tr>
125                                <td colspan="2">
126                                    <xsl:call-template name="histogram"/>
127                                </td>
128                            </tr>
129                        </xsl:when>
130                        <xsl:otherwise>
131                            <xsl:apply-templates/>
132                        </xsl:otherwise>
133                    </xsl:choose>
134                </tbody>
135            </table>
136        </xsl:if>
137    </xsl:template>
138
139    <xsl:template name="histogram">
140        <div class="doc">
141            <xsl:call-template name="barchart">
142                <xsl:with-param name="xoffset">5</xsl:with-param>
143                <xsl:with-param name="yoffset">5</xsl:with-param>
144                <xsl:with-param name="iwidth">800</xsl:with-param>
145                <xsl:with-param name="iheight">600</xsl:with-param>
146                <xsl:with-param name="fill">blue</xsl:with-param>
147            </xsl:call-template>
148        </div>
149    </xsl:template>
150
151    <xsl:template name="barchart">
152        <xsl:param name="xoffset"/>
153        <xsl:param name="yoffset"/>
154        <xsl:param name="iwidth"/>
155        <xsl:param name="iheight"/>
156        <xsl:param name="fill"/>
157        <svg:svg viewBox="0 0 {$iwidth} {$iheight}">
158            <xsl:if test="system-property('xsl:vendor')='Opera' or system-property('xsl:vendor')='libxslt'">
159                <xsl:attribute name="width"><xsl:value-of select="$iwidth"/></xsl:attribute>
160                <xsl:attribute name="height"><xsl:value-of select="$iwidth"/></xsl:attribute>
161            </xsl:if>
162            <xsl:variable name="x" select="$xoffset + 5"/>
163            <xsl:variable name="y" select="$yoffset + 5"/>
164            <xsl:variable name="width" select="$iwidth - 10"/>
165            <xsl:variable name="height" select="$iheight - 30"/>
166            <xsl:variable name="max">
167                <xsl:for-each select="int">
168                    <xsl:sort data-type="number" order="descending"/>
169                    <xsl:if test="position()=1">
170                        <xsl:value-of select="."/>
171                    </xsl:if>
172                </xsl:for-each>
173            </xsl:variable>
174            <xsl:variable name="yRatio" select="$height div $max"/>
175            <xsl:variable name="xRatio" select="$width div count(int)"/>
176            <svg:g>
177                <xsl:for-each select="int">
178                    <svg:rect stroke="none" x="{$x + (position() - 1) * $xRatio + 0.1 * $xRatio}"
179                        y="{($y + $height) - number(.) * $yRatio}" width="{0.8 * $xRatio}"
180                        height="{number(.) * $yRatio}" fill="{$fill}"/>
181                    <xsl:variable name="yboost">
182                        <xsl:choose>
183                            <xsl:when
184                                test="($y + $height) - number(.) * $yRatio +40 &gt; $iheight"
185                                >-25</xsl:when>
186                            <xsl:otherwise>0</xsl:otherwise>
187                        </xsl:choose>
188                    </xsl:variable>
189                    <svg:text
190                        x="{$x + (position() - 1) * $xRatio + 0.1 * $xRatio + (($xRatio * 0.8) div 2)}"
191                        y="{($y + $height) - number(.) * $yRatio +20 + number($yboost)}"
192                        text-anchor="middle" style="fill: red; font-size: 8px;">
193                        <xsl:value-of select="."/>
194                    </svg:text>
195                    <svg:text
196                        x="{$x + (position() - 1) * $xRatio + 0.1 * $xRatio + (($xRatio * 0.8) div 2)}"
197                        y="{$y + $height + 20}" text-anchor="middle" style="fill: black; font-size: 8px;">
198                        <xsl:value-of select="@name"/>
199                    </svg:text>
200                </xsl:for-each>
201            </svg:g>
202        </svg:svg>
203    </xsl:template>
204
205    <xsl:template name="keyvalue">
206        <xsl:choose>
207            <xsl:when test="@name">
208                <tr>
209                    <td class="name">
210                        <xsl:value-of select="@name"/>
211                    </td>
212                    <td class="value">
213                        <xsl:value-of select="."/>
214                    </td>
215                </tr>
216            </xsl:when>
217            <xsl:otherwise>
218                <xsl:value-of select="."/>
219            </xsl:otherwise>
220        </xsl:choose>
221    </xsl:template>
222
223    <xsl:template match="int|bool|long|float|double|uuid|date">
224        <xsl:call-template name="keyvalue"/>
225    </xsl:template>
226
227    <xsl:template match="arr">
228        <tr>
229            <td class="name">
230                <xsl:value-of select="@name"/>
231            </td>
232            <td class="value">
233                <ul>
234                    <xsl:for-each select="child::*">
235                        <li>
236                            <xsl:apply-templates/>
237                        </li>
238                    </xsl:for-each>
239                </ul>
240            </td>
241        </tr>
242    </xsl:template>
243
244    <xsl:template match="str">
245        <xsl:choose>
246            <xsl:when test="@name='schema' or @name='index' or @name='flags'">
247                <xsl:call-template name="schema"/>
248            </xsl:when>
249            <xsl:otherwise>
250                <xsl:call-template name="keyvalue"/>
251            </xsl:otherwise>
252        </xsl:choose>
253    </xsl:template>
254
255    <xsl:template name="schema">
256        <tr>
257            <td class="name">
258                <xsl:value-of select="@name"/>
259            </td>
260            <td class="value">
261                <xsl:if test="contains(.,'unstored')">
262                    <xsl:value-of select="."/>
263                </xsl:if>
264                <xsl:if test="not(contains(.,'unstored'))">
265                    <xsl:call-template name="infochar2string">
266                        <xsl:with-param name="charList">
267                            <xsl:value-of select="."/>
268                        </xsl:with-param>
269                    </xsl:call-template>
270                </xsl:if>
271            </td>
272        </tr>
273    </xsl:template>
274
275    <xsl:template name="infochar2string">
276        <xsl:param name="i">1</xsl:param>
277        <xsl:param name="charList"/>
278
279        <xsl:variable name="char">
280            <xsl:value-of select="substring($charList,$i,1)"/>
281        </xsl:variable>
282        <xsl:choose>
283            <xsl:when test="$char='I'">
284                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='I']"/> - </xsl:when>
285            <xsl:when test="$char='T'">
286                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='T']"/> - </xsl:when>
287            <xsl:when test="$char='S'">
288                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='S']"/> - </xsl:when>
289            <xsl:when test="$char='M'">
290                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='M']"/> - </xsl:when>
291            <xsl:when test="$char='V'">
292                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='V']"/> - </xsl:when>
293            <xsl:when test="$char='o'">
294                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='o']"/> - </xsl:when>
295            <xsl:when test="$char='p'">
296                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='p']"/> - </xsl:when>
297            <xsl:when test="$char='O'">
298                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='O']"/> - </xsl:when>
299            <xsl:when test="$char='L'">
300                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='L']"/> - </xsl:when>
301            <xsl:when test="$char='B'">
302                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='B']"/> - </xsl:when>
303            <xsl:when test="$char='C'">
304                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='C']"/> - </xsl:when>
305            <xsl:when test="$char='f'">
306                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='f']"/> - </xsl:when>
307            <xsl:when test="$char='l'">
308                <xsl:value-of select="/response/lst[@name='info']/lst/str[@name='l']"/> -
309            </xsl:when>
310        </xsl:choose>
311
312        <xsl:if test="not($i>=string-length($charList))">
313            <xsl:call-template name="infochar2string">
314                <xsl:with-param name="i">
315                    <xsl:value-of select="$i+1"/>
316                </xsl:with-param>
317                <xsl:with-param name="charList">
318                    <xsl:value-of select="$charList"/>
319                </xsl:with-param>
320            </xsl:call-template>
321        </xsl:if>
322    </xsl:template>
323    <xsl:template name="css">
324        <style type="text/css">
325            <![CDATA[
326            body { font-family: "Lucida Grande", sans-serif }
327            td.name {font-style: italic; font-size:80%; }
328            th { font-style: italic; font-size: 80%; background-color: lightgrey; }
329            td { vertical-align: top; }
330            ul { margin: 0px; margin-left: 1em; padding: 0px; }
331            table { width: 100%; border-collapse: collapse; }
332            .note { font-size:80%; }
333            .doc { margin: 0.5em; border: solid grey 1px; }
334            .exp { display: none; font-family: monospace; white-space: pre; }
335            ]]>
336        </style>
337    </xsl:template>
338    <xsl:template name="svg_ie_workaround">
339        <xsl:if test="system-property('xsl:vendor')='Microsoft'">
340            <object id="AdobeSVG" classid="clsid:78156a80-c6a1-4bbf-8e6a-3cd390eeb4e2"/>
341            <xsl:processing-instruction name="import">namespace="svg"
342            implementation="#AdobeSVG"</xsl:processing-instruction>
343        </xsl:if>
344    </xsl:template>
345</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.