[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Q: Kaysian set difference in pure XPath statement
Hermann,
I wonder if I am not mistaking your question, since prima facie it seems pretty simple: indeed it is given by your paraphrase of "//*/*" as "all nodes beside the root element node". (And FWIW, this should be all _element_ nodes, not all nodes altogether.) That is, surely the answer to the node in //* that is not in //*/* is /* Now perhaps you mean to inquire not about the solution to this particular problem, but a more general problem regarding set differencing. In XPath 2.0 we have the convenient operation "except", so we can have //* except //*/* Needless to say, you can expect the performance of this to degrade with large documents, unlike /*. If your question is restricted to XPath 1.0, and again /* won't do, then how about the classic //*[count(.|//*/*) != count(//*/*)] The problem of getting out of the local context when inside the predicate isn't a problem, since these are absolute paths. Which again leads me to think you haven't posed the question you really want to answer. As for your attempt, //*[count(.|ancestor-or-self::*//*/*)!=count(ancestor-or-self::*//*/*)] this would actually work if instead of ancestor-or-self::* you had ancestor-or-self::node(). (Again, this is not to say it would be at all efficient.) It's the fact that the document root node has to be accounted for that's throwing this off. The expression ancestor-or-self::*//*/* will never (from any context) return the document element (the element child of the document root) or its element children (it goes only as high as its children's children) -- so these will always be included in your return set. If you had ancestor-or-self::node()//*/*, the element children of the document element would be included in the set of elements being counted, and so excluded from your return set -- leaving only /* (the document element). Cheers, Wendell On 3/24/2011 4:33 PM, Hermann Stamm-Wilbrandt wrote: -- ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|