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<mailto:$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<mailto:$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]<mailto:[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
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to