简体   繁体   English

如何选择从某个数字(XPath)开始的所有h标签?

[英]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 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 XPath 2.0

You can use regex in various ways. 您可以通过多种方式使用正则表达式。 For example... 例如...

For all tags of the form h number : 对于格式为h number的所有标签:

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

For a limited range of a single digit: 对于个位数的有限范围:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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