如何在转换中替换$ content值?

时间:2019-04-02 08:45:39

标签: xquery marklogic marklogic-8 marklogic-9

我需要在转换中替换$ content值。

    public class Event {
        public String name;

        @JsonFormat
          (shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
        public Date eventDate;
}

我需要用$ root值更改$ content值并返回它。我试图直接返回$ root,但是没有用,我收到无效的文档错误。

enter image description here

1 个答案:

答案 0 :(得分:2)

问题在于$output的作用域为FLWOR语句,但是您在该语句之外引用它。请参见下面return中的括号。

xquery version "1.0-ml";

module namespace test = "http://marklogic.com/rest-api/transform/security-load";

declare function test:transform(
    $context as map:map,
    $params as map:map,
    $content as document-node()
) as document-node()
{       
    let $jsonObj := xdmp:from-json($content)
    let $inputval := "fname,lname"
    let $entity :="holidayDate"
    let $domain :="referenceData"

    let $uri := 
        xdmp:apply(
            xdmp:function(xs:QName("createUri"), "/wdsUtils.sjs"),
            $jsonObj,
            $inputval
        )

    let $root := 
        xdmp:apply(
            xdmp:function(xs:QName("addMetaData"), "/wdsUtils.sjs"),
            $entity,
            $domain,
            $jsonObj
        )

    let $output := $root    

    return (
        map:put($context,"uri",$uri),
        document { $output }
    )
};