Your question makes the presumption that the text nodes of all c's with the 
same @x have the same text content,

and there is only 1 c in each  b.

 

I'd love to hear a better or more efficient solution, but what I do for this 
type of problem is this

 

I haven't tried this but something close should work

 

 

  for $a in fn:distinct-values( $doc//c/@x )

 let $bs  := $doc//c...@x eq $a]/..

      $c := $bs/c[1]

return 

   if( count( $bs) gt 1 ) then

       <b>{$c , <D>{ $bs/d}</D>}</b>

  else

     <b>{$c,$bs/d}</b>

 

 

-David Lee

 

----------------------------------------

David A. Lee

Senior Principal Software Engineer

Epocrates, Inc.

[email protected]

812-482-5224

 

 

  

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of 
[email protected]
Sent: Thursday, February 25, 2010 7:06 AM
To: [email protected]
Subject: [MarkLogic Dev General] Problem with XML restructuring.

 

Hi all, 

 

I have a problem where I need to retrieve common data(based on @x) across nodes 
and consolidate them under a single node(<b>). Let me elaborate with xml.

 

Input XML :

 

<a>

 <b>

  <c x="1|2|3|4">5|6|7|8</c>

  <d>the one</d>

 </b>

 <b>

  <c x="1|2|3|4">5|6|7|8</c>

  <d>the other one</d>

 </b>

 <b>

  <c x="2|3|4">6|7|8</c>

  <d>the different one</d>

 </b>

</a>

 

Needs to be converted to 

 

<a>

 <b>

  <c x="1|2|3|4">5|6|7|8</c>

  <D>

   <d>the one</d>

   <d>the other one</d>

  </D>

 </b>

 <b>

  <c x="2|3|4">6|7|8</c>

  <d>the different one</d>

 </b>

</a>

 

Note : the <d> nodes have accumulated under a single <b> node that has the same 
attribute x.

 

Ideally the input XML would have 100 to 200 such <b> tags. 

 

Kindly provide any inputs that would help.

 

Thanks 

Sai 

 

This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information.
If you are not the intended recipient, please contact the sender by reply 
e-mail and destroy all copies of the original message.
Any unauthorized review, use, disclosure, dissemination, forwarding, printing 
or copying of this email or any action taken in reliance on this e-mail is 
strictly prohibited and may be unlawful.

 

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to