qexo-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qexo-general] Re: Quexo question


From: Stan Pinte
Subject: [Qexo-general] Re: Quexo question
Date: Thu, 30 Oct 2003 11:14:38 +0100


hello Per,

thanks a lot for your answer. As I don't specifically want to generate xml, and would prefer to use XQuery, because I may want to make queries on several documents in the same time, and to define more complicated control sequences...

Now there are stuff I cannot find in the Qexo doc, but well in the Saxon doc:

----------- saxon Java interface doc --------

Before you run your query, you may want to build one or more trees representing XML documents that can be used as input to your query. You don't need to do this: if the query loads its source documents using the doc() function then this will be done automatically, but doing it yourself gives you more control. A document node at the root of a tree is represented in Saxon by the net.sf.saxon.DocumentInfo interface. The QueryProcessor provides a convenience method, buildDocument(), that allows an instance of DocumentInfo to be constructed. The input parameter to this is defined by the class javax.xml.transform.Source, which is part of the standard Java JAXP API: the Source interface is an umbrella for different kinds of XML document source, including a StreamSource which parses raw XML from a byte or character stream, SAXSource which takes the input from a SAX parser (or an object that is simulating a SAX parser), and DOMSource which provides the input from a DOM. Saxon also provides a net.sf.saxon.jdom.DocumentWrapper which allows the input to be taken from a JDOM document.

To execute your compiled query, you need to create a DynamicQueryContext object that holds the run-time context information. The main things you can set in the run-time context are: Values of parameters (external global variables). You can set these using the setParameter() method. The mappings from Java classes to XQuery/XPath data types is the same as the mapping used for the returned values from an external Java method call, and is described under Result of an Extension Function. The context node can be set using the method setContextNode(). For some reason it isn't possible to set a context item other than a node. You can also set a URIResolver and/or ErrorListener. These default to the ones that were used during Query compilation.

----------- end of saxon Java interface doc --------

How can I do the following in Qexo, using the Java embedding (i.e. calling XQuery xq = new XQuery();, xq.eval()):

-how can I pass the interpreter some parameters
-how can I pass it an XML DOM node, to use as query context


Thanks a lot,

Stan.


At 17:26 29/10/2003, Per Bothner wrote:
Content-Transfer-Encoding: 7bit

Stan Pinte wrote:

--> I am trying to use Xquery, to be able to compute some values in an XML document, using values defined in this documents. In this very example, I am trying to print out the value of an attribute of a tag specified above...I would like for example to perform numerical operations on them.

I guess if you're careful you could write a write a file that is both valid XML and valid XQuery. Then you could use a call the doc("thix.xml") to access the document, or you could use the (not-yet implemented Qexo feature to bind the top-level focus.

I suspect XSLT would work better for you.  You can use XSLT's
"simplified stylesheets".  For example:

<result xsl:version="1.1"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <field name="one" value="11"/>
    <field name="two" value="12"/>
    <computed name="hehe" value="{sum(result/field/@value)}"/>
</result>

Running this through Saxon (7.6.5) and specifying the same filename for both the input document and teh stylesheet, I get:

<?xml version="1.0" encoding="UTF-8"?><result><field name="one" value="11"/><field name="two" value="12"/><computed name="hehe" value="23"/></result>
--
        --Per Bothner
address@hidden   http://per.bothner.com/





--
Incoming mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.193 / Virus Database: 260.2.2 - Release Date: 27/10/2003


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.193 / Virus Database: 260.2.2 - Release Date: 27/10/2003






reply via email to

[Prev in Thread] Current Thread [Next in Thread]