XQuery Implementation
This module detects input documents with URI suffixes of the form “.1” and converts them into XML documents with a “.xml” URI extension. Note that the transform does not snoop the content to ensure it is actually XML.
xquery version "1.0-ml"; module namespace example = "http://marklogic.com/example"; declare function example:mod_doc_type( $content as map:map, $context as map:map ) as map:map* { let $orig-uri := map:get($content, "uri") return if (fn:substring-after($orig-uri, ".") = "1") then let $doc-type := xdmp:node-kind(map:get($content, "value")) return ( (: change the URI to an xml suffix :) map:put($content, "uri", fn:concat(fn:substring-before($orig-uri, "."), ".xml") ), (: convert the input from binary node to xml document node :) if ($doc-type = "binary") then map:put( $content, "value", xdmp:unquote(xdmp:quote(map:get($content, "value"))) ) else (), $content ) else $content };