如何在xQuery中获取没有子节点的节点?
所以我有两个元素节点,我本质上是想加入它们。我希望顶级节点保持不变,但子节点将被交叉引用的节点替换。
鉴于:
<stuff>
<item foo="foo" boo="1"/>
<item foo="bar" boo="2" />
<item foo="baz" boo="3"/>
<item foo="blah boo="4""/>
</stuff>
<list a="1" b="2">
<foo>bar</foo>
<foo>baz</foo>
</list>
我想循环遍历“列表”并交叉引用“东西”中的元素以获得此结果:
<list a="1" b="2">
<item foo="bar" boo="2" />
<item foo="baz" boo="3"/>
</list>
我想执行此操作而不必知道“列表”上可能有哪些属性。换句话说,我不想像这样明确地称呼它们
attribute a { $list/@a }, attribute b { $list/@b }
So I have two nodes of elements that I'm essentially trying to join. I want the top level node to stay the same but the child nodes to be replaced by those cross referenced.
Given:
<stuff>
<item foo="foo" boo="1"/>
<item foo="bar" boo="2" />
<item foo="baz" boo="3"/>
<item foo="blah boo="4""/>
</stuff>
<list a="1" b="2">
<foo>bar</foo>
<foo>baz</foo>
</list>
I want to loop through "list" and cross reference elements in "stuff" for this result:
<list a="1" b="2">
<item foo="bar" boo="2" />
<item foo="baz" boo="3"/>
</list>
I want to do this without having to know about what attributes might be on "list". In other words I don't want to have to explicitly call them out like
attribute a { $list/@a }, attribute b { $list/@b }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用:
$list1/item[@foo = $list2/item/@foo]
这会选择所有- <
$list1
中的 /code> 元素,其foo
属性的值等于- 之一的
元素。foo
属性;$list2 中的要复制
元素的所有属性,请执行以下操作:Use:
$list1/item[@foo = $list2/item/@foo]
This selects all
<item>
elements in$list1
the value of whosefoo
attribute is equal to thefoo
attribute of one of the<item>
elements in $list2.In order to copy all attributes of the
<list>
element, do something like this:稍微简单一点...从现有对象创建一个新对象,但没有其子对象,仅
假设属性:
let $old_list :=
这将创建一个复制其属性的新列表
Slightly simplier ... to create a new object from an existing one, but without its children only attributes
assume :
let $old_list :=
This creates a new list copying its attributes