RE: Ridiculous XPath expression, can I reduce it?
Hi again, Sorry I didn't explain that properly, but I wanted to keep the post relatively short. Let me explain more thoroughly... Basically what I'm doing is writing a form handler that can handle nested forms within a page, and in order to do that I have to find the <input.?> elements which are under a given <input.form> (the context node), but are not under an <input.form> beneath that, and also are not beneath an <input.link> node, which implies a different behaviour. These items must also not have a 'form.prefix' attribute as that means they've already been dealt with. Once I've processed an <input.form> element I mark it with a 'done' attribute to stop it being processed again (trust me on that one). e.g. (asterisks are selected nodes) <doc> <input.form done='true'> <== Context node <input.form name='john'> *<input.button name='pete'/> <input.form name='steve'> <input.button name='clive'/> </input.form> *<input.button name='dudley'/> *<input.text name='foo' /> </input.form> <input.button name='alan' size='big' color='red'/> <input.button/> </input.form> </doc> For reference the form of the query is: .//input.button[count(ancestor::input.form[not(@done)])=1 and not(@form.prefix) and not(ancestor::input.link)] | .//input.text[count(ancestor::input.form[not(@done)])=1 and not(@form.prefix) and not(ancestor::input.link)] Hope this helps, Nick > -----Original Message----- > From: David Carlisle [mailto:davidc@xxxxxxxxx] > Sent: 03 April 2001 13:17 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: Ridiculous XPath expression, can I reduce it? > > > > ^W on emacs (or ^X on a windows-y editor would probably make it > smaller...) > > > which basically finds all the elements that exist below any given > > <input.form> tag but not below an <input.link> tag. > > does it? > > If I didn't look at the sample code you'd posted I'd code the > requested > selection as > > .//*[ancestor::input.form and not(ancestor::input.link)] > > The code you posted seemed to be doing something with @done > and also checking there was exactly one ancestor. > > Also it restricted * to a fixed list of element names. > > You may change * in the above to > > *[self::input.hidden or self::input.text or ....] > if you really need this restriction. > > David > > > _____________________________________________________________________ > This message has been checked for all known viruses by Star > Internet delivered > through the MessageLabs Virus Control Centre. For further > information visit > http://www.star.net.uk/stats.asp > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
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