templates - MarkLogic 中的 XQuery 模板不显示任何值,只显示属性 (TDE)

标签 templates namespaces xquery marklogic marklogic-9

我创建了一个 .xml 文件和一个模板来提取一些数据,但只显示属性。

这是我的 .xml-testfile:

<user id="1234" email="test.user@live.com" password="1234">
<type>Human</type>
<notes>
    <note reference="5432" id="753" xmlns="http://testnamespace.de/note">
        <text>example</text>
        <username>John Doe</username>
        <groups>
            <group id="42">Avengers</group>
            <group id="55">JLA</group>
        </groups>
        <distinctiveTitle>title</distinctiveTitle>
        <personNameInverted>Doe John</personNameInverted>
    </note>
</notes>

这里是相应的模板:
import module namespace tde = "http://marklogic.com/xdmp/tde" at "/MarkLogic/tde.xqy";
declare namespace testns = "http://testnamespace.de/note";

let $userNoteTDE:=
<template xmlns="http://marklogic.com/xdmp/tde" xmlns:testns="http://testnamespace.de/note">
    <context>/user/notes/testns:note</context>
    <rows>
        <row>
            <schema-name>user</schema-name>
            <view-name>notes</view-name>
            <columns>
                <column>
                    <name>reference</name>
                    <scalar-type>string</scalar-type>
                    <val>@reference</val>
                    <nullable>true</nullable>
                    <default>""</default>
                </column>
                <column>
                    <name>id</name>
                    <scalar-type>string</scalar-type>
                    <val>@id</val>
                    <nullable>true</nullable>
                    <default>""</default>
                </column>
                <column>
                    <name>text</name>
                    <scalar-type>string</scalar-type>
                    <val>text</val>
                    <nullable>true</nullable>
                    <default>""</default>
                </column>
                <column>
                    <name>username</name>
                    <scalar-type>string</scalar-type>
                    <val>username</val>
                    <nullable>true</nullable>
                    <default>""</default>
                </column>
                <column>
                    <name>distinctiveTitle</name>
                    <scalar-type>string</scalar-type>
                    <val>distinctiveTitle</val>
                    <nullable>true</nullable>
                    <default>""</default>
                </column>
                <column>
                    <name>personNameInverted</name>
                    <scalar-type>string</scalar-type>
                    <val>personNameInverted</val>
                    <nullable>true</nullable>
                    <default>""</default>
                </column>
            </columns>
        </row>
    </rows>
</template>

我更改了上下文以使用正确的 (?) 路径和命名空间(因为这部分应该嵌套到另一个模板中):
<context>/user/notes/testns:note</context>

如果我用 检查模板tde:node-data-extract(fn:doc (TESTFILE PATH), $userNoteTDE)
我得到以下输出:
    {
"TESTFILE PATH": [
  {
    "row": {
     "schema": "user", 
     "view": "notes", 
     "data": {
      "rownum": "1", 
      "reference": "5432", 
      "id": "753", 
      "text": "", 
      "username": "", 
      "distinctiveTitle": "", 
      "personNameInverted": ""
     }
    }
   }
  ]
 }

这表明,属性显示正确,但不知何故元素的值(文本、用户名、distinctTitle、personNameInverted)不起作用。
我的猜测是,这些值需要更精细的路径或表达式,但我找不到任何信息。
如果我更改 正文 值例如为 <val>testns:text</val>在我的模板中,我收到错误: XDMP-UNBPRFX: (err:XPST0081) 前缀 testns 没有命名空间绑定(bind)

所以不知何故元素不能使用声明的命名空间,但属性可以。

我也跳过了 <groups>我模板中的部分,因为他们需要自己的上下文,这应该无关紧要,是吗?

在此先感谢您提供任何有用的见解!

最佳答案

MarkLogic Support 给了我这个问题的答案,所以我想在这里分享!

(谢谢克里斯哈姆林!)

这确实是一个命名空间问题。 MarkLogic Documentation表明对于多个命名空间,应该使用“路径命名空间”。

申报后
...

    <path-namespaces>
        <path-namespace>
            <prefix>testns</prefix>
            <namespace-uri>http://testnamespace.de/note</namespace-uri>
        </path-namespace>
    </path-namespaces>
...
在模板和上下文之间,并使用 测试 在我的元素上添加前缀,例如 测试:文本 ,元素正在正确显示!

关于templates - MarkLogic 中的 XQuery 模板不显示任何值,只显示属性 (TDE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46317478/

相关文章:

c++ - 如何将结构模板标记为好友?

python - bpython -i & 命名空间

c++ - "A::B::C v;"是否意味着 A 和 B 是命名空间而 C 是一个类?

c# - 带有嵌套命名空间的编译器错误 "cannot resolve symbol"

c++ - 具有默认类型的可变参数模板

不同类型的 C++ 模板运算符重载

c++ - 如何结合切片、模板和非派生类?

jquery - Marklogic 中是否有简单的 XQuery 可以从简单的 XML 序列中生成 JSON 输出,以便与 JQuery 自动竞争一起使用

xml - 子结构上的 XPath 求和

xml - Xquery dont "filter"第一个带有属性的标签