4

我想用带有 id 的行和原始文档中数组的每个值来构建 aa tde。

我为每个元素得到一行,但值为 null 并被忽略。

似乎如果上下文设置为任何不是数组的 ../uri 工作,但当上下文是数组时永远不会。

除了简单的示例之外,我正在努力为 MarkLogic TDE 寻找好的资源,

示例文档(片段)

 "instance": {
        "uri": "/A/Uri/of/some/type.json", 
         "types": [
          "a", 
          "b", 
          "c"
      ]
}

模板

{
  "template":{
    "context":"/instance/types",
    "collections":["Collection"],
    "enabled" : true,
    "rows":[
      {
        "schemaName":"namespace",
        "viewName":"uri2types",
        "columns":[
          {
            "name":"uri",
            "scalarType":"anyURI",
            "val":"../uri",
            "nullable":true,
            "invalidValues": "ignore"
          }
          ,
          {
            "name":"type",
            "scalarType":"string",
            "val":"/node()",
            "nullable":true,
            "invalidValues": "ignore"
          }
        ]
      }
    ]
  }
}

结果

     {
        "/A/Uri/of/some/type.json": [
            {
                "row": {
                    "schema": "namespace", 
                    "view": "uri2types", 
                    "data": {
                        "rownum": "1"
                }
            }
        }, 
            {
                "row": {
                    "schema": "namespace", 
                    "view": "uri2types", 
                    "data": {
                        "rownum": "2"
                }
            }
        }, 
            {
                "row": {
                "schema": "namespace", 
                "view": "uri2types", 
                "data": {
                    "rownum": "3"
                }
                }
            }
        ]
        }

**Result Wanted** 


    {
        "/A/Uri/of/some/type.json": [
        {
            "row": {
                    "schema": "namespace", 
                    "view": "uri2types", 
                    "data": {
                        "rownum": "1",
                        "uri":"/A/Uri/of/some/type.json":,
                        "type"="a"

                    }
                }
            }, 
        {
            "row": {
                "schema": "namespace", 
                "view": "uri2types", 
                "data": {
                    "rownum": "2",
                    "uri":"/A/Uri/of/some/type.json":,
                    "type":"b"
                }
            }
        }, 
        {
            "row": {
                "schema": "namespace", 
                "view": "uri2types", 
                "data": {
                    "rownum": "3",
                    "uri":"/A/Uri/of/some/type.json":,
                    "type":"c"
                }
            }
        }
    ]
    }
4

2 回答 2

2

/node()该列的表达式type将尝试获取包含您的类型的文本节点的子节点,但文本节点没有任何子节点。data()或者.更合适。

../uri该列的表达式uri没有向上爬到足够高的树上。获取类型值的完整 MarkLogic XPath 将是/object-node()/object-node('instance')/array-node('types')/text(). 您需要上两层才能逃离周围的数组节点。它可以帮助重写/instance/types/instance/array-node()/types

'use strict';

let json = xdmp.toJSON({
  "instance": {
    "uri": "/A/Uri/of/some/type.json", 
    "types": [
      "a", 
      "b", 
      "c"
    ]
  }
});
let tpl = xdmp.toJSON({
  "template":{
    "context":"/instance/array-node()/types",
    "enabled" : true,
    "rows":[
      {
        "schemaName":"namespace",
        "viewName":"uri2types",
        "columns":[
          {
            "name":"uri",
            "scalarType":"anyURI",
            "val":"../../uri",
            "nullable":true,
            "invalidValues": "ignore"
          }
          ,
          {
            "name":"type",
            "scalarType":"string",
            "val":"data()",
            "nullable":true,
            "invalidValues": "ignore"
          }
        ]
      }
    ]
  }
});
tde.validate([tpl]);
tde.nodeDataExtract([json], [tpl]);

HTH!

于 2019-10-31T15:05:47.837 回答
0

我认为问题出在这里:"val":"/node()",. 您给出的路径从根开始,而不是上下文节点。试试这个:

"val":".",
于 2019-10-30T20:01:32.087 回答