Package net.sf.saxon.sxpath

Examples of net.sf.saxon.sxpath.XPathExpression


        System.err.println("Stylesheet built OK");

        NodeInfo doc = config.buildDocument(new StreamSource(new File(sourceID).toURL().toString()));
        System.err.println("Source document built OK");
        net.sf.saxon.sxpath.XPathEvaluator xpath = new net.sf.saxon.sxpath.XPathEvaluator(config);
        XPathExpression xpe = xpath.createExpression("/*/*[1]");
        NodeInfo start = (NodeInfo)xpe.evaluateSingle(doc);

        Transformer transformer = templates.newTransformer();

        TinyBuilder builder = new TinyBuilder();
        transformer.transform(start, builder);
View Full Code Here


            }
        }
        try {
            XPathEvaluator eval = new XPathEvaluator(processor.getUnderlyingConfiguration());
            eval.setStaticContext(ic);
            XPathExpression cexp = eval.createExpression(source);
            return new XPathExecutable(cexp, processor, ic);
        } catch (XPathException e) {
            throw new SaxonApiException(e);
        }
    }
View Full Code Here

    public XPathExecutable compilePattern(String source) throws SaxonApiException {
        try {
            XPathEvaluator eval = new XPathEvaluator(processor.getUnderlyingConfiguration());
            eval.setStaticContext(env);
            XPathExpression cexp = eval.createPattern(source);
            return new XPathExecutable(cexp, processor, env);
        } catch (XPathException e) {
            throw new SaxonApiException(e);
        }
    }
View Full Code Here

    public XPathExecutable compile(String source) throws SaxonApiException {
        try {
            XPathEvaluator eval = new XPathEvaluator(config);
            eval.setStaticContext(env);
            XPathExpression cexp = eval.createExpression(source);
            return new XPathExecutable(cexp, config, env, declaredVariables);
        } catch (XPathException e) {
            throw new SaxonApiException(e);
        }
    }
View Full Code Here

            xpe.setStaticContext(sc);

            Variable thisVar = sc.declareVariable(_contextVar);
            thisVar.setValue(needsDomSourceWrapping ? rootNode : node);

            XPathExpression exp = xpe.createExpression(_queryExpr);

            // After 8.3(?) Saxon nodes no longer implement Dom.
            // The client needs saxon8-dom.jar, and the code needs
            // this NodeOverNodeInfo Dom wrapper doohickey
            List saxonNodes = exp.evaluate(rootNode);
            for (ListIterator it = saxonNodes.listIterator(); it.hasNext();)
            {
                Object o = it.next();
                if(o instanceof NodeInfo)
                {
View Full Code Here

            Value errorObject = ((Value)SequenceExtent.makeSequenceExtent(argument[2].iterate(context))).reduce();
            if (errorObject instanceof SingletonNode) {
                NodeInfo root = ((SingletonNode)errorObject).getNode();
                if (root.getNodeKind() == Type.DOCUMENT) {
                    XPathEvaluator xpath = new XPathEvaluator();
                    XPathExpression exp = xpath.createExpression("/error/@module");
                    NodeInfo moduleAtt = (NodeInfo)exp.evaluateSingle(root);
                    String module = (moduleAtt == null ? null : moduleAtt.getStringValue());
                    exp = xpath.createExpression("/error/@line");
                    NodeInfo lineAtt = (NodeInfo)exp.evaluateSingle(root);
                    int line = (lineAtt == null ? -1 : Integer.parseInt(lineAtt.getStringValue()));
                    exp = xpath.createExpression("/error/@column");
                    NodeInfo columnAtt = (NodeInfo)exp.evaluateSingle(root);
                    int column = (columnAtt == null ? -1 : Integer.parseInt(columnAtt.getStringValue()));
                    ExpressionLocation locator = new ExpressionLocation();
                    locator.setSystemId(module);
                    locator.setLineNumber(line);
                    locator.setColumnNumber(column);
View Full Code Here

    public static void main(String[] args) throws Exception {
        Configuration config = new Configuration();
        Expression exp;
        if (args[0].equals("xpath")) {
            XPathEvaluator xpath = new XPathEvaluator(config);
            XPathExpression xpexp = xpath.createExpression(args[1]);
            exp = xpexp.getInternalExpression();
        } else if (args[0].equals("xquery")) {
            StaticQueryContext sqc = new StaticQueryContext(config);
            sqc.setBaseURI(new File(args[1]).toURI().toString());
            XQueryExpression xqe = sqc.compileQuery(new FileReader(args[1]));
            exp = xqe.getExpression();
View Full Code Here

                // From Michael Kay: http://markmail.org/message/vkb2vaq2miylgndu
                //
                // Underneath the s9api XPathExecutable is a net.sf.saxon.sxpath.XPathExpression.

                XPathExpression xexpr = xexec.getUnderlyingExpression();

                // Call createDynamicContext() on this to get an XPathDynamicContext object;

                XPathDynamicContext xdc = xexpr.createDynamicContext(node.getUnderlyingNode());

                // call getXPathContextObject() on that to get the underlying XPathContext.

                XPathContext xc = xdc.getXPathContextObject();

                // Then call XPathContext.setCurrentIterator()
                // to supply a SequenceIterator whose current() and position() methods return
                // the context item and position respectively. If there's any risk that the
                // expression will call the last() method, then it's simplest to make your
                // iterator's getProperties() return LAST_POSITION_FINDER, and implement the
                // LastPositionFinder interface, in which case last() will be implemented by
                // calling the iterator's getLastPosition() method. (Otherwise last() is
                // implemented by calling getAnother() to clone the iterator and calling next()
                // on the clone until the end of the sequence is reached).

                xsi.setPosition(pos);
                xsi.setItem(node.getUnderlyingNode());
                xc.setCurrentIterator(xsi);

                // Then evaluate the expression by calling iterate() on the
                // net.sf.saxon.sxpath.XPathExpression object.

                SequenceIterator<?> results = xexpr.iterate(xdc);
                item = results.next();

                if (item == null) {
                    throw new XProcException(step.getNode(), "The group-adjacent expression returned nothing.");
                }
View Full Code Here

        // From Michael Kay: http://markmail.org/message/vkb2vaq2miylgndu
        //
        // Underneath the s9api XPathExecutable is a net.sf.saxon.sxpath.XPathExpression.

        XPathExpression xexpr = xexec.getUnderlyingExpression();

        int pos = 0;
        while (source.moreDocuments()) {
            XdmNode doc = source.read();
            pos++;

            Item item = null;

            try {
                // Call createDynamicContext() on this to get an XPathDynamicContext object;

                XPathDynamicContext xdc = xexpr.createDynamicContext(doc.getUnderlyingNode());

                // call getXPathContextObject() on that to get the underlying XPathContext.

                XPathContext xc = xdc.getXPathContextObject();

                // Then call XPathContext.setCurrentIterator()
                // to supply a SequenceIterator whose current() and position() methods return
                // the context item and position respectively. If there's any risk that the
                // expression will call the last() method, then it's simplest to make your
                // iterator's getProperties() return LAST_POSITION_FINDER, and implement the
                // LastPositionFinder interface, in which case last() will be implemented by
                // calling the iterator's getLastPosition() method. (Otherwise last() is
                // implemented by calling getAnother() to clone the iterator and calling next()
                // on the clone until the end of the sequence is reached).

                xsi.setPosition(pos);
                xsi.setItem(doc.getUnderlyingNode());
                xc.setCurrentIterator(xsi);

                // Then evaluate the expression by calling iterate() on the
                // net.sf.saxon.sxpath.XPathExpression object.

                SequenceIterator<?> results = xexpr.iterate(xdc);
                // FIXME: What if the expression returns a sequence?
                item = results.next();
            } catch (XPathException xe) {
                throw new XProcException(xe);
            }
View Full Code Here

        System.err.println("Stylesheet built OK");

        NodeInfo doc = config.buildDocument(new StreamSource(new File(sourceID).toURI().toString()));
        System.err.println("Source document built OK");
        net.sf.saxon.sxpath.XPathEvaluator xpath = new net.sf.saxon.sxpath.XPathEvaluator(config);
        XPathExpression xpe = xpath.createExpression("/*/*[1]");
        NodeInfo start = (NodeInfo)xpe.evaluateSingle(doc);

        Transformer transformer = templates.newTransformer();

        Builder builder = TreeModel.TINY_TREE.makeBuilder(config.makePipelineConfiguration());
        transformer.transform(start, builder);
View Full Code Here

TOP

Related Classes of net.sf.saxon.sxpath.XPathExpression

Copyright © 2018 www.massapicom. 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.