source: gs3-extensions/solr/trunk/src/conf/xslt/example.xsl@ 29135

Last change on this file since 29135 was 29135, checked in by ak19, 10 years ago

Part of port from lucene3.3.0 to lucene4.7.2. Solr related. conf and lib folders for solr4.7.2.

File size: 4.0 KB
Line 
1<?xml version='1.0' encoding='UTF-8'?>
2
3<!--
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 -->
19
20<!--
21 Simple transform of Solr query results to HTML
22 -->
23<xsl:stylesheet version='1.0'
24 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
25>
26
27 <xsl:output media-type="text/html" encoding="UTF-8"/>
28
29 <xsl:variable name="title" select="concat('Solr search results (',response/result/@numFound,' documents)')"/>
30
31 <xsl:template match='/'>
32 <html>
33 <head>
34 <title><xsl:value-of select="$title"/></title>
35 <xsl:call-template name="css"/>
36 </head>
37 <body>
38 <h1><xsl:value-of select="$title"/></h1>
39 <div class="note">
40 This has been formatted by the sample "example.xsl" transform -
41 use your own XSLT to get a nicer page
42 </div>
43 <xsl:apply-templates select="response/result/doc"/>
44 </body>
45 </html>
46 </xsl:template>
47
48 <xsl:template match="doc">
49 <xsl:variable name="pos" select="position()"/>
50 <div class="doc">
51 <table width="100%">
52 <xsl:apply-templates>
53 <xsl:with-param name="pos"><xsl:value-of select="$pos"/></xsl:with-param>
54 </xsl:apply-templates>
55 </table>
56 </div>
57 </xsl:template>
58
59 <xsl:template match="doc/*[@name='score']" priority="100">
60 <xsl:param name="pos"></xsl:param>
61 <tr>
62 <td class="name">
63 <xsl:value-of select="@name"/>
64 </td>
65 <td class="value">
66 <xsl:value-of select="."/>
67
68 <xsl:if test="boolean(//lst[@name='explain'])">
69 <xsl:element name="a">
70 <!-- can't allow whitespace here -->
71 <xsl:attribute name="href">javascript:toggle("<xsl:value-of select="concat('exp-',$pos)" />");</xsl:attribute>?</xsl:element>
72 <br/>
73 <xsl:element name="div">
74 <xsl:attribute name="class">exp</xsl:attribute>
75 <xsl:attribute name="id">
76 <xsl:value-of select="concat('exp-',$pos)" />
77 </xsl:attribute>
78 <xsl:value-of select="//lst[@name='explain']/str[position()=$pos]"/>
79 </xsl:element>
80 </xsl:if>
81 </td>
82 </tr>
83 </xsl:template>
84
85 <xsl:template match="doc/arr" priority="100">
86 <tr>
87 <td class="name">
88 <xsl:value-of select="@name"/>
89 </td>
90 <td class="value">
91 <ul>
92 <xsl:for-each select="*">
93 <li><xsl:value-of select="."/></li>
94 </xsl:for-each>
95 </ul>
96 </td>
97 </tr>
98 </xsl:template>
99
100
101 <xsl:template match="doc/*">
102 <tr>
103 <td class="name">
104 <xsl:value-of select="@name"/>
105 </td>
106 <td class="value">
107 <xsl:value-of select="."/>
108 </td>
109 </tr>
110 </xsl:template>
111
112 <xsl:template match="*"/>
113
114 <xsl:template name="css">
115 <script>
116 function toggle(id) {
117 var obj = document.getElementById(id);
118 obj.style.display = (obj.style.display != 'block') ? 'block' : 'none';
119 }
120 </script>
121 <style type="text/css">
122 body { font-family: "Lucida Grande", sans-serif }
123 td.name { font-style: italic; font-size:80%; }
124 td { vertical-align: top; }
125 ul { margin: 0px; margin-left: 1em; padding: 0px; }
126 .note { font-size:80%; }
127 .doc { margin-top: 1em; border-top: solid grey 1px; }
128 .exp { display: none; font-family: monospace; white-space: pre; }
129 </style>
130 </xsl:template>
131
132</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.