Search in sources :

Example 6 with XPath

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

the class StylesheetRoot method initDefaultRule.

/**
   * Create the default rule if needed.
   *
   * @throws TransformerException
   */
private void initDefaultRule(ErrorListener errorListener) throws TransformerException {
    // Then manufacture a default
    m_defaultRule = new ElemTemplate();
    m_defaultRule.setStylesheet(this);
    XPath defMatch = new XPath("*", this, this, XPath.MATCH, errorListener);
    m_defaultRule.setMatch(defMatch);
    ElemApplyTemplates childrenElement = new ElemApplyTemplates();
    childrenElement.setIsDefaultTemplate(true);
    childrenElement.setSelect(m_selectDefault);
    m_defaultRule.appendChild(childrenElement);
    m_startRule = m_defaultRule;
    // -----------------------------
    m_defaultTextRule = new ElemTemplate();
    m_defaultTextRule.setStylesheet(this);
    defMatch = new XPath("text() | @*", this, this, XPath.MATCH, errorListener);
    m_defaultTextRule.setMatch(defMatch);
    ElemValueOf elemValueOf = new ElemValueOf();
    m_defaultTextRule.appendChild(elemValueOf);
    XPath selectPattern = new XPath(".", this, this, XPath.SELECT, errorListener);
    elemValueOf.setSelect(selectPattern);
    //--------------------------------
    m_defaultRootRule = new ElemTemplate();
    m_defaultRootRule.setStylesheet(this);
    defMatch = new XPath("/", this, this, XPath.MATCH, errorListener);
    m_defaultRootRule.setMatch(defMatch);
    childrenElement = new ElemApplyTemplates();
    childrenElement.setIsDefaultTemplate(true);
    m_defaultRootRule.appendChild(childrenElement);
    childrenElement.setSelect(m_selectDefault);
}
Also used : XPath(org.apache.xpath.XPath)

Example 7 with XPath

use of org.apache.xpath.XPath in project j2objc by google.

the class StylesheetHandler method createMatchPatternXPath.

/**
   * Process an expression string into an XPath.
   *
   * @param str A non-null reference to a valid or invalid match pattern string.
   *
   * @return A non-null reference to an XPath object that represents the string argument.
   *
   * @throws javax.xml.transform.TransformerException if the pattern can not be processed.
   * @see <a href="http://www.w3.org/TR/xslt#patterns">Section 5.2 Patterns in XSLT Specification</a>
   */
XPath createMatchPatternXPath(String str, ElemTemplateElement owningTemplate) throws javax.xml.transform.TransformerException {
    ErrorListener handler = m_stylesheetProcessor.getErrorListener();
    XPath xpath = new XPath(str, owningTemplate, this, XPath.MATCH, 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 8 with XPath

use of org.apache.xpath.XPath in project j2objc by google.

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 9 with XPath

use of org.apache.xpath.XPath in project j2objc by google.

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 10 with XPath

use of org.apache.xpath.XPath in project j2objc by google.

the class ElemWithParam 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 = ElemVariable.rewriteChildToExpression(this);
        if (null != newSelect)
            m_selectPattern = newSelect;
    }
    m_qnameID = sroot.getComposeState().getQNameID(m_qname);
    super.compose(sroot);
    java.util.Vector vnames = sroot.getComposeState().getVariableNames();
    if (null != m_selectPattern)
        m_selectPattern.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize());
// m_index must be resolved by ElemApplyTemplates and ElemCallTemplate!
}
Also used : XPath(org.apache.xpath.XPath)

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