[xquery-talk] Variable references and prolog grammar

Michael Kay mhk at mhk.me.uk
Fri Aug 12 12:35:55 PDT 2005


See section 4.15 of the spec:

The static context for a function body includes all functions that are
declared or imported anywhere in the Prolog, but it includes only those
variables and namespaces that are declared or imported earlier in the Prolog
than the function that is being defined.

XQuery differs here from XSLT, which allows forwards references to global
variables.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: talk-bounces at xquery.com 
> [mailto:talk-bounces at xquery.com] On Behalf Of Pierrick Brihaye
> Sent: 12 August 2005 11:07
> To: talk at xquery.com
> Subject: [xquery-talk] Variable references and prolog grammar
> 
> Hi,
> 
> XQUERY#1 :
> 
> declare variable $foo := "foo";
> declare function local:bar() {
>   "bar"
> };
> local:bar()
> 
> returns :
> "bar"
> 
> XQUERY#2 :
> 
> declare function local:bar() {
>   "bar"
> };
> declare variable $foo := "foo";
> local:bar()
> 
> returns the same result, showing that variable declarations 
> may follow function
> declarations as specficied by :
> ((VarDecl | FunctionDecl | OptionDecl) Separator)*
> 
> XQUERY#3 :
> 
> declare variable $foo := "foo";
> declare function local:bar() {
>   $foo
> };
> local:bar()
> 
> returns : 
> "foo"
> 
> XQUERY#4 :
> declare function local:bar() {
>   $foo
> };
> declare variable $foo := "foo";
> local:bar()
> 
> Saxon 8.5 returns :
> Error on line 3 column 1 of file:/C:/saxon8.5/in.txt:
>   XPST0003: XQuery syntax error in #...unction local:bar() { $foo }#:
>     Variable $foo has not been declared
> Failed to compile query
> 
> Is it a bug in the way Saxon's parser handles (or not) 
> forward references, or is
> such a forward reference disallowed by the specs ?
> 
> Cheers,
> 
> p.b.
> 
> 
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
> 




More information about the talk mailing list