< Pr...">

XPath with Java - choosing a text value between subtags

I am working on this html snippet:

<p class="pageSelector">
    <a href="/BlaBla">&lt; Prev</a>&nbsp;
    <a href="/BlaBla">1</a>&nbsp;
    <a href="/BlaBla">2</a>&nbsp;
    <a href="/BlaBla">3</a>&nbsp;
    4&nbsp;
    <a href="/BlaBla">5</a>&nbsp;
    <a href="/BlaBla">6</a>&nbsp;
    <a href="/BlaBla">Next &gt;</a>&nbsp;
</p>

displayed (more or less) as <Previous 1 2 3 4 5 6 Next>.

I want to select "4" because I need to open the "current" page. Using

//p[@class='pageSelector']/text()[normalize-space()]

(tested with Firefox XPath Ckecker) I decided I decided, but no, because I got 7 matches.

Can anyone tell me where I am going wrong? Thanks you

+3
source share
2 answers

normalize-space removes spaces, but a character without a break (despite its appearance) is not considered a space for this. Therefore i would do

text()[translate(., '&#x20;&#x09;&#x0a;&#x0d;&#xa0;', '')]

, , ; , , .

+3

xslt, ,

<xsl:template match="p[@class='pageSelector']/a/text()[normalize-space()]">
</xsl:template>

, 4

0

Source: https://habr.com/ru/post/1792174/


All Articles