[xquery-talk] modules and context

Howard Katz howardk at fatdog.com
Fri Nov 18 08:14:13 PST 2005


What processor are you using? Some let you preset the top-level context so
that "anonymous" xpaths like "//rng:define" will work. Saxon for example
lets you optionally assign the context to a named document.

It seems a bit wasteful to have to reload the top-level document node via a
second call to doc( ). Why don't you just pass in the top-level context as
an argument to the function you're calling, as in:

declare function dp:gatts($attributes as xs:string, $top-level as
element()+)
{
    for $att in $top-level//rng:define[@name=$attributes]
    ...

Either that or pass in rng:define directly, as in 

declare function dp:gatts($attributes as xs:string, $elem-to-check as
element()+)
{
    for $att in elem-to-check[@name=$attributes]
    ...

Howard
   
 > -----Original Message-----
 > From: talk-bounces at xquery.com 
 > [mailto:talk-bounces at xquery.com] On Behalf Of Dave Pawson
 > Sent: November 18, 2005 7:48 AM
 > To: talk at xquery.com
 > Subject: [xquery-talk] modules and context
 > 
 > I've written a function in a module,
 > and I'm getting the error
 > XPDY0002: Cannot select a node here: the context item is undefined
 > 
 > How do I ... pass in the / context  of a document please,
 > or do I have to open it with doc('a.xml') again?
 > 
 > TIA
 > 
 > Module - failing - is below
 > 
 > xquery version "1.0";
 > module namespace dp ="urn:modul";
 > declare namespace db ="http://docbook.org/ns/docbook";
 > declare namespace rng = "http://relaxng.org/ns/structure/1.0" ;
 > 
 > declare function dp:gatts($attributes as xs:string)
 > {
 > for $att in //rng:define[@name=$attributes]
 > return
 > <att>{$att}</att>
 > };
 > 
 > 
 > 
 > 
 > --
 > Dave Pawson
 > XSLT XSL-FO FAQ.
 > http://www.dpawson.co.uk
 > 
 > _______________________________________________
 > talk at xquery.com
 > http://xquery.com/mailman/listinfo/talk
 > 



More information about the talk mailing list