Your doc() functions all point to files on your file system, which indicates a misunderstanding about how one works with XML data with eXist-db. When working with eXist-db, though, all manipulations of XML data happen in the database. Thus, you need to first store the XML data in the database, and then you can perform your manipulations. Then, if needed, you can serialize the data back out onto the file system.
To store data into the database, see Getting Data into eXist-db.
To merge data, see XQuery Update Extensions.
To serialize the data back out onto the file system, see the function documentation for file:serialize().