1 | <!-- |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | --> |
---|
17 | |
---|
18 | <!-- |
---|
19 | Simple transform of Solr query response into Solr Update XML compliant XML. |
---|
20 | When used in the xslt response writer you will get UpdaateXML as output. |
---|
21 | But you can also store a query response XML to disk and feed this XML to |
---|
22 | the XSLTUpdateRequestHandler to index the content. Provided as example only. |
---|
23 | See http://wiki.apache.org/solr/XsltUpdateRequestHandler for more info |
---|
24 | --> |
---|
25 | <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> |
---|
26 | <xsl:output media-type="text/xml" method="xml" indent="yes"/> |
---|
27 | |
---|
28 | <xsl:template match='/'> |
---|
29 | <add> |
---|
30 | <xsl:apply-templates select="response/result/doc"/> |
---|
31 | </add> |
---|
32 | </xsl:template> |
---|
33 | |
---|
34 | <!-- Ignore score (makes no sense to index) --> |
---|
35 | <xsl:template match="doc/*[@name='score']" priority="100"> |
---|
36 | </xsl:template> |
---|
37 | |
---|
38 | <xsl:template match="doc"> |
---|
39 | <xsl:variable name="pos" select="position()"/> |
---|
40 | <doc> |
---|
41 | <xsl:apply-templates> |
---|
42 | <xsl:with-param name="pos"><xsl:value-of select="$pos"/></xsl:with-param> |
---|
43 | </xsl:apply-templates> |
---|
44 | </doc> |
---|
45 | </xsl:template> |
---|
46 | |
---|
47 | <!-- Flatten arrays to duplicate field lines --> |
---|
48 | <xsl:template match="doc/arr" priority="100"> |
---|
49 | <xsl:variable name="fn" select="@name"/> |
---|
50 | |
---|
51 | <xsl:for-each select="*"> |
---|
52 | <xsl:element name="field"> |
---|
53 | <xsl:attribute name="name"><xsl:value-of select="$fn"/></xsl:attribute> |
---|
54 | <xsl:value-of select="."/> |
---|
55 | </xsl:element> |
---|
56 | </xsl:for-each> |
---|
57 | </xsl:template> |
---|
58 | |
---|
59 | |
---|
60 | <xsl:template match="doc/*"> |
---|
61 | <xsl:variable name="fn" select="@name"/> |
---|
62 | |
---|
63 | <xsl:element name="field"> |
---|
64 | <xsl:attribute name="name"><xsl:value-of select="$fn"/></xsl:attribute> |
---|
65 | <xsl:value-of select="."/> |
---|
66 | </xsl:element> |
---|
67 | </xsl:template> |
---|
68 | |
---|
69 | <xsl:template match="*"/> |
---|
70 | </xsl:stylesheet> |
---|