W3C home > Mailing lists > Public > www-ql@w3.org > July to September 2004

RE: Compare string to node path?

From: Michael Kay <mhk@mhk.me.uk>
Date: Wed, 25 Aug 2004 09:57:07 +0100
To: "'Andreas Jacobsen'" <andreas.jacobsen@rasmus.uib.no>, <www-ql@w3.org>
Message-ID: <E1BztbA-0004sX-37@frink.w3.org>

In standard XPath and XQuery, you can't evaluate an XPath expression held as
a string: all expressions, including path expressions, have to be known at
compile time.

Some products have an extension function (see dyn:evaluate() at
www.exslt.org) to evaluate an expression constructed dynamically or read
from a source document. These tend to differ in the way they handle context,
e.g. namespaces and access to variables. Saxon has such an extension,
saxon:evaluate(), but it's currently available only in XSLT and not in
XQuery - this will change in the next release.

If the "expression" is limited to a single element name (a common use case
is specifying sort keys dynamically) then you can often get by with the
expression *[name()=$param] - but again there can be namespace
complications.

Michael Kay

 

> -----Original Message-----
> From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On 
> Behalf Of Andreas Jacobsen
> Sent: 25 August 2004 08:56
> To: www-ql@w3.org
> Subject: Compare string to node path?
> 
> 
> Hi everyone
> 
> I'm currently working on a master thesis which evolves around 
> using XQuery  
> as a multidatabase/multisource language. In this context I'm 
> try solve the  
> use of synonym element/attribute names in different 
> documents. This is  
> thought done by storing the paths to the synonymous 
> elements/attributes in  
> a xml-documents ("MDBDeclaration.xml"), and accessing these 
> by a function  
> (ub:mdb).There a two other xml documents that contains the data I'm  
> actually trying to return to the user. These are specified 
> together with  
> MDBDeclaration.xml in museumCollection.xml and accessed with 
> ease by Saxon)
> 
> So far so good, the paths are returned as they should.
> 
> I run in to trouble when I try to access the 
> elements/attributes in the  
> paths just extracted by the look-up function.
> 
> declare namespace ub = "http://www.uib.no";
> declare function ub:mdb($globalVariPath)
> 	{
> 	for $i in  
> doc("MDBDeclaration.xml")//member[refsGlobal=$globalVariPath]/path
> 	return $i
> 	};
> 
> let $globalVariPath := "zip"
> for $res in collection("museumCollection.xml")
> 
> where ub:mdb($globalVariPath) = local-name($res)
> 
> return $res
> 
> The Where clause is written in pseudo-code and does not perform as I  
> intended. I've tried using ub:mdb($globalVariPath)  as a 
> predicate in the  
> path expression(for-clause) but I don't get it to work there either
> 
> Any help would be greatly appreciated.
> 
> Regards
> Andreas Jacobsen
> University of Bergen, Norway
> 
> 
> -- 
> Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
> 
> 
Received on Wednesday, 25 August 2004 08:57:40 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:17:16 UTC