1

Below is the XML from which I need the data

<StyleML>
<transaction>
    <party>
    <partyId>Party1</partyId>
    <partyAlias>
        <partyAliasId>2323</partyAliasId>
        <partyAliasLongName>AQR LP</partyAliasLongName>
         </partyAlias>
         </party>
    <party>
    <partyId>Party2</partyId>
    <partyAlias>
         <partyAliasId>2323</partyAliasId>
         <partyAliasLongName>Scotland</partyAliasLongName>
    </partyAlias>
    </party>
         <transactionParticipant>
              <counterpartyRef>Party2</counterpartyRef>
              <participantType>Counterparty Participant</participantType>
         </transactionParticipant>
         <transactionParticipant>
             <counterpartyRef>Party3</counterpartyRef>
             <participantType>Broker Participant</participantType>
         </transactionParticipant>
    </transaction>
</StyleML>

I need partyAliasLongName from the party whose participation type is counterpartyParticipant.

i.e. in the above example , I want data from Party whose id is 'Party 2' as from the transaction Participant , we can conclude that for counterParty Participant party id is 'Party2'

I want to sum up this condition in Xpath , however i am not sure how to do that. Any help would be greatful.

4

3 回答 3

1

In response to you're follow up question:

Perhaps the XQuery route could be a solution.

for $x in /StyleML/transaction/transactionParticipant
where $x/counterpartyRef='Party2'
return <result>{data($x/./counterpartyRef)} {data($x/./participantType)}</result>

This would return the result "Party2 Counterparty Participant".

于 2013-09-12T14:49:02.457 回答
0

Try this xPath here:

//party[./partyId/text() = //transactionParticipant[./participantType/text() = 'Counterparty Participant']/counterpartyRef/text()]/partyId/text()

What you want to do, is find the element, for which the condition in the corresponding bracket [] is valid.

E.g. here you can test the xPath, for me it is working with your example.

Edit: So this xPath searches for a party element whose partyId is in the corresponding transactionParticipant which has the participantType "Counterparty Participant". The text() stuff is to adress the text-node of the xml-element. The stuff behind the brackets then selects those subparts of the xml-elements you wanted to have.

于 2013-09-12T05:52:00.427 回答
0

I need <partyAliasLongName> from the <party> whose <participantType> is 'Counterparty Participant'.

Wrapped for legibility:

//party[
  partyId = //participantType[. = 'Counterparty Participant']/../counterpartyRef
]//partyAliasLongName
于 2013-09-12T06:14:27.963 回答