I have xml document like below,
<chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="chapter1">
<title>First chapter</title>
<section xml:id="section1">
<imageobject>
<image fileref="images/image1.jpg"/>
</imageobject>
<imageobject>
<image fileref="images/image2.jpg"/>
</imageobject>
</section>
<section xml:id="section2" xml:base="../other/section1.xml">
<imageobject>
<image fileref="images/image1.jpg"/>
</imageobject>
<imageobject>
<image fileref="images/image2.jpg"/>
</imageobject>
<section xml:id="section3" xml:base="../some-other/more/section3.xml">
<imageobject>
<image fileref="images/image1.jpg"/>
</imageobject>
</section>
</section>
<section xml:id="section4" xml:base="../some-other/section4.xml">
<imageobject>
<image fileref="images/image2.jpg"/>
</imageobject>
</section>
</chapter>
Be cause of same image name is repeated in different sections, I am renaming all image names other than first section using a java class. Then I can generate a list of renamed image names.
Now I want to reflect those changes in the above xml file also. As example when I rename "image1.jpg" to "aaa.jpg" in section2, I need to reflect that change in the my initial xml by generating a new xml with new renamed image names.
For that purpose, I am using Ant script which uses XSLT 1.0 and take my first xml and renamed image list as inputs and generate a new xml document with new fileref values. How I can make that XSLT and use it in my Ant script.
Here is my new renamed images list.
<Imagedata>
<section>
<sectionID>section2</sectionID>
<relativepath>images/aaa.jpg</relativepath>
<relativepath>images/bbb.jpg</relativepath>
</section>
<section>
<sectionID>section3</sectionID>
<relativepath>images/ccc.jpg</relativepath>
</section>
<section>
<sectionID>section4</sectionID>
<relativepath>images/ddd.jpg</relativepath>
</section>
</Imagedata>
And my new final xml will be some thing like,
<chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="chapter1">
<title>First chapter</title>
<section xml:id="section1">
<imageobject>
<image fileref="images/image1.jpg"/>
</imageobject>
<imageobject>
<image fileref="images/image2.jpg"/>
</imageobject>
</section>
<section xml:id="section2" xml:base="../other/section1.xml">
<imageobject>
<image fileref="images/aaa.jpg"/>
</imageobject>
<imageobject>
<image fileref="images/bbb.jpg"/>
</imageobject>
<section xml:id="section3" xml:base="../some-other/more/section3.xml">
<imageobject>
<image fileref="images/ccc.jpg"/>
</imageobject>
</section>
</section>
<section xml:id="section4" xml:base="../some-other/section4.xml">
<imageobject>
<image fileref="images/ddd.jpg"/>
</imageobject>
</section>
</chapter>
Thank you..!!