XPath连接多个节点 [英] XPath concat multiple nodes
问题描述
我对xpath不太熟悉。但是我正在使用xpath表达式并将其设置在数据库中。
I'm not very familiar with xpath. But I was working with xpath expressions and setting them in a database. Actually it's just the BAM tool for biztalk.
无论如何,我有一个看起来像这样的xml:
Anyway, I have an xml which could look like:
<File>
<Element1>element1<Element1>
<Element2>element2<Element2>
<Element3>
<SubElement>sub1</SubElement>
<SubElement>sub2</SubElement>
<SubElement>sub3</SubElement>
<Element3>
</File>
我想知道是否有一种方法可以使用xpath表达式来使所有SubElement保持一致?目前,我正在使用:
I was wondering if there is a way to use an xpath expression of getting all the SubElements concatted? At the moment, I am using:
/*[local-name()='File']/*[local-name()='Element3']/*[local-name()='SubElement']
如果只有一个索引,则此方法有效。但是显然我的xml有时具有更多的节点,因此它给出NULL。我可以使用
This works if it only has one index. But apparently my xml sometimes has more nodes, so it gives NULL. I could just use
/*[local-name()='File']/*[local-name()='Element3']/*[local-name()='SubElement'][0]
但是我需要所有节点。有办法吗?
but I need all the nodes. Is there a way to do this?
非常感谢!
编辑:我更改了XML,我是错的,它有所不同,应该看起来像这样:
I changed the XML, I was wrong, it's different, it should look like this:
<item>
<element1>el1</element1>
<element2>el2</element2>
<element3>el3</element3>
<element4>
<subEl1>subel1a</subEl1>
<subEl2>subel2a</subEl2>
</element4>
<element4>
<subEl1>subel1b</subEl1>
<subEl2>subel2b</subEl2>
</element4>
</item>
我需要有一个单行代码才能得到如下结果: subel2a subel2b;
And I need to have a one line code to get a result like: "subel2a subel2b";
我需要一行,因为我将此xpath表达式设置为xml属性(不是我的选择,已指定)。我尝试了string-join,但是它实际上没有用。
I need the one line because I set this xpath expression as an xml attribute (not my choice, it's specified). I tried string-join but it's not really working.
推荐答案
string-join(/ file / Element3 / SubElement,',')
这篇关于XPath连接多个节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!