2

I wish to select all <span> that have only <br> as children :

<html>
..
<span>
...
</span>
<span>     <!-- I want those ones -->
  <br/>
</span>

How would I select these elements?

1 Answer 1

3

Assuming you mean elements with no children except br elements, where br is mandatory:

/html/span
    [br and not(
        *[not(self::br)]
    )]

Meaning: All span elements which have at least one br child and no other elements as children.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 More correct answer if brs are mandatory. Also, check my "only one br as content" predicate.
@Alejandro. Already checked. May be more efficient by the way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.