[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Help with multiple deletes

Newman, John W newmanjw at upmc.edu
Tue Sep 1 16:35:13 PDT 2009


  Help with multiple deletes
Thanks Martin, that works.  Except the 3rd delete doesn't run on the updated tree from the 2nd delete, so 2 copy statements are necessary.  Is there a different way to do this, so the delete statements operate on the updated tree w/o doing a copy each time?  i.e. some sort of piping construct ?

copy $x := doc("tree.xml")
modify (
	delete node $x//tree[@ID = 1] /branch[@ID = 2] /branch[@ID = 13] /branch[@ID = 65] /branch[@ID = 15] /leaf[@ID = 25]
)
return
	copy $y := $x
	modify (
		delete node $y//tree//branch[count(.//leaf) = 0]
	)
	return
		copy $z := $y
		modify (
			delete node $z//tree[count(.//branch) = 0]
		)
		return $z

Thanks



-----Original Message-----
From: Martin Probst [mailto:http://x-query.com/mailman/listinfo/talk] 
Sent: Saturday, August 29, 2009 10:47 AM
To: Newman, John W
Cc: Michael Kay; http://x-query.com/mailman/listinfo/talk
Subject: Re:  Help with multiple deletes

> After I spent a nice chunk of time testing this in stylus studio, I took the
> concept and ported it into our application.  Only to discover that the
> implementation we are using, MXQuery 0.6.0, does not support ancestor!
> Argh..  =)  So if anyone thinks it can possibly be rewritten without using
> ancestor (or any other axes I'm guessing), please share your thoughts.  But
> I think we are going to end up using an XSLT for this operation.

You could simply transform twice, which might be less efficient, but
its certainly simpler to write:

copy $x := doc("tree.xml")
     modify (
         delete node $x//tree[@ID = 1] /branch[@ID = 2] /branch[@ID =
13] /branch[@ID = 65] /branch[@ID = 15] /leaf[@ID = 25]
     )
return
  copy $y := $x
  modify (
         delete node $x//tree//branch[count(.//leaf) = 0]
                ,
         delete node $x//tree[count(.//branch) = 0]
  )
  return $y

Martin



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.