Search in sources :

Example 11 with XPath

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

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

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

the class KeyIterator method acceptNode.

/**
   *  Test whether a specified node is visible in the logical view of a
   * TreeWalker or NodeIterator. This function will be called by the
   * implementation of TreeWalker and NodeIterator; it is not intended to
   * be called directly from user code.
   * 
   * @param testNode  The node to check to see if it passes the filter or not.
   *
   * @return  a constant to determine whether the node is accepted,
   *   rejected, or skipped, as defined  above .
   */
public short acceptNode(int testNode) {
    boolean foundKey = false;
    KeyIterator ki = (KeyIterator) m_lpi;
    org.apache.xpath.XPathContext xctxt = ki.getXPathContext();
    Vector keys = ki.getKeyDeclarations();
    QName name = ki.getName();
    try {
        // System.out.println("lookupKey: "+lookupKey);
        int nDeclarations = keys.size();
        // Walk through each of the declarations made with xsl:key
        for (int i = 0; i < nDeclarations; i++) {
            KeyDeclaration kd = (KeyDeclaration) keys.elementAt(i);
            // matches the name on the iterator for this walker. 
            if (!kd.getName().equals(name))
                continue;
            foundKey = true;
            // xctxt.setNamespaceContext(ki.getPrefixResolver());
            // See if our node matches the given key declaration according to 
            // the match attribute on xsl:key.
            XPath matchExpr = kd.getMatch();
            double score = matchExpr.getMatchScore(xctxt, testNode);
            if (score == kd.getMatch().MATCH_SCORE_NONE)
                continue;
            return DTMIterator.FILTER_ACCEPT;
        }
    // end for(int i = 0; i < nDeclarations; i++)
    } catch (TransformerException se) {
    // TODO: What to do?
    }
    if (!foundKey)
        throw new RuntimeException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_XSLKEY_DECLARATION, new Object[] { name.getLocalName() }));
    return DTMIterator.FILTER_REJECT;
}
Also used : XPath(org.apache.xpath.XPath) QName(org.apache.xml.utils.QName) KeyDeclaration(org.apache.xalan.templates.KeyDeclaration) Vector(java.util.Vector) TransformerException(javax.xml.transform.TransformerException)

Example 13 with XPath

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

the class RedundentExprEliminator method createLocalPseudoVarDecl.

/**
   * 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 psuedoVarRecipient The broadest scope of where the variable 
   * should be inserted, usually an xsl:template or xsl:for-each.
   * @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 createLocalPseudoVarDecl(QName uniquePseudoVarName, ElemTemplateElement psuedoVarRecipient, LocPathIterator lpi) throws org.w3c.dom.DOMException {
    ElemVariable psuedoVar = new ElemVariablePsuedo();
    XPath xpath = new XPath(lpi);
    psuedoVar.setSelect(xpath);
    psuedoVar.setName(uniquePseudoVarName);
    ElemVariable var = addVarDeclToElem(psuedoVarRecipient, lpi, psuedoVar);
    lpi.exprSetParent(var);
    return var;
}
Also used : XPath(org.apache.xpath.XPath)

Example 14 with XPath

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

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

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

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