[MarkLogic Dev General] Merge 2 xml files

sai shanker lsaishanker at yahoo.com
Tue Nov 3 13:59:04 PST 2009


That works perfectly fine.
Thanks a lot Doug.
Sai.

--- On Tue, 11/3/09, Glidden, Douglass A <Douglass.A.Glidden at boeing.com> wrote:


From: Glidden, Douglass A <Douglass.A.Glidden at boeing.com>
Subject: RE: [MarkLogic Dev General] Merge 2 xml files
To: "general at developer.marklogic.com" <general at developer.marklogic.com>
Date: Tuesday, November 3, 2009, 4:26 PM



Oh, you should note that my solution makes no guarantees about the order of the <line /> elements—and without an id attribute on the line elements, I don't know that one can guarantee the order of the line elements.

Doug Glidden 
Software Engineer 
The Boeing Company 
Douglass.A.Glidden at boeing.com 



From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Glidden, Douglass A
Sent: Tuesday, November 03, 2009 16:21
To: general at developer.marklogic.com
Subject: RE: [MarkLogic Dev General] Merge 2 xml files 



Sai,
 
This should work for both cases and be extensible to quite a few more.  Note:  I don't claim that this is necessarily the most efficient way to do this for large data sets, but it works.
 
let $xmls := ($xml1, $xml2)
 
for $file-id in fn:distinct-values($xmls/@id)
let $paras := $xmls[@id=$file-id]/para
order by $file-id
return
  <file id='{$file-id}'>{
    for $para-id in fn:distinct-values($paras/@id)
    let $lines := $paras[@id=$para-id]/line
    order by $para-id
    return
      <para id='{$para-id}'>{$lines}</para>
  }</file>
Doug Glidden 
Software Engineer 
The Boeing Company 
Douglass.A.Glidden at boeing.com
 



From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of sai shanker
Sent: Tuesday, November 03, 2009 15:17
To: General Mark Logic Developer Discussion
Subject: [MarkLogic Dev General] Merge 2 xml files 







Hi,
 
I need to merge xmls stored in 2 variables as shown below in 2 cases:-
 
===============================================================
----------------------------------------------------------------------------------------------------------------------
1) Case 1
----------------------------------------------------------------------------------------------------------------------
 
let $xml1 :=  <file id='1'><para id='1'><line>This is line 1.</line></para></file>
 
let $xml2 :=  <file id='1'><para id='1'><line>This is line 2.</line></para></file>
 
the output should look something like:-
 
<file id='1'>
    <para id='1'>
          <line>This is line 1.</line>
          <line>This is line 2.</line>
    </para>
</file>
===============================================================
----------------------------------------------------------------------------------------------------------------------------
2) Case 2
-----------------------------------------------------------------------------------------------------------------------------
 
let $xml1 :=  <file id='1'><para id='1'><line>This is line 1.</line></para></file>
 
let $xml2 :=  <file id='1'><para id='2'><line>This is line 1.</line></para></file>
 
the output should look something like:-
 
<file id='1'>
    <para id='1'>
          <line>This is line 1.</line>
    </para>
    <para id='2'>
          <line>This is line 1.</line>
    </para>
</file>
 
========================================================
 
Can you please let me know if it is possible using any marklogic function?
 
Thanks and Regards,
Sai.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-----Inline Attachment Follows-----


_______________________________________________
General mailing list
General at developer.marklogic.com
http://xqzone.com/mailman/listinfo/general



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xqzone.marklogic.com/pipermail/general/attachments/20091103/cc0c1d77/attachment.html


More information about the General mailing list