【发布时间】:2017-05-21 12:34:44
【问题描述】:
我正在使用 ML 9.0 版并开始使用 TDE(模板驱动提取)。我有很多 XML 文件(3500 个 50 kb 的 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>
我已经可以通过应用以下模板从/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)
但是当我基于相同的结构创建一个新模板选择另一个级别的元素 (/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)
正如我之前提到的,我不想更改上下文,因为我无法选择 order 或 transaction 节点。
我还尝试在 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()
【问题讨论】: