jeudi 29 novembre 2018

xquery to check xquery how to check if value of boolean variable is true

i am writing a xquery in which I have to check if the value of anattribute is true. The attribute / element is defined as Boolean. I tried multiple options but I am not able to get the correct value, the logic works for other elements but not for 'MainCustomer' since it is defined Boolean. How can I write the xquery for this?

Below is the example of my request:

<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>

I am using the if statement inside for loop.APR is an array. I want to get the value of BillAddressSource from only those APR where MainCustomer="true" below xquery doesn't work it gives me the values from all the 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> 

Another xquery I tried is, this gives me syntax error

        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>  

Please help me find a correct if statement . Thanks in advance

Aucun commentaire:

Enregistrer un commentaire