I have an XML document that i need to strip out particular pieces of data
the xml document has a structure as follows:-
<a> <b select='yes please'> <c d='text1' e='text11'/> <c d='text2' e='text12'/> <c d='text3' e='text13'/> <c d='text4' e='text14'/> <c d='text5' e='text15'/> </b> </a> <a> <b select='no thanks'> <c d='text1' e='text21'/> <c d='text3' e='text23'/> <c d='text5' e='text25'/> </b> </a> <a> <b select='yes please'> <c d='text1' e='text31'/> <c d='text2' e='text32'/> <c d='text3' e='text33'/> <c d='text4' e='text34'/> <c d='text5' e='text35'/> </b> </a> <a> <b select='no thanks'> <c d='text4' e='text41'/> <c d='text3' e='text43'/> <c d='text5' e='text45'/> </b> </a>
i need to select only those /a/b element groups that have d attribute = 'text1' and d attribute = 'text4', once i have identified these sub documents i want to get the value of the e attributes with d attribute value 'text5'
hope thats clear
Cheers
DD
XPath text() function is a built-in function of the Selenium web driver that locates items based on their text. It aids in the identification of certain text elements as well as the location of those components within a set of text nodes. The elements that need to be found should be in string format.
You can use this XPath:
//a[b/c/@d = 'text1' and b/c/@d = 'text4']/b/c[@d = 'text5']/@e
It will select e='text15'
and e='text35'
of 1st and 3rd a/b
XSLT:
<xsl:template match="//a[b/c/@d = 'text1' and b/c/@d = 'text4']/b/c[@d = 'text5']"> <xsl:value-of select="@e"/> </xsl:template>
i need to select only those /a/b element groups that have d attribute = 'text1' and d attribute = 'text4', once i have identified these sub documents i want to get the value of the e attributes with d attribute value 'text5'
hope thats clear
Yes, it's so clear the translation into XPath is almost mechanical
(: those /a/b element groups :) a/b (: that have d attribute = 'text1' :) [c/@d='text1'] (: and d attribute = 'text4' :) [c/@d='text4'] (: and .. i want to get the value of the e attributes with d attribute value 'text5' :) / c[@d='text5'] / @e
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