Subject: RE: [xsl] Merging structure and content by own id with XSLT 2.0 From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Tue, 23 Mar 2010 17:09:50 -0000 |
I would start with a for-each-group that selects all the "data elements" from both files, using group-by="data_id". If there's only one item in the current-group() you can copy it unchanged. If there are two, they will be in population order so you know which is the old and which is the new. Then you just have to do some legwork to compare them. Attributes are easy because when you add two attributes with the same name to an element, the last one takes precedence. I haven't tried to work out what your rules on merging element content are. Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay > -----Original Message----- > From: Jacobus Reyneke [mailto:jacobusreyneke@xxxxxxxxx] > Sent: 23 March 2010 16:21 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Merging structure and content by own id with XSLT 2.0 > > Good day, > > I need to merge new data into an existing data set. Data is > identified by data_id's. > How does one merge the structure, content and attributes of XML files? > > This is a complex question, and I don't expect anyone to > answer it in full. I'm quite willing to spend a couple of > days on it. I am basically asking for some advise to get me > down the right track. > Obviously I'm not going to cry if an XSL guru can type out > bits of the required XSL or just jot down some pseudo code. > My greatest concern with XSL is getting the flow right. > Coming from a C background this functional approach is still > getting the better of me. > > Original data: > <a data_id="1"> > AAA > </a> > <b data_id="2"> > BBB > <c data_id="3"> > CCC > </c> > <e data_id="5"> > EEE > </e> > </b> > <d data_id="4" width="2" color="blue"> > DDD > </d> > > New data: > <d-d data_id="4" color="green"> > D-D-D > <c data_id="3"> > CCC > </c> > </d-d> > > XSLT > ??? > > Expected result: > <a data_id="1"> > AAA > </a> > <b data_id="2"> > BBB > <e custom_id="5"> > data > </e> > </b> > <dd data_id="4" width="2" color="green"> > D-D-D > <c data_id="3"> > CCC > </c> > </dd> > > The rules are: > - data_id's are unique in the result set > - new data content replaces original content > - new data structure modifies original structure > - new attributes updates or adds to original element attributes > - element names can be updated by new element names because > only data_id's are used > - all original elements with data_id's that are not in the > new data, remains where they are, as they are > > Kind regards, > Jacobus
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Merging structure and content, Jacobus Reyneke | Thread | Re: [xsl] Merging structure and con, Jacobus Reyneke |
Re: [xsl] combine on key and dedupe, David Carlisle | Date | Re: [xsl] Create Table, Wolfgang Laun |
Month |