MarkLogic TDE XPATH 不适用于重复组

Eri*_*ven 1 xml xpath marklogic

我正在使用 ML 9.0 版并开始使用 TDE(模板驱动提取)。我有很多 XML 文件(每个 50 kb 的 3500 个 xml 文件)并将它们成功加载到 ML。我成功创建了一些基本模板(TDE)。但是当我到达同一元素组的重复组时,视图返回一个空结果。唯一的方法是将上下文设置在我不想要的较低级别,因为我无法从更高的节点中选择元素。

下面的 XML 定义显示了 XML 文件的示例:

<scope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <item>
        <transaction>
            <type>CI</type>
            <sscc>00000379471900000025</sscc>
            <location>4260210630688</location>
            <device>VISTALINK.004</device>
            <date>2017-04-25</date>
            <time>02:15:33</time>
            <gmtOffset>+02:00</gmtOffset>
            <actorId>155081</actorId>
        </transaction>
        <order>
            <orderNumber>3794719</orderNumber>
        </order>
        <load>
            <rti>
                <ean>8714548186004</ean>
                <grai>8003087145481860040019877322</grai>
                <column>2</column>
                <size>
                    <width>1900</width>
                    <height>95</height>
                    <depth>0</depth>
                </size>
                <position>
                    <x>2062,48707520218</x>
                    <y>2015,24337520512</y>
                    <z>0</z>
                </position>
            </rti>
            <rti>
                <ean>8714548106002</ean>
                <grai>8003087145481060020016434653</grai>
                <column>0</column>
                <size>
                    <width>1900</width>
                    <height>95</height>
                    <depth>0</depth>
                </size>
                <position/>
            </rti>
            <rti>
                <ean>8714548186004</ean>
                <grai>8003087145481860040012803719</grai>
                <column>2</column>
                <size>
                    <width>1900</width>
                    <height>95</height>
                    <depth>0</depth>
                </size>
                <position>
                    <x>2064,20629390666</x>
                    <y>2124,57539157396</y>
                    <z>0</z>
                </position>
            </rti>
            <rti>...</rti>
            <rti>...</rti>
            <rti>...</rti>
            <rti>...</rti>
            <rti>...</rti>
        </load>
    </item>
</scope>
Run Code Online (Sandbox Code Playgroud)

我已经能够从选择/scope/item/transaction/type/scope/item/order/orderNumber运用下面的模板:

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

let $transactions :=
<template xmlns="http://marklogic.com/xdmp/tde">
  <context>/scope/item</context>
  <rows>
    <row>
      <schema-name>main</schema-name>
      <view-name>transactions</view-name>
      <columns>
        <column>
          <name>type</name>
          <scalar-type>string</scalar-type>
          <val>transaction/type</val>
        </column>
        <column>
          <name>Ordernumber</name>
          <scalar-type>long</scalar-type>
          <val>order/orderNumber</val>
        </column>
    </columns>
    </row>
  </rows>
</template>
return tde:template-insert("Transactions.xml", $transactions)
Run Code Online (Sandbox Code Playgroud)

但是当我基于相同的结构创建一个新模板时,选择另一个级别的元素 ( /scope/item/load) 它返回一个空视图。

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

let $rti :=
<template xmlns="http://marklogic.com/xdmp/tde">
  <context>/scope/item</context>
  <rows>
    <row>
      <schema-name>main</schema-name>
      <view-name>rti_transaction</view-name>
      <columns>
        <column>
          <name>type</name>
          <scalar-type>string</scalar-type>
          <val>load/rti/grai</val>
        </column>
    </columns>
    </row>
  </rows>
</template>
return tde:template-insert("ssc_rti.xml", $rti)
Run Code Online (Sandbox Code Playgroud)

正如我之前提到的,我不想更改上下文,因为我无法选择ordertransaction节点。

我还尝试在 1 个 xml 文档上使用 xpath 和 xquery 来获取元素。这工作正常。

xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";

fn:doc('/transaction/2017-04-25_02-15-33_3794719_00000379471900000025_CI.xml')/scope/item/load/rti/grai/text()
Run Code Online (Sandbox Code Playgroud)

ehe*_*num 5

要从单个文档生成多行,模板的上下文必须与重复子结构中的元素(或 JSON 属性)匹配。

在这种情况下,模板可能会匹配 rti。

模板的值表达式可以具有向上的相对路径,因此您可以使用包含重复明细子结构的主结构中的值在明细中生成列。

您可以使用该功能在相关主行的明细行中插入外键(或将主数据非规范化为明细行)。

在这种情况下,模板可能会为订单号添加外键列。

这不是限制性的,因为模板文档可以包含多个模板,这些模板将行从文档的不同部分投影到不同的视图中。

在这种情况下,容器模板可能使用范围作为上下文并使用每个文档一行填充订单范围视图,而包含的模板使用 rti 作为上下文并使用每个文档的多行填充项目 rti 视图,关联每个 rti通过作用域行的主键的外键将行转换为作用域行。

希望有所帮助,