I am trying to understand if there is a way to modify an xml document using XSLT or are there any other better approaches than XSLT?
Say, I have an xml like so:
<feed xmlns="http://www.w3.org/2005/Atom">
<id>http://libx.org/libx2/libapps</id>
<entry>
<id>http://libx.org/libx2/libapps/2</id>
</entry>
<entry>
<id>http://libx.org/libx2/libapps/3</id>
</entry>
</feed>
I would like to do the following actions:
- Modify feed:id to (remove the text of feed:id)
- Modify entry:id values such that the last number value after “/” remains.
The result xml should look something like so:
<feed xmlns="http://www.w3.org/2005/Atom">
<id></id>
<entry>
<id>2</id>
</entry>
<entry>
<id>3</id>
</entry>
</feed>
Thanks,
Sony
I. XSLT 1.0 solution:
This XSLT 1.0 transformation works with any url without having any assumptions about all URLs haing a common starting substring:
when applied on the provided XML document:
the wanted, correct result is produced:
II. XSLT 2.0 solution:
when applied on the same XML document (above), the same correct result is produced: