Form Transform

About this task

You can add a secondary parser to a form to perform advanced query manipulation and normalization. With a form transform, you are able to manipulate the parse node after it has been created by your input form. This is what the Teoma source's parse param looks like after searching for "test" with a language CGI parameter with a value of "danish":

<parse url="http://ask.com/search" method="GET" url-encoding="ISO_8859-1"
      display-url="http://web.ask.com/web" source="teoma" per="100"
      page="0" start="0" parser="#anonymous#0">
      <parse-param name="q" value="test" position="0" />
      <parse-param name="language" value="DA" position="7" />
      <parse-param name="u" position="1" value="100" />
      </parse>

Since this source uses a language: field rather than a CGI parameter for language, you need to grab the value of that param and add it to the query parse-param as a field. With that goal in mind, let's get started.

Procedure

  1. Add a transform attribute to your form in XML mode:
    <form transform="language-transform">
  2. Add a Secondary Parser with the same name (language-transform in this case).
  3. Write the parser to copy and/or change any values or attributes you like:
    <xsl:variable name="query" select="'q'" />
      <xsl:template match="/scope">
      <xsl:copy>
      <xsl:apply-templates select="parse" />
      </xsl:copy>
      </xsl:template>
    
      <xsl:template match="parse">
      <xsl:copy>
      <xsl:apply-templates select="@*" mode="copy" />
      <xsl:apply-templates select="parse-param" />
      </xsl:copy>
      </xsl:template>
    
      <xsl:template match="parse-param[@name=$query]">
      <xsl:variable name="language" select="../parse-param[@name='language']/@value" />
      <parse-param name="{$query}">
      <xsl:attribute name="value">
      <xsl:value-of select="@value" />
      <xsl:if test="$language">
      <xsl:value-of select="concat(' language:', $language)" />
      </xsl:if>
      </xsl:attribute>
      </parse-param>
      </xsl:template>
    
      <xsl:template match="parse-param">
      <xsl:copy-of select="." />
      </xsl:template>
    
      <xsl:template match="@*" mode="copy">
      <xsl:attribute name="{name()}">
      <xsl:value-of select="." />
      </xsl:attribute>
      </xsl:template>
  4. While writing your form transformations, you can view the translation through in the debug session.
  5. The resulting parse node for this example looks like (note the value of the "q" parse-param):
    <parse url="http://ask.com/search" method="GET" url-encoding="ISO_8859-1"
      display-url="http://web.ask.com/web" source="teoma" per="100"
      page="0" start="0" parser="#anonymous#0">
      <parse-param name="q" value="test language:DA geoloc:EU" />
      <parse-param name="language" value="DA" position="7" />
      <parse-param name="u" position="1" value="100" />
      </parse>