Skip to content

Instantly share code, notes, and snippets.

@ssp
Last active December 12, 2015 05:39
Show Gist options
  • Save ssp/4723573 to your computer and use it in GitHub Desktop.
Save ssp/4723573 to your computer and use it in GitHub Desktop.
XSLT hack for Solr results to pass the content of a specific field through unchanged. Allows for structured XML content in Solr results.
<?xml version='1.0' encoding='UTF-8'?>
<!--
XSL hack for retrieving structured XML data from Solr fields without re-parsing.
It assumes that the <str> field »xml« contains valid XML, replaces the
<str> tag by an <xml> tag and includes the field content without escaping.
To use this, place the XSL in the »conf/xslt« folder
and invoke the XSLT Response writer [1] for this XSL by appending
&wt=xslt&tr=xmlpassthrough.xsl
to the request URL.
Edit the second template’s match attribute to use this on other fields.
[1] http://wiki.apache.org/solr/XsltResponseWriter
2013 Sven-S. Porst, SUB Göttignen <porst@sub.uni-goettingen.de>
-->
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="arr[@name='xml']/str">
<xml>
<xsl:value-of disable-output-escaping="yes" select="." />
</xml>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment