本文整理汇总了Java中org.apache.xml.dtm.DTM.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java DTM.getParent方法的具体用法?Java DTM.getParent怎么用?Java DTM.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xml.dtm.DTM
的用法示例。
在下文中一共展示了DTM.getParent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldStripWhiteSpace
import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
* Get information about whether or not an element should strip whitespace.
* @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
*
* @param support The XPath runtime state.
* @param targetElement Element to check
*
* @return true if the whitespace should be stripped.
*
* @throws TransformerException
*/
public boolean shouldStripWhiteSpace(
XPathContext support, int targetElement) throws TransformerException
{
if (null != m_whiteSpaceInfoList)
{
while(DTM.NULL != targetElement)
{
DTM dtm = support.getDTM(targetElement);
WhiteSpaceInfo info = (WhiteSpaceInfo) m_whiteSpaceInfoList.getTemplate(support,
targetElement, null, false, dtm);
if(null != info)
return info.getShouldStripSpace();
int parent = dtm.getParent(targetElement);
if(DTM.NULL != parent && DTM.ELEMENT_NODE == dtm.getNodeType(parent))
targetElement = parent;
else
targetElement = DTM.NULL;
}
}
return false;
}
示例2: findAncestor
import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
* Given a 'from' pattern (ala xsl:number), a match pattern
* and a context, find the first ancestor that matches the
* pattern (including the context handed in).
*
* @param xctxt The XPath runtime state for this.
* @param fromMatchPattern The ancestor must match this pattern.
* @param countMatchPattern The ancestor must also match this pattern.
* @param context The node that "." expresses.
* @param namespaceContext The context in which namespaces in the
* queries are supposed to be expanded.
*
* @return the first ancestor that matches the given pattern
*
* @throws javax.xml.transform.TransformerException
*/
int findAncestor(
XPathContext xctxt, XPath fromMatchPattern, XPath countMatchPattern,
int context, ElemNumber namespaceContext)
throws javax.xml.transform.TransformerException
{
DTM dtm = xctxt.getDTM(context);
while (DTM.NULL != context)
{
if (null != fromMatchPattern)
{
if (fromMatchPattern.getMatchScore(xctxt, context)
!= XPath.MATCH_SCORE_NONE)
{
//context = null;
break;
}
}
if (null != countMatchPattern)
{
if (countMatchPattern.getMatchScore(xctxt, context)
!= XPath.MATCH_SCORE_NONE)
{
break;
}
}
context = dtm.getParent(context);
}
return context;
}
示例3: execute
import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
String lang = m_arg0.execute(xctxt).str();
int parent = xctxt.getCurrentNode();
boolean isLang = false;
DTM dtm = xctxt.getDTM(parent);
while (DTM.NULL != parent)
{
if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
{
int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");
if (DTM.NULL != langAttr)
{
String langVal = dtm.getNodeValue(langAttr);
// %OPT%
if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
{
int valLen = lang.length();
if ((langVal.length() == valLen)
|| (langVal.charAt(valLen) == '-'))
{
isLang = true;
}
}
break;
}
}
parent = dtm.getParent(parent);
}
return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
示例4: execute
import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
* The here function returns a node-set containing the attribute or
* processing instruction node or the parent element of the text node
* that directly bears the XPath expression. This expression results
* in an error if the containing XPath expression does not appear in the
* same XML document against which the XPath expression is being evaluated.
*
* @param xctxt
* @return the xobject
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws TransformerException {
Node xpathOwnerNode = (Node) xctxt.getOwnerObject();
if (xpathOwnerNode == null) {
return null;
}
int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);
int currentNode = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(currentNode);
int docContext = dtm.getDocument();
if (DTM.NULL == docContext) {
error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
}
{
// check whether currentNode and the node containing the XPath expression
// are in the same document
Document currentDoc =
XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);
if (currentDoc != xpathOwnerDoc) {
throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
}
}
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
NodeSetDTM nodeSet = nodes.mutableNodeset();
{
int hereNode = DTM.NULL;
switch (dtm.getNodeType(xpathOwnerNodeDTM)) {
case Node.ATTRIBUTE_NODE :
case Node.PROCESSING_INSTRUCTION_NODE : {
// returns a node-set containing the attribute / processing instruction node
hereNode = xpathOwnerNodeDTM;
nodeSet.addNode(hereNode);
break;
}
case Node.TEXT_NODE : {
// returns a node-set containing the parent element of the
// text node that directly bears the XPath expression
hereNode = dtm.getParent(xpathOwnerNodeDTM);
nodeSet.addNode(hereNode);
break;
}
default :
break;
}
}
/** $todo$ Do I have to do this detach() call? */
nodeSet.detach();
return nodes;
}
示例5: findPrecedingOrAncestorOrSelf
import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
* Given a 'from' pattern (ala xsl:number), a match pattern
* and a context, find the first ancestor that matches the
* pattern (including the context handed in).
* @param xctxt The XPath runtime state for this.
* @param fromMatchPattern The ancestor must match this pattern.
* @param countMatchPattern The ancestor must also match this pattern.
* @param context The node that "." expresses.
* @param namespaceContext The context in which namespaces in the
* queries are supposed to be expanded.
*
* @return the first preceding, ancestor or self node that
* matches the given pattern
*
* @throws javax.xml.transform.TransformerException
*/
private int findPrecedingOrAncestorOrSelf(
XPathContext xctxt, XPath fromMatchPattern, XPath countMatchPattern,
int context, ElemNumber namespaceContext)
throws javax.xml.transform.TransformerException
{
DTM dtm = xctxt.getDTM(context);
while (DTM.NULL != context)
{
if (null != fromMatchPattern)
{
if (fromMatchPattern.getMatchScore(xctxt, context)
!= XPath.MATCH_SCORE_NONE)
{
context = DTM.NULL;
break;
}
}
if (null != countMatchPattern)
{
if (countMatchPattern.getMatchScore(xctxt, context)
!= XPath.MATCH_SCORE_NONE)
{
break;
}
}
int prevSibling = dtm.getPreviousSibling(context);
if (DTM.NULL == prevSibling)
{
context = dtm.getParent(context);
}
else
{
// Now go down the chain of children of this sibling
context = dtm.getLastChild(prevSibling);
if (context == DTM.NULL)
context = prevSibling;
}
}
return context;
}
示例6: getMatchingAncestors
import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
* 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))
{
// The following if statement gives level="single" different
// behavior from level="multiple", which seems incorrect according
// to the XSLT spec. For now we are leaving this in to replicate
// the same behavior in XT, but, for all intents and purposes we
// think this is a bug, or there is something about level="single"
// 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;
}