假设我有给定的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>
现在我想将两个XPath值填充为单个逗号分隔值。
例如。我想填写2323,AQR LP,即[/ styleml / transaction / party / partyAlias / partyAliasId,/ styleml / transaction / party / partyAlias / partyAliasLongName]
我试过了|运算符加入XPath结果,但它只填充第一个xpath数据作为最终结果。
答案 0 :(得分:1)
请务必尊重标记案例(styelml
→StyleML
)。
or
我会像XPath to select multiple tags中描述的那样:
/StyleML/transaction/party/partyAlias/*[self::partyAliasId or self::partyAliasLongName]
|
和saxon
使用saxon XQuery,您可以使用/path/(a|b)
语法:
java -cp "/path/to/saxon9ee.jar" net.sf.saxon.Query -s:"/path/to/file.xml" \
-qs:"/StyleML/transaction/party/partyAlias/(partyAliasId|partyAliasLongName)"
输出:
<?xml version="1.0" encoding="UTF-8"?>
<partyAliasId>2323</partyAliasId><partyAliasLongName>AQR LP</partyAliasLongName>
<partyAliasId>2323</partyAliasId><partyAliasLongName>Scotland</partyAliasLongName>