Hi Pragya,

Following code should give the expected result ,
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";;

declare function local:transform($result as node()){

for $name in $result/Name, $law in $result/Law
return <result>{($name,$law)}</result>

};
let $data := <results>
    <result>
        <Name>thg</Name>
        <Name>rty</Name>
        <Law>England and Wales</Law>
        <Law>Latvia</Law>
    </result>
    <result>
        <Name>gux</Name>
        <Law>India</Law>
    </result>
    <result>
        <Name>abc</Name>
        <Name>xyz</Name>
        <Name>cde</Name>
        <Law>England</Law>
    </result>
</results>

let $result :=<results>{ for $result in $data/result
              return local:transform($result)
              }</results>
return $result

Thanks and regards
Raja >>>


From: [email protected] 
[mailto:[email protected]] On Behalf Of Kapoor, Pragya
Sent: Thursday, May 14, 2015 1:05 PM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] query on xml


Hi,



I need to convert the below input to the desired output.

The elements in the input xml is dynamic(it could be one element,two,three n so 
on, not fixed).



Input:



<results>
    <result>
        <Name>thg</Name>
        <Name>rty</Name>
        <Law>England and Wales</Law>
        <Law>Latvia</Law>
    </result>
    <result>
        <Name>gux</Name>
        <Law>India</Law>
    </result>
    <result>
        <Name>abc</Name>
        <Name>xyz</Name>
        <Name>cde</Name>
        <Law>England</Law>
    </result>
</results>​

desired output:

<results>
    <result>
        <Name>thg</Name>
        <Law>England and Wales</Law></result>
    <result>
        <Name>thg</Name>
        <Law>Latvia</Law></result>
    <result>
        <Name>rty</Name>
        <Law>England and Wales</Law>​</result>
    <result>
        <Name>rty</Name>
        <Law>Latvia</Law>​</result>
    <result>
        <Name>gux</Name>
        <Law>India</Law>
    </result>
    <result>
        <Name>abc</Name>
        <Law>England</Law>
    </result>
    <result>
        <Name>xyz</Name>
        <Law>England</Law>
    </result>
    <result>
        <Name>cde</Name>
        <Law>England</Law>
    </result>
</results>​

Thanks
Pragya


"This e-mail and any attachments transmitted with it are for the sole use of 
the intended recipient(s) and may contain confidential , proprietary or 
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 e-mail or any action taken in reliance on this e-mail is 
strictly prohibited and may be unlawful."
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(s), please reply to the sender and 
destroy all copies of the original message. Any unauthorized review, use, 
disclosure, dissemination, forwarding, printing or copying of this email, 
and/or any action taken in reliance on the contents of this e-mail is strictly 
prohibited and may be unlawful. Where permitted by applicable law, this e-mail 
and other e-mail communications sent to and from Cognizant e-mail addresses may 
be monitored.
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to