Search code examples
marklogicmarklogic-8

Errors when trying to apply transform to search results


Edit: I did some more debugging and that error is actually thrown when I am trying to install the transform, not use it. However, when I search though my DB I can find the script there.

I am using the Java API and Marklogic version 8.

I wrote an xquery transform to modify documents when they are retrieved by a search. I wrote it up in the query console, verified that it did what I wanted it to, but now that I have it in a file and am trying to use it in my application I get the following error:

Server Message: RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: invalid xml_to_string extension: xml_to_string either is not a valid module or does not provide extension functions (transform) in the http://marklogic.com/rest-api/transform/xml_to_string namespace

I followed the documentation pretty close to verbatim on how to install and use a transform, so i'm not really sure where the problem lies except for maybe in the script itself. The code is as follows:

xquery version "1.0-ml";
module namespace xmlTrans =
  "http://marklogic.com/rest-api/transform/xml_to_string";

declare function xmlTrans:xmlToString(
  $context as map:map,
  $params as map:map,
  $fullDoc as document-node()
) as document-node()
{
  if(fn:empty($fullDoc/*)) then $fullDoc
  else (
    let $root  := $fullDoc/*
    let $contentArray := $root/contents
    return document
    {
      element {fn:name($root)}
      {
        $root/@*, $root/element()[fn:not(fn:name(.) eq "contents")],
        element contents
        {
          for $contentEle in $contentArray/content

          return(
            if($contentEle/@type = "paragraph") then (<content type="paragraph"><paragraph>{xdmp:quote($contentEle/paragraph/*)}</paragraph></content> )
            else ($contentEle)
          )

        }
      }
    }
  )
};

Is there something wrong in my syntax that is preventing Marklogic from recognizing it as a transform?


Solution

  • The REST API extensions follow a convention-over-configuration approach.

    A transform extension must contain a function named "transform" -- see:

    http://docs.marklogic.com/guide/rest-dev/transforms#id_17421

    Also, the REST API installs extensions even if it detects errors.

    Hoping that clarifies,