如何从 FINAL 数据库中协调文档中的 header 获取 TDE 数据

How to get TDE data from header in a harmonized document in FINAL database

我正在创建一个 TDE 文档,我需要从协调文档的 headers 部分获取数据,并从文档的主要部分(工作订单)获取值。

但是,我当前的 tde 上下文值似乎没有显示预期值。关于为什么在我当前的 TDE 代码中会发生这种情况有什么想法吗?

我尝试了很多代码,例如下面的代码:

//es:headers/ProjectSpecificData/WorkOrderStatusHistory/StatusHistory/StatusHistory

但它没有从 headers

中获取任何数据

FINAL 数据库中的样本协调文件

<?xml  version="1.0" encoding="UTF-8"?>
<envelope xmlns="http://marklogic.com/entity-services">
<headers>
<sourceURI xmlns="">/JDEdwards/CMMS/Sample/WorkOrder/DASH_JDEWO/7044389</sourceURI>
<ProjectSpecificData xmlns="http://testing.com/ads/project">
    <CompletedDate xmlns="http://testing.com/ads/project/fwe">2018-06-29</CompletedDate>
    <WorkOrderStatusHistory xmlns="http://testing.com/ads/project/fwe">
        <StatusHistory>
        <StatusHistory><UpdatedBy>RFCM</UpdatedBy>
        <UpdatedDate>2018/06/24</UpdatedDate>
        <StatusCode>55</StatusCode>
        <StatusDesc>Scheduled</StatusDesc>
        <StatusEffectiveDate>2018-06-24</StatusEffectiveDate>
        <StatusEndDate>2018-06-29</StatusEndDate></StatusHistory>
        <StatusHistory><UpdatedBy>GPFW</UpdatedBy>
        <UpdatedDate>2018/06/23</UpdatedDate>
        <StatusCode>10</StatusCode>
        <StatusDesc>Job Planning</StatusDesc>
        <StatusEffectiveDate>2018-06-23</StatusEffectiveDate>
        <StatusEndDate>2018-06-23</StatusEndDate></StatusHistory>
        <StatusHistory><UpdatedBy>COLO</UpdatedBy>
        <UpdatedDate>2018/07/01</UpdatedDate>
        <StatusCode>60</StatusCode>
        <StatusDesc>Daily Work in Progress</StatusDesc>
        <StatusEffectiveDate>2018-06-29</StatusEffectiveDate>
        <StatusEndDate>2018-06-29</StatusEndDate></StatusHistory>
        <StatusHistory><UpdatedBy>GPFW</UpdatedBy>
        <UpdatedDate>2018/06/22</UpdatedDate>
        <StatusCode>05</StatusCode>
        <StatusDesc>Ready for Approval</StatusDesc>
        <StatusEffectiveDate>2018-06-22</StatusEffectiveDate>
        <StatusEndDate>2018-06-23</StatusEndDate></StatusHistory>
        <StatusHistory><UpdatedBy>GPFW</UpdatedBy>
        <UpdatedDate>2018/06/24</UpdatedDate>
        <StatusCode>50</StatusCode>
        <StatusDesc>Ready to Schedule</StatusDesc>
        <StatusEffectiveDate>2018-06-23</StatusEffectiveDate>
        <StatusEndDate>2018-06-24</StatusEndDate></StatusHistory>
        <StatusHistory><UpdatedBy>JPGS</UpdatedBy>
        <UpdatedDate>2018/06/14</UpdatedDate>
        <StatusCode>01</StatusCode>
        <StatusDesc>Work Request</StatusDesc>
        <StatusEffectiveDate>2018-06-14</StatusEffectiveDate>
        <StatusEndDate>2018-06-22</StatusEndDate></StatusHistory>
        <StatusHistory><UpdatedBy>COLO</UpdatedBy>
        <UpdatedDate>2018/07/01</UpdatedDate>
        <StatusCode>65</StatusCode>
        <StatusDesc>Completed Ready for Review</StatusDesc>
        <StatusEffectiveDate>2018-06-29</StatusEffectiveDate>
        <StatusEndDate/></StatusHistory>
        </StatusHistory>
        </WorkOrderStatusHistory>
    </ProjectSpecificData>
    </headers>
<triples>
<instance>
<info>
<title>WorkOrder</title>
<version>1.0.1</version>
</info>
<WorkOrder entityExtVersion="1.0.1" entityVersion="1.0.1" entity="WorkOrder" defaultConfidence="95.00" xmlns="">
<WorkOrderCode sourcesystem="Testing" confidence="95.00">7044389</WorkOrderCode>
</WorkOrder>
</instance>
<attachments>
</attachments>
</envelope>

当前 TDE 文档代码:

xquery version "1.0-ml";
import module namespace tde = "http://marklogic.com/xdmp/tde" 
        at "/MarkLogic/tde.xqy";

let $workordertde:=
<tde:template xmlns:tde="http://marklogic.com/xdmp/tde">
<tde:context>//es:headers/ProjectSpecificData/WorkOrderStatusHistory/StatusHistory/StatusHistory</tde:context>
<tde:path-namespaces>
<tde:path-namespace>
<tde:prefix>es</tde:prefix>
<tde:namespace-uri>http://marklogic.com/entity-services</tde:namespace-uri>
</tde:path-namespace>
</tde:path-namespaces>
<tde:collections>
<tde:collection>Collection</tde:collection>
</tde:collections>
<tde:enabled>true</tde:enabled>
<tde:rows>
<tde:row>
<tde:schema-name>TestSchema</tde:schema-name>
<tde:view-name>TestView</tde:view-name>
<tde:view-layout>sparse</tde:view-layout>
<tde:columns>
<tde:column>
<tde:name>WorkOrderID</tde:name>
<tde:scalar-type>string</tde:scalar-type>
<tde:val>//es:instance[es:info/es:version = "1.0.1"]/WorkOrder/WorkOrderNo</tde:val>
<tde:invalid-values>ignore</tde:invalid-values>
</tde:column>
<tde:column>
<tde:name>WOStatus</tde:name>
<tde:scalar-type>string</tde:scalar-type>
<tde:val>fn:concat(StatusCode, " - ", StatusDesc)</tde:val>
<tde:nullable>true</tde:nullable>
</tde:column>
<tde:name>BeginDate</tde:name>
<tde:scalar-type>string</tde:scalar-type>
<tde:val>StatusEffectiveDate</tde:val>
<tde:nullable>true</tde:nullable>
</tde:column>
</tde:columns>
</tde:row>
</tde:rows>
</tde:template>

实际结果: 当我测试单个文档的 TDE 时,它没有显示任何值:

{
"/WorkOrder/JDEdwards/130008HU52-7044389.xml": [
]
}

预期结果:

我希望 TDE 显示我试图从 headers(StatusHistory 数据)以及主要部分(WorkOrdercCode)中获取的值。

编辑:

看起来返回状态历史值的函数正在返回一个字符串值。我试图删除 toString() 调用,但它不起作用。对代码有什么想法吗?

function getStatusHistory(workOrder) { 
  var status = [];

  let statusHistory =  cts.search(cts.andQuery([
            cts.collectionQuery('Collection1'),
            cts.collectionQuery('Collection2'),
            //cts.collectionQuery('Collection3'),
            cts.elementWordQuery(fn.QName('http://www.testing.com/ads/JDEdwards/wostatushistory', 'F1DOCO'), workOrder)
        ])); 

  if(fn.count(statusHistory) <= 0) return "";

  let builder;
  let doc = new NodeBuilder();
  doc.startElement('StatusHistory');

  for (const item of statusHistory) {

    builder = new NodeBuilder();
    builder.startElement('StatusHistory');

    //Audit
    builder.addElement('UpdatedBy',sfh.ensureStringResult(fn.normalizeSpace(hl.elementText(item, "F1USER", true))));
    builder.addElement('UpdatedDate',sfh.ensureStringResult(fn.normalizeSpace(hl.elementText(item, "F1UPMJ", true))));


    //Status
    let statusCode = fn.normalizeSpace(hl.elementText(item, "F1EWST", true));
    builder.addElement('StatusCode',sfh.ensureStringResult(statusCode));
    builder.addElement('StatusDesc',sfh.ensureStringResult(getUDCDescription("00", "SS", statusCode)));

    builder.addElement('StatusEffectiveDate',sfh.ensureStringResult(fn.replace(fn.normalizeSpace(hl.elementText(item, "F1EFTB", true)),"/","-")));
    builder.addElement('StatusEndDate',sfh.ensureStringResult(fn.replace(fn.normalizeSpace(hl.elementText(item, "F1EFTE", true)),"/","-")));

    builder.endElement();
    doc.addElement('StatusHistory', builder.toNode().xpath('/node()').toString());

  }

  doc.endElement();

  return doc.toNode();
  //return status;
}

ProjectSpecificData 元素在 http://testing.com/ads/project 命名空间中,但您没有在上下文路径中引用该命名空间。尝试:

<tde:template xmlns:tde="http://marklogic.com/xdmp/tde">
    <tde:context>//es:headers/ads:ProjectSpecificData/fwe:WorkOrderStatusHistory/fwe:StatusHistory/fwe:StatusHistory</tde:context>
    <tde:path-namespaces>
        <tde:path-namespace>
            <tde:prefix>es</tde:prefix>
            <tde:namespace-uri>http://marklogic.com/entity-services</tde:namespace-uri>
        </tde:path-namespace>
        <tde:path-namespace>
            <tde:prefix>ads</tde:prefix>
            <tde:namespace-uri>http://testing.com/ads/project</tde:namespace-uri>
        </tde:path-namespace>
        <tde:path-namespace>
            <tde:prefix>fwe</tde:prefix>
            <tde:namespace-uri>http://testing.com/ads/project/fwe</tde:namespace-uri>
        </tde:path-namespace>
    </tde:path-namespaces>
    ...
</tde:template>


编辑:回复评论以便我可以使用格式:

由于您在获取值时遇到问题,您的路径可能仍然存在问题。与在 TDE 中相比,在查询控制台中直接使用路径会更容易。在QC中,设置如下:

declare namespace es = "http://marklogic.com/entity-services";
declare namespace ads = "http://testing.com/ads/project";
declare namespace fwe = "http://testing.com/ads/project/fwe";

let $doc := (: your doc :)
let $context := $doc//es:headers/ads:ProjectSpecificData/fwe:WorkOrderStatusHistory/fwe:StatusHistory/fwe:StatusHistory
return $context

你有得到什么回报吗?如果是这样,太棒了,现在尝试返回您想要的单个数据。如果不是,请从上下文路径的末尾开始删除元素,直到您这样做,然后找出路径有什么问题。

完成后,您应该能够正确设置 TDE 模板。