XPath expression for containing element of a given text node

WebSysBoano

New Member
I am coding some Perl to use XPath to locate a particular \[code\]td\[/code\] element within a table` that looks similar to this\[code\] <table> <tr> <td>...</td> <td><font color="white" face="verdana, Helvetica, Arial" size="2">Showing <b>1</b>-<b>100</b> of <b>200</b> total</font></td> <td>...</td> <td>...</td> </tr> </table>\[/code\]What I want is to find a \[code\]td\[/code\] element that has a \[code\]font/text()\[/code\] node that contains the string \[code\]Showing\[/code\].matches \[code\]contains(., "Showing")\[/code\]A direct comparison works fine:\[code\]//td[font/text()="Showing "]\[/code\]but I want to use the \[code\]contains()\[/code\] XPath function so that the match is more flexible.I have tried\[code\]//td[contains(font/text(), "Showing ")]\[/code\]but this raises the error\[code\]XPath failed due to: A sequence of more than one item is not allowed as the first argument of contains()\[/code\]and I have managed to achieve what I want with\[code\]//td[font/text()[contains(., "Showing")]]\[/code\]but this is very ugly and I am hoping for something more concise. Please can someone improve on this for me, or perhaps confirm that this is the best and most concise way?
 
Back
Top