I have this HTML:
<tr class="even expanded first> <td class="score-time status"> <a href="/matches/2012/08/02/europe/uefa-cup/"> 16 : 00 </a> </td> </tr>
I want to extract the (16 : 00) string without the extra whitespace. Is this possible?
normalize-space() produces a new string from its argument, in which any leading or trailing white-space (space, tab, NL or CR characters) is deleted and any intermediary white-space is replaced by a single space character.
XPath/XQuery normalize-space function Returns the value of $arg with leading and trailing whitespace removed, and sequences of internal whitespace reduced to a single space character.
If an element has spaces in its text or in the value of any attribute, then to create an xpath for such an element we have to use the normalize-space function. It removes all the trailing and leading spaces from the string. It also removes every new tab or lines existing within the string.
The normalize-space(String s) method is used to normalize a string i.e. to remove any leading or trailing spaces from the string s passed as parameter to the XPath function.
I. Use this single XPath expression:
translate(normalize-space(/tr/td/a), ' ', '')
Explanation:
normalize-space()
produces a new string from its argument, in which any leading or trailing white-space (space, tab, NL or CR characters) is deleted and any intermediary white-space is replaced by a single space character.
translate()
takes the result produced by normalize-space()
and produces a new string in which each of the remaining intermediary spaces is replaced by the empty string.
II. Alternatively:
translate(/tr/td/a, ' 	 
', '')
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