Friday, January 13, 2012

Custom Output from IDOL using Templates

One can get a customized output from IDOL as the response using Template parameter which is available with the following queries:

  • Action=Query
  • Action=GetContent
  • Action=List
  • Action=Suggest
  • Action=SuggestOnText
  • Action=GetQueryTagValues
  • Action=GetTagNames
  • Action=GetTagValues

To use Template parameter enable XSLTemplates=true needs to be set under [Server] Section of Autonomy IDOL Server configuration file, restart the IDOL Server for the change to reflect.

Then place custom .tmpl file inside the templates directory.

Use &Template=<template.tmpl>&ForceTemplateRefresh=true parameter along with any of the queries mentioned above to see a customized output.

Please find the below template file which outputs a customized response for GetQueryTagValues query i.e., autn:total_values value is removed in the XML Response.

The template content is 
---------------------------------

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:autn="http://schemas.autonomy.com/aci/"
> 
    <xsl:output method="xml" indent="yes"/>
    <xsl:include href="RetrievalAppConfig.tmpl" />
    <xsl:template match="/">
                   <autnresponse>
                   <action><xsl:value-of select="autnresponse/action"/></action>
                   <response><xsl:value-of select="autnresponse/response"/></response>
                   <responsedata>
                             <autn:number_of_fields><xsl:value-of select="autnresponse/responsedata/autn:number_of_fields"/></autn:number_of_fields>
                             <autn:field>
                                      <autn:name><xsl:value-of select="autnresponse/responsedata/autn:field/autn:name"/></autn:name>
                                      <autn:number_of_values><xsl:value-of select="autnresponse/responsedata/autn:field/autn:number_of_values"/></autn:number_of_values>                                   
                                      <xsl:copy-of select="autnresponse/responsedata/autn:field/autn:value">
                                      </xsl:copy-of>
                             </autn:field>
                   </responsedata>
                   </autnresponse>     
    </xsl:template>
</xsl:stylesheet>
  

Use ForceTemplateRefresh=true along with &Template=<template> parameter if one requires the change in the .tmpl file to reflect immediately in the response.


No comments:

Post a Comment