2

I have tried to find example without success

Here an example with an XML doc :

<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <name>vlabresvsanvc01</name>
    <adapterKindKey>VMWARE</adapterKindKey>
    <resourceKindKey>VMwareAdapter Instance</resourceKindKey>
    <resourceStatusStates>
        <adapterInstanceId>85966e95-1ds5-4551-aecb-d707c9453efe</adapterInstanceId>
        <resourceStatus>DATA_RECEIVING</resourceStatus>
        <resourceState>STARTED</resourceState>
        <statusMessage></statusMessage>
    </resourceStatusStates>
    <resourceStatusStates>
        <adapterInstanceId>95f3530e-a526-4a21-bd92-c0f391a8c2ad</adapterInstanceId>
        <resourceStatus>DATA_RECEIVING</resourceStatus>
        <resourceState>STARTED</resourceState>
        <statusMessage>Trust Established.</statusMessage>
    </resourceStatusStates>
    <identifier>95f3530e-a526-4a21-bd92-c0f391a8c2ad</identifier>
</root>

I want only to select the resourceStatus (/root/resourceStatusStates/resourceStatus) for the adapterInstanceId sibling( 95f3530e-a526-4a21-bd92-c0f391a8c2ad ) that is equal to the identifier (/root/identifier).

I'm in fact wondering if this is possible to express that in XPath 2.0.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
fd06
  • 23
  • 2

1 Answers1

1

This XPath,

/root/resourceStatusStates[adapterInstanceId = /root/identifier]/resourceStatus

will select resourceStatus elements with a sibling adapterInstanceId equal to the /root/identifier,

<resourceStatus>DATA_RECEIVING</resourceStatus>

as requested.

See also Matching a node based on a sibling's value with XPath

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • HI . Thanks a lot. That is exactly what I was looking for. thanks also for the link – fd06 May 21 '20 at 16:38