kovalu
kovalu

Reputation: 129

XPath - trim and starts-with together (cut of whitespaces)

I have XML like this:

<div class="errorMessage">
    <ul>
        <li>
            <a href="...">
                ABC - efg
            </a>
            <a href="...">
                HIJ - klm
            </a>
        </li>
    </ul>
</div>

How do I select link's text which starts with "ABC"? I need to trim the "text()" of "a" and apply "starts-with()" on it. I have something like this, but it doesn't work:

//div[@class='errorMessage']/.//a[starts-with(normalize-space(./text())),'ABC')]/text()

Upvotes: 1

Views: 2751

Answers (1)

forty-two
forty-two

Reputation: 12817

This ought to work:

//div[@class='errorMessage']//a[starts-with(normalize-space(.), 'ABC')]/text()

Upvotes: 2

Related Questions