Package net.sf.saxon.expr

Examples of net.sf.saxon.expr.Expression


                TinyBuilder result = new TinyBuilder();
                factory.newTransformer().transform(source, result);
                contextNode = (Node)result.getCurrentDocument();
            }

            Expression expression = ExpressionTool.make(
                    str, new Saxon7Context((NodeInfo)contextNode, resolver), 0, -1);
            XPathContext context = new XPathContext((NodeInfo)contextNode);
            return expression.iterate(context);
        }
        catch (final Exception e)
        {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Failed to evaluate '" + str + "'", e);
View Full Code Here


        if ((contextNode == null) || !(contextNode instanceof Element) ||
                !(xpathExpr instanceof XPathExpressionImpl)) {
            return;
        }

        Expression expression = ((XPathExpressionImpl) xpathExpr).getInternalExpression();
        Iterator<Expression> subExpressions = (Iterator<Expression>) expression.iterateSubExpressions();

        if (!subExpressions.hasNext()) {
            return;
        }

        Expression subExpr = (Expression) subExpressions.next();

        if (!(subExpr instanceof PathExpression)) {
            return;
        }

        Document document = DOMUtils.toDOMDocument(contextNode);
        PathExpression pathExpr = (PathExpression) subExpr;
        Expression step = pathExpr.getFirstStep();

        while (step != null) {
            if (step instanceof AxisExpression) {
                AxisExpression axisExpr = (AxisExpression) step;

                NodeTest nodeTest = axisExpr.getNodeTest();

                if (!(nodeTest instanceof NameTest)) {
                    break;
                }

                NameTest nameTest = (NameTest) nodeTest;

                QName childName = getQualifiedName(nameTest.getFingerprint(),
                        namePool, contextUris);
               
                if (Axis.CHILD == axisExpr.getAxis()) {
                    if (NodeKindTest.ELEMENT.getNodeKindMask() != nameTest.getNodeKindMask()) {
                        break;
                    }
                 
                    NodeList children = ((Element) contextNode).getElementsByTagNameNS(childName.getNamespaceURI(),
                            childName.getLocalPart());
                    if ((children == null) || (children.getLength() == 0)) {
                        Node child = document.createElementNS(childName.getNamespaceURI(),
                                DOMUtils.getQualifiedName(childName));
                        contextNode.appendChild(child);
                        contextNode = child;
                    } else if (children.getLength() == 1) {
                        contextNode = children.item(0);
                    } else {
                        break;
                    }
                } else if (Axis.ATTRIBUTE == axisExpr.getAxis()) {
                    if (NodeKindTest.ATTRIBUTE.getNodeKindMask() != nameTest.getNodeKindMask()) {
                        break;
                    }
                   
                    Attr attribute = ((Element) contextNode).getAttributeNodeNS(childName.getNamespaceURI(), childName.getLocalPart());
                    if (attribute == null) {
                      attribute = document.createAttributeNS(childName.getNamespaceURI(), childName.getLocalPart());
                      ((Element) contextNode).setAttributeNode(attribute);
                      contextNode = attribute;
                    } else {
                      break;
                    }
                 
                } else {
                  break;
                }


            } else if (step instanceof ItemChecker) {
                ItemChecker itemChecker = (ItemChecker) step;
                Expression baseExpr = itemChecker.getBaseExpression();

                if (!(baseExpr instanceof VariableReference)) {
                    break;
                }
            } else {
                break;
            }

            if (pathExpr != null) {
                Expression remainingSteps = pathExpr.getRemainingSteps();

                if (remainingSteps instanceof PathExpression) {
                    pathExpr = (PathExpression) remainingSteps;
                    step = pathExpr.getFirstStep();
                } else if (remainingSteps instanceof AxisExpression) {
View Full Code Here

                TinyBuilder result = new TinyBuilder();
                factory.newTransformer().transform(source, result);
                contextNode = (Node)result.getCurrentDocument();
            }

            Expression expression = ExpressionTool.make(
                    str, new Saxon7Context((NodeInfo)contextNode, resolver));
            XPathContext context = new XPathContext((NodeInfo)contextNode);
            return expression.iterate(context);
        }
        catch (final Exception e)
        {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Failed to evaluate '" + str + "'", e);
View Full Code Here

TOP

Related Classes of net.sf.saxon.expr.Expression

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.