Getting Upper XPath Value Based on Lower XML value
I'm trying to get the value of SERepeatKey if ItemOID REQUIRED.REQ_V has a value of "1". In the below case I want to return the value 2. Is this possible with this XML? If so how?
With this I was able to do it if there was only 1 "Data" node but now with 2 I am at a loss. In XPath tester I get the below error message.
string(ODM/Data/SData[@SKey='003-003' and SiteRef[@LOID='SE 003']]/SEData[@SEOID='UNSCHEDULED']/@SERepeatKey)
"Unable to perform XPath operation. A sequence of more than one item is not allowed as the first argument of string() (@SERepeatKey, @SERepeatKey)"
<ODM>
<Data SOID="(DEV)" MetaDataVersionOID="" >
<SData SKey="003-003" >
<SiteRef LOID="SE 003"/>
<SEData SEOID="UNSCHEDULED" SERepeatKey="1">
<FData FOID="REQUIRED" FormRepeatKey="1">
<IGData IGOID="REQUIRED" IGRepeatKey="0" TransactionType="Upsert">
<IData ItemOID="REQUIRED.REQ_V" Value="0" />
</IGData>
</FData>
</SEData>
</SData>
</Data>
<Data SOID="(DEV)" MetaDataVersionOID="" >
<SData SKey="003-003" >
<SiteRef LOID="SE 003"/>
<SEData SEOID="UNSCHEDULED" SERepeatKey="2">
<FData FOID="REQUIRED" FormRepeatKey="1">
<IGData IGOID="REQUIRED" IGRepeatKey="0" TransactionType="Upsert">
<IData ItemOID="REQUIRED.REQ_V" Value="1" />
</IGData>
</FData>
</SEData>
</SData>
</Data>
<Data SOID="(DEV)" MetaDataVersionOID="" >
<SData SKey="003-003" >
<SiteRef LOID="SE 003"/>
<SEData SEOID="UNSCHEDULED" SERepeatKey="3">
<FData FOID="REQUIRED" FormRepeatKey="1">
<IGData IGOID="REQUIRED" IGRepeatKey="0" TransactionType="Upsert">
<IData ItemOID="REQUIRED.REQ_V" Value="1" />
</IGData>
</FData>
</SEData>
</SData>
This XPath should do what you are looking for:
//Data[.//IData[@ItemOID='REQUIRED.REQ_V' and @Value='1']]//SEData/@SERepeatKey
According to the presented XML looks like you can even omit @ItemOID='REQUIRED.REQ_V'
and make this expression simpler
//Data[.//IData[@Value='1']]//SEData/@SERepeatKey