I would like to find the value of an element matched on id attribute for which I only have the ref - the bit with #, the anchor.
I am looking for the value of partyId:
< party id="partyA" >
< partyId >THEID< /partyId >
but to get there I only have the href from the following
< MyData >
< MyReference href="#partyA" />
Strip the # sign does not look good to me.
Any hints?
Because you haven't provided complete XML documents, I have to use //
-- a practice I strongly recommend to avoid.
Suppose that
$vDataRef
is defined as
//MyData/MyReference/@href
and its string value is "#partyA"
, then one possible XPath expression that selects the wanted node is:
//party[@id=substring($vDataRef,2)]
In case the XML document has a DTD in which the id
attribute of party
is defined to be of type ID
, then it is more convenient and efficient to use the standard XPath function id()
:
id(substring($vDataRef,2))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With