Xpath 只选择属性的一部分

Moa*_*oak 4 xpath attributes replace

如果

/dt/@id
Run Code Online (Sandbox Code Playgroud)

返回comment_34232comment_12我怎样才能让它返回3423212(换句话说,'comment_'替换为''

而如果

/span/style
Run Code Online (Sandbox Code Playgroud)

返回width: 80%;我如何替换 width:,然后%;再取回80

问候

Dim*_*hev 5

一、部分

如果

/dt/@id returns `comment_34232` or `comment_12` how can I make it return
Run Code Online (Sandbox Code Playgroud)

3423212(换句话说,'comment_'替换为''

使用

substring-after(/dt/@id, '_')
Run Code Online (Sandbox Code Playgroud)

二、部分

而如果

/span/style returns `width: 80%;` how can I replace  `width: ` and after
Run Code Online (Sandbox Code Playgroud)

%;检索80

使用

substring-before(substring-after(/span/style, ' '), '%')
Run Code Online (Sandbox Code Playgroud)

请注意:使用标准 XPath 函数substring-before()substring-after().