加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – 使用xpath在Teiid中将多个属性连接与节点值连接起来

发布时间:2020-12-16 22:47:33 所属栏目:百科 来源:网络整理
导读:这是我在 here年发布的问题的副本 我只需要注意这是在teiid引擎的XMLTABLE中发生的.我正在解析以下xml内容: AttributeSets ns2:ItemAttributes xml:lang="de-DE" ns2:Creator Role="Role1"Creator One/ns2:Creator ns2:Creator Role="Role2"Creator Two/ns2
这是我在 here年发布的问题的副本
我只需要注意这是在teiid引擎的XMLTABLE中发生的.我正在解析以下xml内容:

<AttributeSets>
    <ns2:ItemAttributes xml:lang="de-DE">
        <ns2:Creator Role="Role1">Creator One</ns2:Creator>
        <ns2:Creator Role="Role2">Creator Two</ns2:Creator>
        <ns2:Creator Role="Role3">Creator Three</ns2:Creator>
    </ns2:ItemAttributes>
</AttributeSets>

运用

Select * From
        XMLTABLE(XMLNAMESPACES( DEFAULT 'http://ns1','http://ns2/default.xsd' as ns2 ),'AttributeSets/ns2:ItemAttributes' PASSING x.AttributeSets
        COLUMNS 
            Creator STRING PATH 'string-join(//ns2:Creator/(@Role,node()),'','')'
    ) p;

这里x.AttributeSets是一个xml类型的变量,其内容来自上面.

我正在尝试使用xpath格式化并将其组合成一行.
就像是:

string-join(//ns2:Creator/concat(./text(),@Role),',')

我想,我在某个地方很近,因为这个:

string-join(//ns2:Creator/@Role,')

工作并给我一个以逗号分隔的角色列表:Role1,Role2,Role3

还有这个

string-join(//ns2:Creator/node(),')

结合创作者的价值观:“造物主一,造物主二,造物主三”.

我想要最后的输出

Role1: Creator One,Role2: Creator Two,Role3: Creator Three

我能得到的最多是:

string-join(//ns2:Creator/(@Role,')

这个逗号将所有角色和创建者分成一行.由于某种原因,concat运算符似乎无法工作.
能否请你帮忙.

解决方法

尝试以下xpath

string-join(for $n in /AttributeSets/ItemAttributes/Creator return concat($n/@Role,':',$n/text()),')

请记住根据源树上下文调整for中的选择器xpath.因此,我认为文件根

/AttributeSets/ItemAttributes/Creator

W3C的字符串连接函数的文档有一个非常相似的例子.

更新:

I think,i’m somewhere close,because this: … works and gives me a comma-separated list of roles: Role1,Role3

认为你很亲密.我尝试了一个小的调整,这工作:

string-join(//ns2:Creator/concat(@Role,./text()),')

For some reason the concat operator seems no to work.

不确定,我检查了一个在线xpath测试仪here,它完美地工作.事实上,在线工具也接受你的xapth以及以下输出:

Creator OneRole1,Creator TwoRole2,Creator ThreeRole3

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读