Search in sources :

Example 1 with XPath

use of org.apache.xpath.XPath in project robovm by robovm.

the class ElemNumber method getCountMatchPattern.

/**
   * Get the count match pattern, or a default value.
   *
   * @param support The XPath runtime state for this.
   * @param contextNode The node that "." expresses.
   *
   * @return the count match pattern, or a default value. 
   *
   * @throws javax.xml.transform.TransformerException
   */
XPath getCountMatchPattern(XPathContext support, int contextNode) throws javax.xml.transform.TransformerException {
    XPath countMatchPattern = m_countMatchPattern;
    DTM dtm = support.getDTM(contextNode);
    if (null == countMatchPattern) {
        switch(dtm.getNodeType(contextNode)) {
            case DTM.ELEMENT_NODE:
                MyPrefixResolver resolver;
                if (dtm.getNamespaceURI(contextNode) == null) {
                    resolver = new MyPrefixResolver(dtm.getNode(contextNode), dtm, contextNode, false);
                } else {
                    resolver = new MyPrefixResolver(dtm.getNode(contextNode), dtm, contextNode, true);
                }
                countMatchPattern = new XPath(dtm.getNodeName(contextNode), this, resolver, XPath.MATCH, support.getErrorListener());
                break;
            case DTM.ATTRIBUTE_NODE:
                // countMatchPattern = m_stylesheet.createMatchPattern("@"+contextNode.getNodeName(), this);
                countMatchPattern = new XPath("@" + dtm.getNodeName(contextNode), this, this, XPath.MATCH, support.getErrorListener());
                break;
            case DTM.CDATA_SECTION_NODE:
            case DTM.TEXT_NODE:
                // countMatchPattern = m_stylesheet.createMatchPattern("text()", this);
                countMatchPattern = new XPath("text()", this, this, XPath.MATCH, support.getErrorListener());
                break;
            case DTM.COMMENT_NODE:
                // countMatchPattern = m_stylesheet.createMatchPattern("comment()", this);
                countMatchPattern = new XPath("comment()", this, this, XPath.MATCH, support.getErrorListener());
                break;
            case DTM.DOCUMENT_NODE:
                // countMatchPattern = m_stylesheet.createMatchPattern("/", this);
                countMatchPattern = new XPath("/", this, this, XPath.MATCH, support.getErrorListener());
                break;
            case DTM.PROCESSING_INSTRUCTION_NODE:
                // countMatchPattern = m_stylesheet.createMatchPattern("pi("+contextNode.getNodeName()+")", this);
                countMatchPattern = new XPath("pi(" + dtm.getNodeName(contextNode) + ")", this, this, XPath.MATCH, support.getErrorListener());
                break;
            default:
                countMatchPattern = null;
        }
    }
    return countMatchPattern;
}
Also used : XPath(org.apache.xpath.XPath) NodeSetDTM(org.apache.xpath.NodeSetDTM) DTM(org.apache.xml.dtm.DTM)

Example 2 with XPath

use of org.apache.xpath.XPath in project robovm by robovm.

the class ElemNumber method getMatchingAncestors.

/**
   * Get the ancestors, up to the root, that match the
   * pattern.
   * 
   * @param xctxt The XPath runtime state for this.
   * @param node Count this node and it's ancestors.
   * @param stopAtFirstFound Flag indicating to stop after the
   * first node is found (difference between level = single
   * or multiple)
   * @return The number of ancestors that match the pattern.
   *
   * @throws javax.xml.transform.TransformerException
   */
NodeVector getMatchingAncestors(XPathContext xctxt, int node, boolean stopAtFirstFound) throws javax.xml.transform.TransformerException {
    NodeSetDTM ancestors = new NodeSetDTM(xctxt.getDTMManager());
    XPath countMatchPattern = getCountMatchPattern(xctxt, node);
    DTM dtm = xctxt.getDTM(node);
    while (DTM.NULL != node) {
        if ((null != m_fromMatchPattern) && (m_fromMatchPattern.getMatchScore(xctxt, node) != XPath.MATCH_SCORE_NONE)) {
            // that we still don't understand.
            if (!stopAtFirstFound)
                break;
        }
        if (null == countMatchPattern)
            System.out.println("Programmers error! countMatchPattern should never be null!");
        if (countMatchPattern.getMatchScore(xctxt, node) != XPath.MATCH_SCORE_NONE) {
            ancestors.addElement(node);
            if (stopAtFirstFound)
                break;
        }
        node = dtm.getParent(node);
    }
    return ancestors;
}
Also used : XPath(org.apache.xpath.XPath) NodeSetDTM(org.apache.xpath.NodeSetDTM) NodeSetDTM(org.apache.xpath.NodeSetDTM) DTM(org.apache.xml.dtm.DTM)

Example 3 with XPath

use of org.apache.xpath.XPath in project robovm by robovm.

the class StylesheetHandler method createXPath.

/**
   * Process an expression string into an XPath.
   * Must be public for access by the AVT class.
   *
   * @param str A non-null reference to a valid or invalid XPath expression string.
   *
   * @return A non-null reference to an XPath object that represents the string argument.
   *
   * @throws javax.xml.transform.TransformerException if the expression can not be processed.
   * @see <a href="http://www.w3.org/TR/xslt#section-Expressions">Section 4 Expressions in XSLT Specification</a>
   */
public XPath createXPath(String str, ElemTemplateElement owningTemplate) throws javax.xml.transform.TransformerException {
    ErrorListener handler = m_stylesheetProcessor.getErrorListener();
    XPath xpath = new XPath(str, owningTemplate, this, XPath.SELECT, handler, m_funcTable);
    // Visit the expression, registering namespaces for any extension functions it includes.
    xpath.callVisitors(xpath, new ExpressionVisitor(getStylesheetRoot()));
    return xpath;
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) XPath(org.apache.xpath.XPath) ExpressionVisitor(org.apache.xalan.extensions.ExpressionVisitor)

Example 4 with XPath

use of org.apache.xpath.XPath in project robovm by robovm.

the class ElemVariable method compose.

/**
   * This function is called after everything else has been
   * recomposed, and allows the template to set remaining
   * values that may be based on some other property that
   * depends on recomposition.
   */
public void compose(StylesheetRoot sroot) throws TransformerException {
    // See if we can reduce an RTF to a select with a string expression.
    if (null == m_selectPattern && sroot.getOptimizer()) {
        XPath newSelect = rewriteChildToExpression(this);
        if (null != newSelect)
            m_selectPattern = newSelect;
    }
    StylesheetRoot.ComposeState cstate = sroot.getComposeState();
    // This should be done before addVariableName, so we don't have visibility 
    // to the variable now being defined.
    java.util.Vector vnames = cstate.getVariableNames();
    if (null != m_selectPattern)
        m_selectPattern.fixupVariables(vnames, cstate.getGlobalsSize());
    // it was already added by stylesheet root.
    if (!(m_parentNode instanceof Stylesheet) && m_qname != null) {
        m_index = cstate.addVariableName(m_qname) - cstate.getGlobalsSize();
    } else if (m_parentNode instanceof Stylesheet) {
        // If this is a global, then we need to treat it as if it's a xsl:template, 
        // and count the number of variables it contains.  So we set the count to 
        // zero here.
        cstate.resetStackFrameSize();
    }
    // This has to be done after the addVariableName, so that the variable 
    // pushed won't be immediately popped again in endCompose.
    super.compose(sroot);
}
Also used : XPath(org.apache.xpath.XPath)

Example 5 with XPath

use of org.apache.xpath.XPath in project robovm by robovm.

the class RedundentExprEliminator method createGlobalPseudoVarDecl.

/**
   * Create a psuedo variable reference that will represent the 
   * shared redundent XPath, for a local reduction.
   * 
   * @param uniquePseudoVarName The name of the new variable.
   * @param stylesheetRoot The broadest scope of where the variable 
   *        should be inserted, which must be a StylesheetRoot element in this case.
   * @param lpi The LocationPathIterator that the variable should represent.
   * @return null if the decl was not created, otherwise the new Pseudo var  
   *              element.
   */
protected ElemVariable createGlobalPseudoVarDecl(QName uniquePseudoVarName, StylesheetRoot stylesheetRoot, LocPathIterator lpi) throws org.w3c.dom.DOMException {
    ElemVariable psuedoVar = new ElemVariable();
    psuedoVar.setIsTopLevel(true);
    XPath xpath = new XPath(lpi);
    psuedoVar.setSelect(xpath);
    psuedoVar.setName(uniquePseudoVarName);
    Vector globalVars = stylesheetRoot.getVariablesAndParamsComposed();
    psuedoVar.setIndex(globalVars.size());
    globalVars.addElement(psuedoVar);
    return psuedoVar;
}
Also used : XPath(org.apache.xpath.XPath) Vector(java.util.Vector)

Aggregations

XPath (org.apache.xpath.XPath)32 TransformerException (javax.xml.transform.TransformerException)7 DTM (org.apache.xml.dtm.DTM)7 Vector (java.util.Vector)6 NodeSetDTM (org.apache.xpath.NodeSetDTM)6 ErrorListener (javax.xml.transform.ErrorListener)4 ExpressionVisitor (org.apache.xalan.extensions.ExpressionVisitor)4 StringTokenizer (java.util.StringTokenizer)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 ElemExtensionCall (org.apache.xalan.templates.ElemExtensionCall)2 ElemLiteralResult (org.apache.xalan.templates.ElemLiteralResult)2 ElemTemplate (org.apache.xalan.templates.ElemTemplate)2 ElemTemplateElement (org.apache.xalan.templates.ElemTemplateElement)2 KeyDeclaration (org.apache.xalan.templates.KeyDeclaration)2 Stylesheet (org.apache.xalan.templates.Stylesheet)2 QName (org.apache.xml.utils.QName)2 SAXSourceLocator (org.apache.xml.utils.SAXSourceLocator)2 StringVector (org.apache.xml.utils.StringVector)2 Expression (org.apache.xpath.Expression)2 StepPattern (org.apache.xpath.patterns.StepPattern)2