Project

Profile

Help

XQuery : the context item is undefined

Added by Anonymous almost 18 years ago

Legacy ID: #4047391 Legacy Poster: Monte Hansen (monte-hansen)

Hello again, I'm trying to run a simple xquery template that takes a document reference on input. I can't seem to get xqj to associate the context. I've run thru numerous XQUery and Java samples from Saxon and others. While I can seem execute using the builtin Stylus Studio ide. When using the bindContextItem approach, I get this error: Error on line 16 XPDY0002: Axis step descendant-or-self::node() cannot be used here: the context item is undefined When using bindNode with an externally declared variable, I get this error: Error at xsl:variable on line 1 of module with no systemId: XTDE0050: No value supplied for required parameter $d In the Stylus Studio ide, I've noticed that it supports the "." notation to reference the context document. Is that outside of the spec? Snippets below. Thanks in advance for your helps. Monte // Begin Java Snippet net.sf.saxon.Configuration config = new net.sf.saxon.Configuration(); XQDataSource dataSrc = new SaxonXQDataSource( config ); XQConnection connection = dataSrc.getConnection(); XQExpression exp = connection.createExpression(); XQItemType type = connection.createAtomicItemType( XQItemType.XQITEMKIND_DOCUMENT_ELEMENT ); exp.bindNode( new QName("$d"), document.getDocumentElement(), type ); //exp.bindContextItem( dataSrc.createItemFromNode( document, type ) ); XQResultSequence result = exp.executeQuery( new String(me) ); // End Java Snippet // Begin XQueryTemplate declare variable $d as document-node() external; declare function local:writeProcess($src as element())as element() { <Process name="{ $src/@description }" .... 9 lines snipped .... stackpath="{ $src/@stackpath }" > { for $v in $d//PerformanceStatistics/row where $v/@stackparentid = $src/@stackid return local:writeProcess( $v ) } </Process> }; <PerformanceStatistics> { for $v in $d//PerformanceStatistics/row where $v/@stackparentid = '' return local:writeProcess($v) } </PerformanceStatistics> // End XQueryTemplate


Replies (2)

RE: XQuery : the context item is undefined - Added by Anonymous almost 18 years ago

Legacy ID: #4047546 Legacy Poster: Michael Kay (mhkay)

Firstly, when binding the external variable, the name of the variable is "d", not "$d". I forgot that "new QName()" does not check that the name is a valid QName, so I probably should check this when using the QName. Your use of XQITEMKIND_DOCUMENT_ELEMENT is completely wrong, I think: but I don't think it should matter, because the value you supply in bindNode() or createItemFromNode() is ignored anyway. Apart from that, I'm afraid I can't see why it isn't working. It would help if you could supply a complete executable example so that I can reproduce the effect and if necessary run it through the debugger. It's always possible there's something wrong with the code you snipped out. It's nice to see the XQJ interface being used, but it's a very "wide" interface (lots of methods) and it hasn't been tested as thoroughly as I would like, in particular there are no third party tests available yet.

RE: XQuery : the context item is undefined - Added by Anonymous almost 18 years ago

Legacy ID: #4061082 Legacy Poster: Monte Hansen (monte-hansen)

> Firstly, when binding the external variable... Thanks Mike, that helped. I actually had the variable binding correct early on but with bad a type. It processed as expected after correcting the two. > It's nice to see the XQJ interface being used... I think this is going to be big; it's just going to take a while for folks to grasp and use it. Fortunately, familiar language constructs and xpath make it easier to dive in. It's a terrific compliment to Ajax, and with ajax being so popular, I think it's a perfect way to demonstrate XQuery/XQJ and increase awareness. I love this stuff! Thanks for the help Mike. Monte

    (1-2/2)

    Please register to reply