如何使用 Xquery 在序列中获取节点的相同属性值?
How to get same attribute values of a node, in a sequence using Xquery?
Hi..I would like to print attribute values in a sequence ,for example If have an XML which looks like below
<module>
<content>
<catalouge SC="25" item="200">
<Number id="250" >
<Character condValue="PRE" changeMark="1">
<count Number="1" </count>
</Character>
<Character condValue="EMB">
<count Number="154"</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="200" >
<Number id="780">
<Character condValue="EMB" changeMark="1">
<count Number="1" </count>
</Character>
<Character condValue="EMB">
<count Number="154"</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="240">
<Number id="666" Value="123" >
<Character condValue="EMB">
<count Number="2" </count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="280">
<Number id="1994" Value="1234" >
<Character condValue="POST">
<count Number="3"</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="300">
<Number id="19956" Value="1235">
<Character condValue="PRE">
<count Number="4" </count>
</Character>
</Number>
</catalouge>
</content>
</module>
Please find below xquery which i have tried
for $p in doc("abc.xml")//module/content
let $csns := $p/catalouge
for $csn in $csns
let $item := $csn/string(@item)
let $isns := $csn/Number
for $isn in $isns
let $id := $isn/string(@id)
let $chr := $isn/Character/string(@condValue)
return $chr
输出:
当我 运行 时,我从上面的 Xquery
得到如下输出
前
EMB
EMB
EMB
EMB
POST
前
但是我需要这样,下面怎么实现
("PRE","EMB")
("EMB","EMB")
"EMB"
"POST"
"PRE"
怎么样
for $number in $doc//catalouge//Number
return string-join($number//Character//@condValue,", ")
输出:
PRE, EMB
EMB, EMB
EMB
POST
PRE
Hi..I would like to print attribute values in a sequence ,for example If have an XML which looks like below
<module>
<content>
<catalouge SC="25" item="200">
<Number id="250" >
<Character condValue="PRE" changeMark="1">
<count Number="1" </count>
</Character>
<Character condValue="EMB">
<count Number="154"</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="200" >
<Number id="780">
<Character condValue="EMB" changeMark="1">
<count Number="1" </count>
</Character>
<Character condValue="EMB">
<count Number="154"</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="240">
<Number id="666" Value="123" >
<Character condValue="EMB">
<count Number="2" </count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="280">
<Number id="1994" Value="1234" >
<Character condValue="POST">
<count Number="3"</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="300">
<Number id="19956" Value="1235">
<Character condValue="PRE">
<count Number="4" </count>
</Character>
</Number>
</catalouge>
</content>
</module>
Please find below xquery which i have tried
for $p in doc("abc.xml")//module/content
let $csns := $p/catalouge
for $csn in $csns
let $item := $csn/string(@item)
let $isns := $csn/Number
for $isn in $isns
let $id := $isn/string(@id)
let $chr := $isn/Character/string(@condValue)
return $chr
输出: 当我 运行 时,我从上面的 Xquery
得到如下输出前
EMB
EMB
EMB
EMB
POST
前
但是我需要这样,下面怎么实现
("PRE","EMB")
("EMB","EMB")
"EMB"
"POST"
"PRE"
怎么样
for $number in $doc//catalouge//Number
return string-join($number//Character//@condValue,", ")
输出:
PRE, EMB
EMB, EMB
EMB
POST
PRE