Package net.sf.saxon.query

Examples of net.sf.saxon.query.StaticQueryContext.compileQuery()


     */

    public static void exampleWithParam() throws XPathException {
        final Configuration config = new Configuration();
        final StaticQueryContext sqc = config.newStaticQueryContext();
        final XQueryExpression exp = sqc.compileQuery("declare variable $in as xs:integer external;" +
                "$in * $in");

        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        dynamicContext.setParameterValue("in", Int64Value.makeIntegerValue(17));
        final Long result = (Long)exp.evaluateSingle(dynamicContext);
View Full Code Here


    public static void examplePipeline() throws XPathException {
        final Configuration config = new Configuration();

        // Compile the first query
        final StaticQueryContext sqc1 = config.newStaticQueryContext();
        final XQueryExpression exp1 = sqc1.compileQuery("declare variable $in as xs:integer external;" +
                "document{ <a>{$in * $in}</a> }");

        // Compile the second query (each query should have its own static context)
        final StaticQueryContext sqc2 = config.newStaticQueryContext();
        final XQueryExpression exp2 = sqc2.compileQuery("/a + 5");
View Full Code Here

        final XQueryExpression exp1 = sqc1.compileQuery("declare variable $in as xs:integer external;" +
                "document{ <a>{$in * $in}</a> }");

        // Compile the second query (each query should have its own static context)
        final StaticQueryContext sqc2 = config.newStaticQueryContext();
        final XQueryExpression exp2 = sqc2.compileQuery("/a + 5");

        // Run the first query
        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        dynamicContext.setParameterValue("in", Int64Value.makeIntegerValue(3));
        final NodeInfo doc = (NodeInfo)exp1.evaluateSingle(dynamicContext);
View Full Code Here

     */

    public static void exampleDirectFunction() throws XPathException {
        final Configuration config = new Configuration();
        final StaticQueryContext sqc = config.newStaticQueryContext();
        final XQueryExpression exp1 = sqc.compileQuery("declare namespace f='f.ns';" +
                "declare function f:t1($v1 as xs:integer, $v2 as xs:untypedAtomic*) { " +
                "   $v1 div $v2" +
                "};" +
                "10");

View Full Code Here

                    StaticQueryContext qenv = config.newStaticQueryContext();
                    qenv.setBaseURI(query.toURI().toString());
                    if (val) {
                        qenv.setSchemaAware(true);
                    }
                    XQueryExpression exp = qenv.compileQuery(new FileReader(query));
                    int runs = 0;
                    long totalTime = 0;
                    long min = Integer.MAX_VALUE;
                    long max = 0;
                    for (int t=0; t<1000; t++) {
View Full Code Here

     * Run a query against input that is supplied using the pull interface
     */

    public void query(PullProvider in, String query, OutputStream out) throws XPathException {
        final StaticQueryContext sqc = config.newStaticQueryContext();
        final XQueryExpression exp = sqc.compileQuery(query);
        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        dynamicContext.setContextItem(config.buildDocument(new PullSource(in)));
        Properties props = new Properties();
        props.setProperty(OutputKeys.INDENT, "yes");
        exp.run(dynamicContext, new StreamResult(out), props);
View Full Code Here

     * of the query
     */

    public PullProvider pullQueryResults(NodeInfo source, String query) throws XPathException {
        final StaticQueryContext sqc = config.newStaticQueryContext();
        final XQueryExpression exp = sqc.compileQuery(query);
        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        dynamicContext.setContextItem(source);
        PullProvider pull = new PullFromIterator(exp.iterator(dynamicContext));
        pull = new PullNamespaceReducer(pull);
        pull.setPipelineConfiguration(config.makePipelineConfiguration());
View Full Code Here

     */

    public static void exampleToSerializedSequence() throws XPathException {
        final Configuration config = new Configuration();
        final StaticQueryContext sqc = new StaticQueryContext(config);
        final XQueryExpression exp = sqc.compileQuery("<doc><chap><a>3</a></chap></doc>//a, <b>4</b>, attribute c {5}, 19");
        Properties props = new Properties();
        props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        final SequenceIterator iter = exp.iterator(dynamicContext);
View Full Code Here

     */

    public static void exampleToWrappedSequence() throws XPathException {
        final Configuration config = new Configuration();
        final StaticQueryContext sqc = new StaticQueryContext(config);
        final XQueryExpression exp = sqc.compileQuery("<doc><chap><a>3</a></chap></doc>//a, <b>4</b>, attribute c {5}, 19");
        Properties props = new Properties();
        props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
        props.setProperty(OutputKeys.INDENT, "yes");

        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
View Full Code Here

     */

    public static void exampleToHTMLFile() throws XPathException, IOException {
        final Configuration config = new Configuration();
        final StaticQueryContext sqc = new StaticQueryContext(config);
        final XQueryExpression exp = sqc.compileQuery(new FileReader("query/books-to-html.xq"));
        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        dynamicContext.setContextNode(sqc.buildDocument(new StreamSource("data/books.xml")));
        final Properties props = new Properties();
        props.setProperty(OutputKeys.METHOD, "html");
        props.setProperty(OutputKeys.DOCTYPE_PUBLIC, "-//W3C//DTD HTML 4.01 Transitional//EN");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.