XPTY0004 预期项目,找到序列,如何使用 Xquery 查找序列中是否存在值
XPTY0004 Item expected, sequence found, How to find whether a value is present in a sequence or not using Xquery
Hi.. I would like to find whether a value is present in a sequence or not ,for example If I have an XML which looks like below
<module>
<content>
<customer SC="25" item="200">
<Number id="250">
<Character Value="PRE" Evaluate="1">
<count Number="1" Name="Sree">FOR XYZ 1994, 1995, 1996, 1997, 0357, 0376</count>
</Character>
<Character Value="EMB">
<count Number="154" Name="Sree" Evaluate="1">FOR XYZ 1995, 1996, 1994, 1997, 0357, 0376</count>
</Character>
</Number>
</customer>
<customer SC="25" item="200" >
<Number id="780" >
<Character Value="EMB" Evaluate="1">
<count Number="1" Name="Sree">FOR XYZ 1998, 1995, 1996, 1994, 0357, 0376</count>
</Character>
<Character Value="EMB">
<count Number="154" Name="Sree" Evaluate="1">FOR XYZ 0357, 1995, 1996, 1997, 1994, 0376</count>
</Character>
</Number>
</customer>
<customer SC="25" item="240">
<Number id="666" Value="123" >
<Character Value="EMB">
<count Number="2" Name="Sree" Evaluate="1">FOR XYZ 1995, 1994, 1996, 1997, 0357, 0376</count>
</Character>
</Number>
</customer>
<customer SC="25" item="280">
<Number id="1994" Value="1234" >
<Character Value="POST">
<count Number="3" Name="Sree" Evaluate="1">FOR XYZ 1994, 1995, 1909, 1997, 0357, 0376</count>
</Character>
</Number>
</customer>
<customer SC="25" item="300">
<Number id="19956" Value="1235" >
<Character Value="PRE">
<count Number="4" Name="Sree" Evaluate="1">FOR XYZ 1997, 1995, 1996, 1994, 0357, 0376</count>
</Character>
</Number>
</customer>
</content>
</module>
Please find below xquery
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 $count := $isn/Character/data(count)
let $count_status := contains($count, '1994')
return $count_status
am trying to check whether count tag has a value 1994 (FOR A/C 1994, 1995, 1996, 1997, 0357, 0376) which returns boolean value
While running Xquery I have tried with contains function but in vain, I got an error when i ran above Xquery
错误:
[XPTY0004] 预期的项目,找到的序列:(“FOR A/C 1994、1995、1996、1997、0357、0376”,...)。
但是我需要return一个布尔值
请尝试以下 XQuery。我在 BaseX 9.4.6
测试过
XQuery
xquery version "3.1";
declare variable $year as xs:string :='1994';
declare context item := document {
<module>
<content>
<catalouge SC="25" item="200">
<Number id="250" RefIds="xyz20000">
<Character condValue="PRE" changeMark="1">
<count Number="1" Name="Sree">FOR A/C 1994, 1995, 1996, 1997, 0357, 0376</count>
</Character>
<Character condValue="EMB">
<count Number="154" Name="Sree" changeMark="1">FOR A/C 1995, 1996, 1994, 1997, 0357, 0376</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="200">
<Number id="780" RefIds="xyz20000">
<Character condValue="EMB" changeMark="1">
<count Number="1" Name="Sree">FOR A/C 1998, 1995, 1996, 1994, 0357, 0376</count>
</Character>
<Character condValue="EMB">
<count Number="154" Name="Sree" changeMark="1">FOR A/C 0357, 1995, 1996, 1997, 1994, 0376</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="240">
<Number id="666" Value="123" RefIds="xyz20000">
<Character condValue="EMB">
<count Number="2" Name="Sree" changeMark="1">FOR A/C 1995, 1994, 1996, 1997, 0357, 0376</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="280">
<Number id="1994" Value="1234" RefIds="xyz20000">
<Character condValue="POST">
<count Number="3" Name="Sree" changeMark="1">FOR A/C 1994, 1995, 1909, 1997, 0357, 0376</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="300">
<Number id="19956" Value="1235" RefIds="xyz20000">
<Character condValue="PRE">
<count Number="4" Name="Sree" changeMark="1">FOR A/C 1997, 1995, 1996, 1994, 0357, 0376</count>
</Character>
</Number>
</catalouge>
</content>
</module>
};
<root>
{
for $x in ./module/content/catalouge/Number/Character/count
return <r status='{contains($x/text(), $year)}'>{data($x)}</r>
}
</root>
输出
<root>
<r status="true">FOR A/C 1994, 1995, 1996, 1997, 0357, 0376</r>
<r status="true">FOR A/C 1995, 1996, 1994, 1997, 0357, 0376</r>
<r status="true">FOR A/C 1998, 1995, 1996, 1994, 0357, 0376</r>
<r status="true">FOR A/C 0357, 1995, 1996, 1997, 1994, 0376</r>
<r status="true">FOR A/C 1995, 1994, 1996, 1997, 0357, 0376</r>
<r status="true">FOR A/C 1994, 1995, 1909, 1997, 0357, 0376</r>
<r status="true">FOR A/C 1997, 1995, 1996, 1994, 0357, 0376</r>
</root>
Hi.. I would like to find whether a value is present in a sequence or not ,for example If I have an XML which looks like below
<module>
<content>
<customer SC="25" item="200">
<Number id="250">
<Character Value="PRE" Evaluate="1">
<count Number="1" Name="Sree">FOR XYZ 1994, 1995, 1996, 1997, 0357, 0376</count>
</Character>
<Character Value="EMB">
<count Number="154" Name="Sree" Evaluate="1">FOR XYZ 1995, 1996, 1994, 1997, 0357, 0376</count>
</Character>
</Number>
</customer>
<customer SC="25" item="200" >
<Number id="780" >
<Character Value="EMB" Evaluate="1">
<count Number="1" Name="Sree">FOR XYZ 1998, 1995, 1996, 1994, 0357, 0376</count>
</Character>
<Character Value="EMB">
<count Number="154" Name="Sree" Evaluate="1">FOR XYZ 0357, 1995, 1996, 1997, 1994, 0376</count>
</Character>
</Number>
</customer>
<customer SC="25" item="240">
<Number id="666" Value="123" >
<Character Value="EMB">
<count Number="2" Name="Sree" Evaluate="1">FOR XYZ 1995, 1994, 1996, 1997, 0357, 0376</count>
</Character>
</Number>
</customer>
<customer SC="25" item="280">
<Number id="1994" Value="1234" >
<Character Value="POST">
<count Number="3" Name="Sree" Evaluate="1">FOR XYZ 1994, 1995, 1909, 1997, 0357, 0376</count>
</Character>
</Number>
</customer>
<customer SC="25" item="300">
<Number id="19956" Value="1235" >
<Character Value="PRE">
<count Number="4" Name="Sree" Evaluate="1">FOR XYZ 1997, 1995, 1996, 1994, 0357, 0376</count>
</Character>
</Number>
</customer>
</content>
</module>
Please find below xquery
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 $count := $isn/Character/data(count)
let $count_status := contains($count, '1994')
return $count_status
am trying to check whether count tag has a value 1994 (FOR A/C 1994, 1995, 1996, 1997, 0357, 0376) which returns boolean value While running Xquery I have tried with contains function but in vain, I got an error when i ran above Xquery
错误: [XPTY0004] 预期的项目,找到的序列:(“FOR A/C 1994、1995、1996、1997、0357、0376”,...)。
但是我需要return一个布尔值
请尝试以下 XQuery。我在 BaseX 9.4.6
测试过XQuery
xquery version "3.1";
declare variable $year as xs:string :='1994';
declare context item := document {
<module>
<content>
<catalouge SC="25" item="200">
<Number id="250" RefIds="xyz20000">
<Character condValue="PRE" changeMark="1">
<count Number="1" Name="Sree">FOR A/C 1994, 1995, 1996, 1997, 0357, 0376</count>
</Character>
<Character condValue="EMB">
<count Number="154" Name="Sree" changeMark="1">FOR A/C 1995, 1996, 1994, 1997, 0357, 0376</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="200">
<Number id="780" RefIds="xyz20000">
<Character condValue="EMB" changeMark="1">
<count Number="1" Name="Sree">FOR A/C 1998, 1995, 1996, 1994, 0357, 0376</count>
</Character>
<Character condValue="EMB">
<count Number="154" Name="Sree" changeMark="1">FOR A/C 0357, 1995, 1996, 1997, 1994, 0376</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="240">
<Number id="666" Value="123" RefIds="xyz20000">
<Character condValue="EMB">
<count Number="2" Name="Sree" changeMark="1">FOR A/C 1995, 1994, 1996, 1997, 0357, 0376</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="280">
<Number id="1994" Value="1234" RefIds="xyz20000">
<Character condValue="POST">
<count Number="3" Name="Sree" changeMark="1">FOR A/C 1994, 1995, 1909, 1997, 0357, 0376</count>
</Character>
</Number>
</catalouge>
<catalouge SC="25" item="300">
<Number id="19956" Value="1235" RefIds="xyz20000">
<Character condValue="PRE">
<count Number="4" Name="Sree" changeMark="1">FOR A/C 1997, 1995, 1996, 1994, 0357, 0376</count>
</Character>
</Number>
</catalouge>
</content>
</module>
};
<root>
{
for $x in ./module/content/catalouge/Number/Character/count
return <r status='{contains($x/text(), $year)}'>{data($x)}</r>
}
</root>
输出
<root>
<r status="true">FOR A/C 1994, 1995, 1996, 1997, 0357, 0376</r>
<r status="true">FOR A/C 1995, 1996, 1994, 1997, 0357, 0376</r>
<r status="true">FOR A/C 1998, 1995, 1996, 1994, 0357, 0376</r>
<r status="true">FOR A/C 0357, 1995, 1996, 1997, 1994, 0376</r>
<r status="true">FOR A/C 1995, 1994, 1996, 1997, 0357, 0376</r>
<r status="true">FOR A/C 1994, 1995, 1909, 1997, 0357, 0376</r>
<r status="true">FOR A/C 1997, 1995, 1996, 1994, 0357, 0376</r>
</root>