提问人:srikrishnan 提问时间:10/27/2023 最后编辑:LMCsrikrishnan 更新时间:10/29/2023 访问量:32
如何找到紧跟在上标后面的下标
How to find subscript immediately following superscript
问:
我想区分以下下标和上标情况,并基于此我需要显示输出。如果只出现上标,则会有不同的处理方式,如果上标和下标紧随其后,则会有不同的处理方式
≠aaa M 示例文本 ≠M<article><sup>≠</sup>aaa<sub>M</sub> sample text <sup>≠</sup><sub>M</sub></article>
有没有办法在 XPath 中识别这一点?
我正在尝试如下所示的方法:
boolean(following-sibling::text()),但需要设置两个条件
答:
0赞
LMC
10/28/2023
#1
对于给定的示例,此 xpath 将返回(第一种情况)aaa
//text()[following-sibling::*[position()=1 and name()="sub"] and preceding-sibling::sup[1]]
这个 xpath 将返回(第二种情况)sample text
//text()[following-sibling::*[1][name()="sup"] and following-sibling::*[2][name()="sub"]]
0赞
Dimitre Novatchev
10/29/2023
#2
对于<sup>
不立即紧随其后的<sub>
使用:
sup/following-sibling::node()[1][not(self::sub)]
对于紧跟 <sub>
的 <sup>
使用:
sup/following-sibling::node()[1][self::sub]
评论
1赞
srikrishnan
11/19/2023
感谢您的回复。它适用于我的情况。谢谢
0赞
Dimitre Novatchev
11/20/2023
很高兴这个答案很有帮助。请通过接受答案并点赞来表明这种帮助。
评论
<sup>=</sup>aaa<sub>MM</sub>
sup[following-sibling::node()[1][self::text()] and following-sibling::node()[2][self::sub]]