example_atom.xsl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. Simple transform of Solr query results to Atom
  20. -->
  21. <xsl:stylesheet version='1.0'
  22. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  23. <xsl:output
  24. method="xml"
  25. encoding="utf-8"
  26. media-type="application/xml"
  27. />
  28. <xsl:template match='/'>
  29. <xsl:variable name="query" select="response/lst[@name='responseHeader']/lst[@name='params']/str[@name='q']"/>
  30. <feed xmlns="http://www.w3.org/2005/Atom">
  31. <title>Example Solr Atom 1.0 Feed</title>
  32. <subtitle>
  33. This has been formatted by the sample "example_atom.xsl" transform -
  34. use your own XSLT to get a nicer Atom feed.
  35. </subtitle>
  36. <author>
  37. <name>Apache Solr</name>
  38. <email>solr-user@lucene.apache.org</email>
  39. </author>
  40. <link rel="self" type="application/atom+xml"
  41. href="http://localhost:8983/solr/q={$query}&amp;wt=xslt&amp;tr=atom.xsl"/>
  42. <updated>
  43. <xsl:value-of select="response/result/doc[position()=1]/date[@name='timestamp']"/>
  44. </updated>
  45. <id>tag:localhost,2007:example</id>
  46. <xsl:apply-templates select="response/result/doc"/>
  47. </feed>
  48. </xsl:template>
  49. <!-- search results xslt -->
  50. <xsl:template match="doc">
  51. <xsl:variable name="id" select="str[@name='id']"/>
  52. <entry>
  53. <title><xsl:value-of select="str[@name='name']"/></title>
  54. <link href="http://localhost:8983/solr/select?q={$id}"/>
  55. <id>tag:localhost,2007:<xsl:value-of select="$id"/></id>
  56. <summary><xsl:value-of select="arr[@name='features']"/></summary>
  57. <updated><xsl:value-of select="date[@name='timestamp']"/></updated>
  58. </entry>
  59. </xsl:template>
  60. </xsl:stylesheet>