Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: A question about XPath filters (predicates)

From: Peter Flynn <peter.nosp@-.--------.-->
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/


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent