xsl-list
[Top] [All Lists]

RE: Delta between 2 xml docs in xslt

2006-01-15 08:51:46
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(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Rich_Wheadon(_at_)MATRIXResources(_dot_)com
Sent:     Sat, 14 Jan 2006 01:29:31 -0500
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  [xsl] 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.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>