use of org.apache.xpath.XPath in project robovm by robovm.
the class ElemNumber method getPreviousNode.
/**
* Get the previous node to be counted.
*
* @param xctxt The XPath runtime state for this.
* @param pos The current node
*
* @return the previous node to be counted.
*
* @throws TransformerException
*/
public int getPreviousNode(XPathContext xctxt, int pos) throws TransformerException {
XPath countMatchPattern = getCountMatchPattern(xctxt, pos);
DTM dtm = xctxt.getDTM(pos);
if (Constants.NUMBERLEVEL_ANY == m_level) {
XPath fromMatchPattern = m_fromMatchPattern;
// or the top of the tree is found.
while (DTM.NULL != pos) {
// Get the previous sibling, if there is no previous sibling,
// then count the parent, but if there is a previous sibling,
// dive down to the lowest right-hand (last) child of that sibling.
int next = dtm.getPreviousSibling(pos);
if (DTM.NULL == next) {
next = dtm.getParent(pos);
if ((DTM.NULL != next) && ((((null != fromMatchPattern) && (fromMatchPattern.getMatchScore(xctxt, next) != XPath.MATCH_SCORE_NONE))) || (dtm.getNodeType(next) == DTM.DOCUMENT_NODE))) {
// return null from function.
pos = DTM.NULL;
// from while loop
break;
}
} else {
// dive down to the lowest right child.
int child = next;
while (DTM.NULL != child) {
child = dtm.getLastChild(next);
if (DTM.NULL != child)
next = child;
}
}
pos = next;
if ((DTM.NULL != pos) && ((null == countMatchPattern) || (countMatchPattern.getMatchScore(xctxt, pos) != XPath.MATCH_SCORE_NONE))) {
break;
}
}
} else // NUMBERLEVEL_MULTI or NUMBERLEVEL_SINGLE
{
while (DTM.NULL != pos) {
pos = dtm.getPreviousSibling(pos);
if ((DTM.NULL != pos) && ((null == countMatchPattern) || (countMatchPattern.getMatchScore(xctxt, pos) != XPath.MATCH_SCORE_NONE))) {
break;
}
}
}
return pos;
}
use of org.apache.xpath.XPath in project robovm by robovm.
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!
}
use of org.apache.xpath.XPath in project robovm by robovm.
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;
}
use of org.apache.xpath.XPath in project robovm by robovm.
the class TemplateList method setTemplate.
/**
* Add a template to the table of named templates and/or the table of templates
* with match patterns. This routine should
* be called in decreasing order of precedence but it checks nonetheless.
*
* @param template
*/
public void setTemplate(ElemTemplate template) {
XPath matchXPath = template.getMatch();
if (null == template.getName() && null == matchXPath) {
template.error(XSLTErrorResources.ER_NEED_NAME_OR_MATCH_ATTRIB, new Object[] { "xsl:template" });
}
if (null != template.getName()) {
ElemTemplate existingTemplate = (ElemTemplate) m_namedTemplates.get(template.getName());
if (null == existingTemplate) {
m_namedTemplates.put(template.getName(), template);
} else {
int existingPrecedence = existingTemplate.getStylesheetComposed().getImportCountComposed();
int newPrecedence = template.getStylesheetComposed().getImportCountComposed();
if (newPrecedence > existingPrecedence) {
// This should never happen
m_namedTemplates.put(template.getName(), template);
} else if (newPrecedence == existingPrecedence)
template.error(XSLTErrorResources.ER_DUPLICATE_NAMED_TEMPLATE, new Object[] { template.getName() });
}
}
if (null != matchXPath) {
Expression matchExpr = matchXPath.getExpression();
if (matchExpr instanceof StepPattern) {
insertPatternInTable((StepPattern) matchExpr, template);
} else if (matchExpr instanceof UnionPattern) {
UnionPattern upat = (UnionPattern) matchExpr;
StepPattern[] pats = upat.getPatterns();
int n = pats.length;
for (int i = 0; i < n; i++) {
insertPatternInTable(pats[i], template);
}
} else {
// TODO: assert error
}
}
}
use of org.apache.xpath.XPath in project robovm by robovm.
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;
}
Aggregations