Is it possible to do a find and replace to the attributes of a xml element? I want to change the directory that is being pointed to by a href:
From:
<image href="./views/screenshots/page1.png">
to
<image href="screenshots/page1.png">
And from:
<image href="./screenshots/page2.png">
to
<image href="screenshots/page2.png">
So by getting rid of all “./” that belong to the href of all image tags, but only the image tags. And furthermore, get rid of first folder if it is not named “screenshots”. Is there a simple way to do this in one go?
This transformation:
when applied on this XML document:
produces the wanted result:
Do note:
The use and overriding of the identity rule. This is the most fundamental and most powerful XSLT design pattern.
Only
hrefattributes ofimageelements are modified.Only
hrefattributes that start with the string"./"or the string"./{something-different-than-screenshots}/"are processed in a special way (by separate templates).All other nodes are only processed by the identity template.
This is a pure “push style” solution.