【发布时间】:2018-11-29 22:25:51
【问题描述】:
我正在编写一个 xquery,我必须在其中检查属性的值是否为真。属性/元素定义为布尔值。 我尝试了多个选项,但无法获得正确的值,该逻辑适用于其他元素,但不适用于“MainCustomer”,因为它被定义为布尔值。我该如何为此编写 xquery?
以下是我的请求示例:
<Maintenance xmlns="*******">
<AccountPersons>
<APH AccountID="56987" LastFinancialRespSwitch="Y" LastMainCustomerSwitch="Y" LastPersonID="987569" QuickAddSwitch="false"/>
<APR AccountID="98759" AccountRelationshipType="MIN" BillAddressSource="PER" PersonID="000000" MainCustomer="true"></APR>
<APR AccountID="123456" AccountRelationshipType="MAIN" BillAddressSource="PERSON" PersonID="123456" MainCustomer="false"></APR>
</AccountPersons>
</Maintenance>
我在 for 循环中使用 if 语句。APR 是一个数组。
我只想从 MainCustomer="true" 的那些 APR 中获取 BillAddressSource 的值
下面的 xquery 不起作用,它给了我所有 APR 的值。
if (fn:boolean($MaintenanceResponse/ns1:AccountPersons/ns1:APR[$position]/@MainCustomer))
then
<acc:data>
{if ($MaintenanceResponse/ns1:AccountPersons/ns1:APR[$position]/@BillAddressSource)
then <acc:addressSource>{fn:data($MaintenanceResponse/ns1:AccountPersons/ns1:APR[$position]/@BillAddressSource)}</acc:addressSource>
else ()
}
</acc:data>
我尝试的另一个 xquery 是,这给了我语法错误
if ($MaintenanceResponse/ns1:AccountPersons/ns1:APR[$position]/@MainCustomer='true')
then
<acc:data>
{if ($MaintenanceResponse/ns1:AccountPersons/ns1:APR[$position]/@BillAddressSource)
then <acc:addressSource>{fn:data($MaintenanceResponse/ns1:AccountPersons/ns1:APR[$position]/@BillAddressSource)}</acc:addressSource>
else ()
}
</acc:data>
请帮我找到一个正确的 if 语句。提前致谢
【问题讨论】:
标签: if-statement boolean xquery