简体   繁体   中英

How to select all h tags starting from a certain number (XPath)?

我想选择所有h标签,例如从标签h3 ,即h3h4h5 ...我知道如何仅选择h3

//h:h3

Use this:

//*[matches(name(), '^h\d')]

if there are namespaces in element name then use:

//*[matches(local-name(), '^h\d')]

XPath 1.0

Keep it simple and just enumerate them:

//*[self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]

XPath 2.0

You can use regex in various ways. For example...

For all tags of the form h number :

//*[matches(local-name(),'^h\d+$')]

For a limited range of a single digit:

//*[matches(local-name(),'^h[3-6]$')]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM