Reputation: 415
Suppose I have the given XML
<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>
Now I would like to populate the two XPath values as a single comma separated value.
For eg. I would like to populate 2323,AQR LP i.e.[/styleml/transaction/party/partyAlias/partyAliasId ,/styleml/transaction/party/partyAlias/partyAliasLongName]
I have tried the | operator to join to XPath results , however Its populating only the first xpath data as an end result.
Upvotes: 0
Views: 57
Reputation: 43401
Be sure to respect tag case (styelml
→StyleML
).
or
I would go to something like what is described in XPath to select multiple tags:
/StyleML/transaction/party/partyAlias/*[self::partyAliasId or self::partyAliasLongName]
|
and saxon
Using saxon XQuery you can use the /path/(a|b)
syntax:
java -cp "/path/to/saxon9ee.jar" net.sf.saxon.Query -s:"/path/to/file.xml" \
-qs:"/StyleML/transaction/party/partyAlias/(partyAliasId|partyAliasLongName)"
Output:
<?xml version="1.0" encoding="UTF-8"?>
<partyAliasId>2323</partyAliasId><partyAliasLongName>AQR LP</partyAliasLongName>
<partyAliasId>2323</partyAliasId><partyAliasLongName>Scotland</partyAliasLongName>
Upvotes: 1