If you already have a document, you can use something like xdmp:node-insert-after to insert a sibling node.
Or if you only have less than 1000 "records", then it is probably small enough to just do that all in one go by using xdmp:document-insert. Just be careful-generally speaking, you do not want to do the search and the update in the same transaction (because it will create a read lock on all of the documents you are searching). Do the search gathering your results, and then hand that off to another request to do the insert. -Danny From: [email protected] [mailto:[email protected]] On Behalf Of Kari Cowan Sent: Thursday, June 18, 2015 1:56 PM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] Generating Reports in ML To be clear, I can take a single result and return it into a xdmp:document-insert statement - is there a method available to iteratively append to that document? From: [email protected] [mailto:[email protected]] On Behalf Of Kari Cowan Sent: Thursday, June 18, 2015 8:47 AM To: [email protected] Subject: [MarkLogic Dev General] Generating Reports in ML I have a query that returns a set of results for a single record. I want to loop through all records (under 1000 records), and create a spreadsheet or document. Assume I could do a search on cts:search(xdmp:directory("/olympus/scope-xml/"), and then a value query on a node called "Coporate_Profile_ID" - that would return the id's I want below. How would I then create the report? (tips on efficient code tips to return the id's are appreciated as well) Below is my query and sample results for 1 record. Any suggestions? xquery version "1.0-ml"; declare namespace olympus = "http://www.alm.com/olympus"; declare namespace this = "this"; import module namespace scope="http://alm.com/modules/scope" at "olympus/modules/scope.xqy"; import module namespace pacer = "http://alm.com/modules/pacer" at "olympus/modules/pacer.xqy"; (:450075101|450040301|450033801|450025401:) let $id:="450025401" let $sub-ids:= scope:build-id-sub-list($id) let $cases:=pacer:get-cases($sub-ids,"") let $profile:=scope:fetch-profile($id,"",0,-1,0,0,"","","") let $fields:=$profile//( Coporate_Profile_ID| Main_Details/Company_Name| Main_Details/No_of_Subsidiaries) let $subsidiaries:=$profile//Subsidiaries let $subs:= for $sub in $subsidiaries/Subsidiary let $name:=$sub/Subsidiary_name let $id:=$sub/Subsidiary_Profile_ID let $count:=pacer:get-cases($id/text(),"")/@total return <Subsidiary>{$name}{$id}<case-count>{$count}</case-count></Subsidiary> return <Result> {$fields} {$subs} </Result> .............................. <Result> <Coporate_Profile_ID>450025401</Coporate_Profile_ID> <Company_Name>AOL Inc.</Company_Name> <No_of_Subsidiaries>13</No_of_Subsidiaries> <Coporate_Profile_ID>450025401</Coporate_Profile_ID> <Coporate_Profile_ID></Coporate_Profile_ID> <Subsidiary> <Subsidiary_name>Adap.tv, Inc</Subsidiary_name> <Subsidiary_Profile_ID>450025404</Subsidiary_Profile_ID> <case-count total="0"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>AOL Advertising Inc</Subsidiary_name> <Subsidiary_Profile_ID>450025405</Subsidiary_Profile_ID> <case-count total="2"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>AOL Advertising Inc</Subsidiary_name> <Subsidiary_Profile_ID>450025405</Subsidiary_Profile_ID> <case-count total="2"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>AOL Canada Corp</Subsidiary_name> <Subsidiary_Profile_ID>450025406</Subsidiary_Profile_ID> <case-count total="0"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>AOL Holdings (Lux) S. r.l</Subsidiary_name> <Subsidiary_Profile_ID>450025409</Subsidiary_Profile_ID> <case-count total="0"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>AOL Internet Services Holdings Inc</Subsidiary_name> <Subsidiary_Profile_ID>450025407</Subsidiary_Profile_ID> <case-count total="0"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>AOL Israel Ltd</Subsidiary_name> <Subsidiary_Profile_ID>450025427</Subsidiary_Profile_ID> <case-count total="0"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>Convertro, Inc</Subsidiary_name> <Subsidiary_Profile_ID>450025428</Subsidiary_Profile_ID> <case-count total="0"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>Gravity.com, Inc</Subsidiary_name> <Subsidiary_Profile_ID>450025429</Subsidiary_Profile_ID> <case-count total="0"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>MapQuest, Inc</Subsidiary_name> <Subsidiary_Profile_ID>450025410</Subsidiary_Profile_ID> <case-count total="2"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>TechCrunch, Inc</Subsidiary_name> <Subsidiary_Profile_ID>450025414</Subsidiary_Profile_ID> <case-count total="0"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>TheHuffingtonPost.com, Inc</Subsidiary_name> <Subsidiary_Profile_ID>450025415</Subsidiary_Profile_ID> <case-count total="2"></case-count> </Subsidiary> <Subsidiary> <Subsidiary_name>Vidible, Inc.</Subsidiary_name> <Subsidiary_Profile_ID>450025430</Subsidiary_Profile_ID> <case-count total="0"></case-count> </Subsidiary> </Result> ________________________________ Learn more about ALM, visit http://www.alm.com . - ALM, an Integrated Media Company, is a leading provider of news and information for the legal and commercial real estate markets. ALM's market-leading brands include The American Lawyer, Corporate Counsel, GlobeSt.com, Insight Conferences, Law.com, Law Journal Press, LegalTech, The National Law Journal and Real Estate Forum. ________________________________ Learn more about ALM, visit http://www.alm.com . - ALM, an Integrated Media Company, is a leading provider of news and information for the legal and commercial real estate markets. ALM's market-leading brands include The American Lawyer, Corporate Counsel, GlobeSt.com, Insight Conferences, Law.com, Law Journal Press, LegalTech, The National Law Journal and Real Estate Forum.
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
