[MarkLogic Dev General] How to exclude some elements from marklogic xquery output?
Erik Hennum
Erik.Hennum at marklogic.com
Thu Jun 14 07:48:35 PDT 2012
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: general-bounces at developer.marklogic.com [general-bounces at developer.marklogic.com] On Behalf Of Karthik.Nagarajan2 at cognizant.com [Karthik.Nagarajan2 at cognizant.com]
Sent: Thursday, June 14, 2012 7:25 AM
To: general at developer.marklogic.com
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.
More information about the General
mailing list