0

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>

13
  • 1
    Well, you should be using <xsl:copy-of select="document('retail_transactions.xml')/transaction/*"/>. But if your attempt did not return anything, then the file is not where you think it is. Or has a different name. Or maybe some other flaw we cannot see because you did not post the actual XSLT. Commented Mar 18, 2022 at 6:27
  • I am trying to make the XSLT and it relatively empty as i am just trying to read the entire file and I have edited to add the XSLT Commented Mar 18, 2022 at 14:43
  • 1
    What do you get with <xsl:copy-of select="document('file:///C:/Users/full/path/to/retail_transactions.xml')"/>? Note the use of forward slashes. Commented Mar 18, 2022 at 15:56
  • Tried / and \ variants also tried using directories that do not have spaces in the names still doesn't show anything the code I was using : <?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('file://C:/Users/valer/Desktop/retail_transactions.xml')/*"/> </xsl:template> </xsl:stylesheet> Commented Mar 18, 2022 at 17:30
  • You are missing a slash after file: Commented Mar 18, 2022 at 17:49

2 Answers 2

0

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 .

Sign up to request clarification or add additional context in comments.

2 Comments

Good to hear that the issue is resolved. Out of curiosity, what XSLT engine you used in the Oxygen scenario?
I am using XSLT 1.0 and the default Engine was set as Saxon 6.5.5
-1

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/*"/>
     

4 Comments

tried this ``` <xsl:template match="/"> <xsl:copy-of select="document('C:\Users\<FullPath >\retail_transactions.xml')/transactions/*"/> </xsl:template> ``` and it made a blank file
Shouldn't it be transaction singular instead of the transactions plural?
The root node is called transactions and each child node it's called transaction
@YitzhakKhabinsky Your assertion that a fully qualified (i.e. an absolute) path is required is entirely baseless. The specification states explicitly that the URI reference may be relative. Moreover, the path you suggest cannot possibly work because it's a Windows path, not a URI. You may have a friend or a fake account to offsett my downvote, but the fact remains that this is an exceptionally bad answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.