![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: A question about XPath filters (predicates) [Thread Next] Re: A question about XPath filters (predicates)To: NULL Date: 10/7/2007 1:32:00 PM Altu wrote: > Hi Peter, > > Thanks for the reply. > > The thing that was confusing me was that why would we insert a > predicate that starts with / or // in a specifiec location in the > XPath query. Looks like _generally_ they can be anywhere in the > query and yet we will get the same result. A predicate which immediately references the root element can be considered global in scope, in the sense that if it always evaluates to false (as is the case with your example referencing a root element type that could not exist), then the entire XPath statement which depends on it will necessarily also always be false. In that case it is immaterial where you place it in the expression. Don't confuse syntax with logic. The XPath syntax permits you to express constraints in a variety of ways in order to direct the expression to reference the node that you want. Just because it allows something doesn't mean that it will always be meaningful to express it that way. The same applies in many languages: I can write "if(1==0)" or its equivalent in most programming languages and it will be accepted for compilation even though it will always evaluate to false. The only occasion on which I tend to write a predicate which immediately references the root element type is when I use it as a crude switch to detect the current document type in XSLT which is common to several. So for example in XSLT which handles DocBook, [/article] might enable a certain XPath which would otherwise not be needed in books, etc. It's inelegant and probably inefficient, and there are probably better examples from other fields. ///Peter -- XML FAQ: http://xml.silmaril.ie/ | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||
|
