Reputation: 73
I want remove an xml attribute via xpath, but the xml element could have more atrributes in the future.
html code:
<p class="red, blue, green">test/<p>
xpath:
<xpath expr="//p[contains(@class, 'green')]" position="attributes">
<attribute name="class">red, blue</attribute>
</xpath>
Is where a better way for fixtext "red, blue"?
In order to suppport possible new version of the html file like
"<p class="red, blue, green, brown">test</p>"
in the future without need to change the xpath code again.
for instance actual attribute list as var + an xpath function
Upvotes: 0
Views: 348
Reputation: 242333
What about setting the @class to
concat(substring-before(@class, "green"), substring-after(@class, "green"))
You'll need to solve the abandoned commas, too, but as Björn Tantau commented, in real HTML the classes would be separated by spaces, so you can just wrap the result into normalize-space
.
Upvotes: 2