Moak
Moak

Reputation: 12885

Xpath select only part of an attribute

if

/dt/@id

returns comment_34232 or comment_12 how can I make it return 34232 or 12 (in other words replaceing 'comment_' with ''

and if

/span/style

returns width: 80%; how can I replace width: and after that %; to retrieve 80

Regards

Upvotes: 4

Views: 1968

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243599

I. Part

if

/dt/@id returns `comment_34232` or `comment_12` how can I make it return

34232 or 12 (in other words replaceing 'comment_' with ''

Use:

substring-after(/dt/@id, '_')

II. Part

and if

/span/style returns `width: 80%;` how can I replace  `width: ` and after

that %; to retrieve 80

Use:

substring-before(substring-after(/span/style, ' '), '%')

Do note: the use of the standard XPath functions substring-before() and substring-after() .

Upvotes: 5

Related Questions