1 <?xml version='1.0' encoding='UTF-8'?>
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 Simple transform of Solr query results to HTML
23 <xsl:stylesheet version='1.0'
24 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
27 <xsl:output media-type="text/html" encoding="UTF-8"/>
29 <xsl:variable name="title" select="concat('Solr search results (',response/result/@numFound,' documents)')"/>
31 <xsl:template match='/'>
34 <title><xsl:value-of select="$title"/></title>
35 <xsl:call-template name="css"/>
38 <h1><xsl:value-of select="$title"/></h1>
40 This has been formatted by the sample "example.xsl" transform -
41 use your own XSLT to get a nicer page
43 <xsl:apply-templates select="response/result/doc"/>
48 <xsl:template match="doc">
49 <xsl:variable name="pos" select="position()"/>
53 <xsl:with-param name="pos"><xsl:value-of select="$pos"/></xsl:with-param>
54 </xsl:apply-templates>
59 <xsl:template match="doc/*[@name='score']" priority="100">
60 <xsl:param name="pos"></xsl:param>
63 <xsl:value-of select="@name"/>
66 <xsl:value-of select="."/>
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>
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)" />
78 <xsl:value-of select="//lst[@name='explain']/str[position()=$pos]"/>
85 <xsl:template match="doc/arr" priority="100">
88 <xsl:value-of select="@name"/>
92 <xsl:for-each select="*">
93 <li><xsl:value-of select="."/></li>
101 <xsl:template match="doc/*">
104 <xsl:value-of select="@name"/>
107 <xsl:value-of select="."/>
112 <xsl:template match="*"/>
114 <xsl:template name="css">
116 function toggle(id) {
117 var obj = document.getElementById(id);
118 obj.style.display = (obj.style.display != 'block') ? 'block' : 'none';
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; }