Jump to content

XQuery Question


cschlaefcke
 Share

Recommended Posts

Hi Folks,I have a xml structure that can have arbitrary nested categories/category elements:

<...>  <categories>	<category name="1">	  <categories>		<category name="A"/>		<category name="B"/>		<category name="C"/>	  </categories>	<category>	<category name="2">	  <categories>		<category name="D">		  <categories>			<.../>		  </categories>		</category>		<category name="E"/>		<category name="F"/>	  </categories>	<category>	<category name="3">	  <categories>		<category name="G"/>		<category name="H"/>		<category name="I"/>	  </categories>	<category>  </categories></..>

What I want to do with XQuery is something like: "Give me everything except Category 2" and it should return:

<...>  <categories>	<category name="1">	  <categories>		<category name="A"/>		<category name="B"/>		<category name="C"/>	  </categories>	<category>	<category name="3">	  <categories>		<category name="G"/>		<category name="H"/>		<category name="I"/>	  </categories>	<category>  </categories></..>

What I have so far is: Give me Category "1" and I´ll figure out, to get the delta myself :-)

  declare namespace mn='http://www.my_namespace.com';  let $e := $this//mn:categories return <mn:categories> {  for $z in $e/mn:category where $z/@name='2' return $z  } </mn:categories>

But this is getting really ugly the bigger the matching result becomes. When I try to invert my query with "!=" like this:

  declare namespace mn='http://www.my_namespace.com';  let $e := $this//mn:categories return <mn:categories> {  for $z in $e/mn:category where $z/@name!='2' return $z  } </mn:categories>

it returns crap :-(Is there any clever way to get the delta with XQuery directly?Thanks for any help! Regards,Chris

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...