If you need to make a lot of complex changes to a document, then you might try using a library to help like this one: https://github.com/ryanjdew/XQuery-XML-Memory-Operations. This library tries its best to provide the transform statement capability from the XQuery Update Facility ( http://www.w3.org/TR/xquery-update-10/#id-transform ) to MarkLogic.
If the change is as simple as the example provided, though, I would probably go with the previous suggestions from Erik. -Ryan Dew On Thu, Jun 14, 2012 at 8:48 AM, Erik Hennum <[email protected]>wrote: > Hi, Karthik: > > Basically, you need to construct a new version of the doc root element > that doesn't have the b child element but has all other child nodes. If > it is just a single exclusion, a simple predicate might be best: > > xquery version "1.0-ml"; > for $m in fn:doc() > return document { > <doc>{ > $m/doc/node()[empty(self::b)] > }</doc> > } > > If you need to exclude lots of stuff, you're probably better off with > typeswitch: > > xquery version "1.0-ml"; > for $m in fn:doc() > return document { > <doc>{ > for $node in $m/doc/node() > return typeswitch($node) > case element(b) return () > default return $node > }</doc> > } > > > Hoping that's useful, > > > Erik Hennum > > ________________________________________ > From: [email protected] [ > [email protected]] On Behalf Of > [email protected] [[email protected]] > Sent: Thursday, June 14, 2012 7:25 AM > To: [email protected] > Subject: [MarkLogic Dev General] How to exclude some elements from > marklogic xquery output? > > Hi, > > I want to exclude some elements from xquery output.. > For ex: if I have many documents with the following xml , > <doc> > <a>a</a> > <b>b</b> > </doc> > > I want to return all the documents, but element <b> must be excluded in > all these documents. > > for $m in fn:doc() > return $m > > Above xquery will return all the documents as it is. Can someone please > let me know how to exclude only element <b> before returning the document. > Is there any xquery or marklogic function readily available to ignore some > elements while returning the response? I know that we can easily achieve > this using XSLT. But, is it possible using Xquery or marklogic function? > > > Thanks and Regards, > Karthik > > 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. > _______________________________________________ > General mailing list > [email protected] > http://community.marklogic.com/mailman/listinfo/general >
_______________________________________________ General mailing list [email protected] http://community.marklogic.com/mailman/listinfo/general
