Re: XQuery for every node except for something

Hi Mike,

Just use the same XPath that you would in XSLT:

//*[not(Owner) or Owner = 'mluu']

You indicated that an element always contains at most one Owner, but if
there might be multiple owners you need to decide what you want done in that
case.  The query above matches as long as there exists an Owner equal to
mluu (or no Owner).

You also implied that Owner has simple content.  The query above would also
match cases with complex content, like <Owner><foo>mluu</foo></Owner>.


Hope this helps,

Michael Brundage
xquery@comcast.net

Writing as
Author, XQuery: The XML Query Language (Addison-Wesley, 2004)
Co-author, Professional XML Databases (Wrox Press, 2000)

not as
Technical Lead
Common Query Runtime/XML Query Processing
WebData XML Team
Microsoft



On 12/19/03 4:48 PM, "Michael Luu" <mluu@cougaarsoftware.com> wrote:
> i want to query for all nodes except for a selected few.  this is pretty
> straight forward in SQL, but how do you do it for XQuery?  I can do this
> in XSLT but want an equivalent XQuery.
> 
> for example:
> 
> <Directories>
> <Permission>
> <Mask>744</Mask>
> </Permission>
> <File>
> <Name>.cshrc</Name>
> <Owner>mluu</Owner>
> </File>
> <Directory>
> <Name>D1</Name>
> <Owner>mluu</Owner>
> <File>
>   <Name>README.txt</Name>
>   <Owner>mluu</Owner>
> </File>
> <File>
>   <Name>foo.txt</Name>
>   <Owner>cchan</Owner>
> </File>
> <File>
>   <Name>bar.txt</Name>
>   <Owner>cchan</Owner>
> </File>
> <Directory>
>   <Name>D2</Name>
>   <Owner>mluu</Owner>
> </Directory>
> <Directory>
>   <Name>D3</Name>
>   <Owner>cchan</Owner>
> </Directory>
> </Directory>
> </Directories>
> 
> i want to return all the nodes that do not contain an <Owner> element or
> if a node where its child <Owner> element is equal to "mluu".   so the
> resulting output would be:
> 
> <Directories>
> <Permission>
> <Mask>744</Mask>
> </Permission>
> <File>
> <Name>.cshrc</Name>
> <Owner>mluu</Owner>
> </File>
> <Directory>
> <Name>D1</Name>
> <Owner>mluu</Owner>
> <File>
>   <Name>README.txt</Name>
>   <Owner>mluu</Owner>
> </File>
> <Directory>
>   <Name>D2</Name>
>   <Owner>mluu</Owner>
> </Directory>
> </Directory>
> </Directories>
> 
> thanks for your help!
> 
> -mike
> 

Received on Saturday, 20 December 2003 13:39:15 UTC