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

Reply via email to