xpath expression to remove whitespace

前端 未结 6 1988
野性不改
野性不改 2020-12-08 00:18

I have this HTML:

 
   
     

        
6条回答
  •  难免孤独
    2020-12-08 00:30

    I. Use this single XPath expression:

    translate(normalize-space(/tr/td/a), ' ', '')
    

    Explanation:

    1. 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.

    2. 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, ' 	
    
', '')
    

提交回复
热议问题