0

I have been working with a SolrJ-based Java client that builds/sends queries to an external Solr instance and processes their responses back to a web application. I have an XSLT named response.xslt where all necessary mappings between the local Solr schema and the UI are specified. In my case, I have been trying to build and display facets according to the SOLR response below:

<facets>
    <facet name="domain">
        <facetEntry count="10">blogspot.co.uk</facetEntry>
        <facetEntry count="6">indys.org.uk</facetEntry>
        <facetEntry count="3">royalcanin.co.uk</facetEntry>
        <facetEntry count="1">faerie-tales.co.uk</facetEntry>
        <facetEntry count="1">polishbeautyclinic.co.uk</facetEntry>
        <facetEntry count="1">shua.org.uk</facetEntry>
        <facetEntry count="1">sunnyharbour.org.uk</facetEntry>
    </facet>
</facets>

The XML as returned by my web application looks like this:

   <sear:FACET NAME="local36" COUNT="20">
               <sear:FACET_VALUES KEY="blogspot.co.uk" VALUE="10"/>
               <sear:FACET_VALUES KEY="indys.org.uk" VALUE="6"/>
               <sear:FACET_VALUES KEY="royalcanin.co.uk" VALUE="3"/>
               <sear:FACET_VALUES KEY="faerie-tales.co.uk" VALUE="1"/>
               <sear:FACET_VALUES KEY="polishbeautyclinic.co.uk" VALUE="1"/>
               <sear:FACET_VALUES KEY="shua.org.uk" VALUE="1"/>
               <sear:FACET_VALUES KEY="sunnyharbour.org.uk" VALUE="1"/>
   </sear:FACET>

Nevertheless, the final facets structure from the UI is wrongly generated. In a nutshell, it only displays the last value "sunnyharbour.org.uk" multiple times. My first thought was that, for some reasons, the full stops/periods in the URLs trigger such UI behaviour, so I harcoded the response as follows:

<sear:FACET NAME="local36" COUNT="20">
               <sear:FACET_VALUES KEY="blogspot" VALUE="10"/>
               <sear:FACET_VALUES KEY="indys" VALUE="6"/>
               <sear:FACET_VALUES KEY="royalcanin" VALUE="3"/>
               <sear:FACET_VALUES KEY="faerie-tales" VALUE="1"/>
               <sear:FACET_VALUES KEY="polishbeautyclinic" VALUE="1"/>
               <sear:FACET_VALUES KEY="shua" VALUE="1"/>
               <sear:FACET_VALUES KEY="sunnyharbour" VALUE="1"/>
   </sear:FACET>

In this way, the facets are generated as expected.

My response file looks like this:

<xsl:template match="facets">
    <xsl:apply-templates select="facet" />
</xsl:template>

<xsl:template match="facet">
</xsl:template> 

<xsl:template match="facet[@name='domain']">
    <sear:FACET NAME="local36" COUNT="{count(facetEntry)}">         
        <xsl:apply-templates select="facetEntry" />
    </sear:FACET>

<xsl:template match="facetEntry">
    <sear:FACET_VALUES VALUE="{@count}" KEY="{.}" />                    
</xsl:template>

I am not sure what it would be the best course of action, but in principle I would like to be able to encode periods in URLs. Can you help me with this?

Thanks,

I.

panza
  • 1,341
  • 7
  • 38
  • 68
  • And what does the rest of the XSLT look like, in particular the template(s) relating to `facetEntry`? – Ian Roberts Feb 03 '14 at 18:23
  • @IanRoberts, I have just added the template for facetEntry. Thanks – panza Feb 03 '14 at 20:27
  • 2
    There's nothing special about periods in string values in XSLT... and from what you've shown us, it looks like your XSLT handled them perfectly. The problem appears to be in whatever is _consuming_ the XML document you're generating. – keshlam Feb 03 '14 at 20:46
  • Sorry, it's still not clear for me. Please specify: what is the input, what is the actual output and what is the expected output. Why did you hard code something different (no top level domains) than what you describe (I expected you would hard code the top level domani with dots encoded as %2E or something). Also note that `http://google%2Ecom` cannot be used as a URL – Thomas Weller Feb 03 '14 at 20:47
  • @ThomasW. I have hardcoded the URLs with no top level domains to prove that the dots/periods were somehow causing the issue. In my particular case, I only have top level domains. – panza Feb 03 '14 at 21:31
  • @ilariac: Ok, I see. Which encoding of the dots would the receiving application understand, given the fact that it doesn't even understand simple dots? – Thomas Weller Feb 03 '14 at 21:35
  • @ThomasW. Is it possible to convert the URLs into strings? – panza Feb 03 '14 at 22:31
  • 1
    @ilariac: the way it currently is, no matter whether it's part of an an element or an attribute, is already a string. – Thomas Weller Feb 03 '14 at 22:34
  • @ThomasW. Yes, you are right. I am afraid, I will have to go with what keshlam suggested. Thanks for your help! – panza Feb 03 '14 at 23:22

0 Answers0