Loading TOC...


   source-model as Object,
   target-model as Object
) as String


This function is deprecated and will be removed in a future release.
Generate a module that can be used to translate instances conforming to one version of a model into instances conforming to another version

source-model The basic model for the "older" version of the model. This is the model to translate data from.
target-model The basic model for the "newer" version of the model. This is the model to translate data to.

Usage Notes

This function compares two versions of a basic model and generates an XQuery library module you can use to transform instance data from one version to the other. Use this function as part of managing a data model lifecycle. As the model for an entity type changes over time, you can use the output of this function as the basis for code that helps with migrating dependent services and transforms from source data systems.

The generated XQuery module contains one function per entity type in target-model. Each such function stubs out the conversion of one entity type to another. You can use these functions in concert with transform code to implement runtime versioning transforms.

You will typically need to install the generated module in your modules database before you can use it.

See Also


// Generate a translator module between two versions of a basic model.
// The models only differ in that the new version contains an additional
// (optional) property named "middle" in the Name entity type. 

const es = require('/MarkLogic/entity-services/entity-services');

const v1Model =
  { "info": {
      "title": "Example",
      "version": "1.0.0"
    "definitions": {
      "Name": {
        "properties": {
          "first": { "datatype": "string" },
          "last": { "datatype": "string" }
        "required": [ "first", "last" ]
  } } } ;
const v2Model =
  { "info": {
      "title": "Example",
      "version": "2.0.0"
    "definitions": {
      "Name": {
        "properties": {
          "first": { "datatype": "string" },
          "middle": { "datatype": "string" },
          "last": { "datatype": "string" }
        "required": [ "first", "last" ]
  } } };
es.versionTranslatorGenerate(v1Model, v2Model);

/* Result: An XQuery library module similar to the following. Some of the
 *  comments in the generated module have been omitted for brevity.

xquery version "1.0-ml";
module namespace example-from-example
    = "http://example.org/Example-2.0.0-from-Example-1.0.0";

import module namespace es = "http://marklogic.com/entity-services"
    at "/MarkLogic/entity-services/entity-services.xqy";

declare option xdmp:mapping "false";

declare function example-from-example:convert-instance-Name(
    $source-node as node()
) as map:map
    (: The following line identifies the type of this instance.  Do not change it. :)
    =>map:with('$type', 'Name')
    (: The following lines are generated from the 'Name' entity type. :)
    =>   map:with('first',                  xs:string($source-node/Name/first))
    (: The following property was missing from the source type :)
    =>es:optional('middle',                 xs:string( () ))
    =>   map:with('last',                   xs:string($source-node/Name/last))


Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.