[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Delta between 2 xml docs in xslt

Subject: RE: Delta between 2 xml docs in xslt
From: cknell@xxxxxxxxxx
Date: Sun, 15 Jan 2006 10:51:46 -0500
delta xml
There isn't enough information for me to map the input file to the output file, but you can use this stylesheet to extract the <uniqueItemID> values from the daily file which do not appear in the <ItemID> elements in the active file.

Since you have the information necessary to map the input format to the output format, "the rest remains as an exercise for the reader".



<?xml version="1.0" encoding="UTF-8" ?>
<!-- The file processed by this stylesheet is the "daily" file -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" />
  <xsl:strip-space elements="*" />
  
  <xsl:variable name="ac-file" select="document('active.xml')" />

  <xsl:template match="/">
    <doc>
      <xsl:apply-templates />
    </doc>
  </xsl:template>
  
  <xsl:template match ="doc">
    <xsl:apply-templates />
  </xsl:template>
  
  <xsl:template match="uniqueItemID">
    <xsl:copy-of select=".[not(.=$ac-file/listing/items/item/ItemID)]" />
  </xsl:template>

</xsl:stylesheet>


-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Rich_Wheadon@xxxxxxxxxxxxxxxxxxx
Sent:     Sat, 14 Jan 2006 01:29:31 -0500
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:   Delta between 2 xml docs in xslt

Hello, I have done a considerable amount of research and perhaps have hit 
a wall I cannot cross.

I am using a client running xalan-c version 1 upgrading is not an option. 
This process is the result of a generic data miner which creates an xml 
file following some very simple internal data structure. The generic xml 
file generated contains no attribute nor namespace other then the most 
rudimentary necessary for the xml to pass syntax. This file can now be 
transformed into whatever structure our vendors require to publish our 
records.

To set the stage I am transforming generic (well formed) xml into specific 
xml or other file formats for vendor services we use. A new specification 
on one vendor requires me to have knowledge of current data on their 
system so that I can send records flagged for deletion/update/add. 
(Previously they simply scrapped the old records and replaced the entire 
inventory with the file I send)

I have an xml structure via url which indicates to me what items I have 
currently active on their site, I am having difficulty figuring out how to 
walk the active content file and determine what exists on their site but 
not in my new file of records. 

Artifacts:
DAILY FILE : My daily file being transformed into dtd compliant xml - 
<listing>
     <items>
        <item>
                <ItemID>1a2b</ItemID>
                <description>Something Green</description>
                <cost>1.00</cost>
        </item>
        <item>
                <ItemID>1b2c</ItemID>
                <description>Something Blue</description>
                <cost>1.00</cost>
        </item>
        <item>
                <ItemID>1b2b</ItemID>
                <description>Something Yellow</description>
                <cost>1.00</cost>
        </item>
        <item>
                <ItemID>1c2b</ItemID>
                <description>Something Black</description>
                <cost>1.00</cost>
        </item>
     </items>
</listing>

ACTIVE CONTENT FILE : The inventory file I can get via url from my vendor 
lists only the uniqueIDs i have active in their system:
<doc>
<uniqueItemID>1b2c</uniqueItemID>
<uniqueItemID>1b2b</uniqueItemID>
<uniqueItemID>1c2b</uniqueItemID>
<uniqueItemID>1b2e</uniqueItemID>
</doc>

MY OUTPUT TO THE VENDOR : The final result should be something like:
<inventory>
     <header>
        <headerCode>XXXXX</headerCode>
        <companyName>My Company</companyName>
        <otherStuff>and on and on</otherStuff>
     <products>
        <unit>
                <transactionType>Add</transactionType>
                <uniqueItemID>1a2b</uniqueItemID>
                <title>Something Green</title>
                <lowestPrice>1.00</lowestPrice>
        </unit>
        <unit>
                <transactionType>Update</transactionType>
                <uniqueItemID>1b2c</uniqueItemID>
                <title>Something Blue</title>
                <lowestPrice>1.00</lowestPrice>
        </unit>
        <unit>
                <transactionType>Update</transactionType>
                <uniqueItemID>1b2b</uniqueItemID>
                <title>SomethingYellow</title>
                <lowestPrice>1.00</lowestPrice>
        </unit>
        <unit>
                <transactionType>Update</transactionType>
                <uniqueItemID>1c2b</uniqueItemID>
                <title>Something Black</title>
                <lowestPrice>1.00</lowestPrice>
        </unit>
        <unit>
                <transactionType>Delete</transactionType>
                <uniqueItemID>1b2e</uniqueItemID>
                <title>Something Red and Purple</title>
                <lowestPrice>1.00</lowestPrice>
        </unit>
     </products>
</inventory>

in my example above I could default all records in the daily feed to 
update which would handle new and changed files fine, but I need to 
additionally create new nodes in the file for those in the active content 
file but not in the daily file.

thanks in advance for any insights you might have.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.