I want to replace some nodes of an XML file by the equivalent nodes of another XML file. As this wouldn't be challenging enough, I want the ID used for comparision be the value of some child.
The "old" XML looks like:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Documents>
<Document id="001">
<Tags>
<Tag id="document_id">someIDfilename.pdf</Tag>
<Tag id="document_type">Type A</Tag>
<Tag id="document_text">A very important document of course.</Tag>
<Tags>
</Document>
<Document id="018">
<Tags>
<Tag id="document_id">someOtherIDfilename.pdf</Tag>
<Tag id="document_type">Type B</Tag>
<Tag id="document_text">Another very important document.</Tag>
<Tags>
</Document>
</Documents>
</Root>
The second Docoument shall be replaced by the quivalent of the following XML, whereby the ID that I have to use is the value of document_id (since the "id" of the Document node sometimes is overwritten or altered) :
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Documents>
<Document id="014">
<Tags>
<Tag id="document_id">someOtherIDfilename.pdf</Tag>
<Tag id="document_type">Type B</Tag>
<Tag id="document_text">The oh so important new document text.</Tag>
<Tags>
</Document>
</Documents>
</Root>
The result is expected to look like:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Documents>
<Document id="001">
<Tags>
<Tag id="document_id">someIDfilename.pdf</Tag>
<Tag id="document_type">Type A</Tag>
<Tag id="document_text">A very important document of course.</Tag>
<Tags>
</Document>
<Document id="018">
<Tags>
<Tag id="document_id">someOtherIDfilename.pdf</Tag>
<Tag id="document_type">Type B</Tag>
<Tag id="document_text">The oh so important new document text.</Tag>
<Tags>
</Document>
</Documents>
</Root>
Q1: is that possible by means of XSLT? Or do I have to use Java / DOM?
Q2: If Q1==yes : can somebody solve that here?
Best! Philipp