我被困在Xquery的一个地方。在响应中,我想恢复每种类型的电话号码,即主页和单元格,但只有最高序列号的电话。如果有两个行带有phoneType =" home",我希望回到具有最高序列的手机在我的情况下,序列=" 3"。
使用我的Xquery,我可以回到phoneType =" home"和带有类型home的第一行。我也无法添加条件来检查序列。我在哪里以及如何添加它。请建议。预先感谢
我Xquery的一部分:
<acc:phones>
{
for $PersonPhonesRow in $PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[@PhoneType="HOME"][1]
return
if(fn:data($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow/@PhoneType="HOME"[1]))
then
<com:phone>
<com:type>{'HOME'}</com:type>
<com:phoneNumber>{fn:data($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[@PhoneType="HOME"][1]/@PhoneNumber)}</com:phoneNumber>
<com:carrier>{fn:data($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[@PhoneType="HOME"][1]/@Extension)}</com:carrier>
</com:phone>
else
()
}
</acc:phones>
请求:
<CMPerson xmlns="http://splwg.com/CMPerson.xsd">
<CMPersonService>
<CMPersonDetails>
<PersonPhones>
<PersonPhonesHeader PersonID="1234567890" LastSequenceNumber="9"/>
<PersonPhonesRow PersonID="1234567890" Sequence="1" PhoneType="HOME" IntlPrefix="" PhoneNumber="(850) 123-0000" Extension="" Version="12" PhoneAlgorithmParamValue="(999) 999-9999"/>
<PersonPhonesRow PersonID="1234567890" Sequence="2" PhoneType="CELL" IntlPrefix="" PhoneNumber="(850) 000-0000" Extension="" Version="3" PhoneAlgorithmParamValue="(999) 999-9999"/>
<PersonPhonesRow PersonID="1234567890" Sequence="3" PhoneType="HOME" IntlPrefix="" PhoneNumber="(850) 123-1111" Extension="ATT" Version="1" PhoneAlgorithmParamValue="(999) 999-9999"/>
<PersonPhonesRow PersonID="1234567890" Sequence="4" PhoneType="BUSN" IntlPrefix="" PhoneNumber="(904) 111-1111" Extension="" Version="3" PhoneAlgorithmParamValue="(999) 999-9999"/>
</PersonPhones>
</CMPersonDetails>
</CMPersonService>
</CMPerson>
需要响应:
<acc:phones>
<com:phone xmlns:com="******">
<com:type>HOME</com:type>
<com:phoneNumber>(850) 123-1111</com:phoneNumber>
<com:carrier>ATT</com:carrier>
</com:phone>
<com:phone xmlns:com="******">
<com:type>CELL</com:type>
<com:phoneNumber>(904) 111-1111</com:phoneNumber>
<com:carrier></com:carrier>
</com:phone>
</acc:phones>
要使用的查询:
let $PersonMaintenanceResponse := 'Your request'
let $uniqPhoneType :=distinct-values($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow/@PhoneType)
for $each at $i in $uniqPhoneType
return
<acc:phones>
{
let $seq := $PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[(@PhoneType = $each)]
let $maxValue := max($seq/@Sequence)
let $maxrow := $seq[@Sequence eq $maxValue]
return
<com:phone xmlns:com="*******">
<com:type>{$each}</com:type>
<com:phoneNumber>{$maxrow/@PhoneNumber}</com:phoneNumber>
<com:carrier>{$maxrow/@Extension}</com:carrier>
</com:phone>
}</acc:phones>