That works perfectly fine. Thanks a lot Doug. Sai. --- On Tue, 11/3/09, Glidden, Douglass A <[email protected]> wrote:
From: Glidden, Douglass A <[email protected]> Subject: RE: [MarkLogic Dev General] Merge 2 xml files To: "[email protected]" <[email protected]> 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 [email protected] From: [email protected] [mailto:[email protected]] On Behalf Of Glidden, Douglass A Sent: Tuesday, November 03, 2009 16:21 To: [email protected] 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 := $xm...@id=$file-id]/para order by $file-id return <file id='{$file-id}'>{ for $para-id in fn:distinct-values($paras/@id) let $lines := $par...@id=$para-id]/line order by $para-id return <para id='{$para-id}'>{$lines}</para> }</file> Doug Glidden Software Engineer The Boeing Company [email protected] From: [email protected] [mailto:[email protected]] 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 [email protected] http://xqzone.com/mailman/listinfo/general
_______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
