Home > Blockchain >  Merge two XML files using Notepad into a third one
Merge two XML files using Notepad into a third one

Time:03-19

I have two XML files that I need to combine into a third one using XSLT 1.0 only

File one:

<customer>
    <prefix>Mrs</prefix>
    <lastName>Macauley</lastName>
    <givenName>Ernestine</givenName>
    <addressID>547053</addressID>
    <customerID>OS2M5PKJ</customerID>
</customer>

File Two:

<transaction>
    <transaction_date>02/11/2019</transaction_date>
    <customerID>OS2M5PKJ</customerID>
    <giftShop>3</giftShop>
    <transactionID>UWMWF82vkYvh5dMQ</transactionID>
    <value currency="gbp">63.97</value>
</transaction>

The end result should be outputted into a third file called output.xml and should look something like this

<transaction>
    <transaction_date>02/11/2019</transaction_date>
    <customerID>OS2M5PKJ</customerID>
    <giftShop>3</giftShop>
    <transactionID>UWMWF82vkYvh5dMQ</transactionID>
    <value currency="gbp">63.97</value>
    <prefix>Mrs</prefix>
    <lastName>Macauley</lastName>
    <givenName>Ernestine</givenName>
    <addressID>547053</addressID>
</transaction>

I am applying the XSLT to the second file using Notepad have tried to use <xsl:value-of select="document('retail_transactions.xml')/*"/> to try and read the second file but it doesn't do anything

EDIT XSLT ADDED

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

<xsl:template match="/">

<xsl:copy-of select="document('C:\Users<FULL-PATH>\retail_transactions.xml')/transaction/*"/>

</xsl:stylesheet>

CodePudding user response:

Please try the following.

You would need to adjust a fully qualified path to the XML file starting with the drive.

XSLT

<xsl:copy-of select="document('e:\<fully qualified path>\retail_transactions.xml')/transaction/*"/>
     

CodePudding user response:

The Problem was solved by using a different IDE (Oxygen XML) I have tried VS/VS code but they weren't really easy to use and Oxygen XML seems fairly intuitive, My initial code works

  • Related