/** * Set the initial context node for the transformation. * * @param node the initial context node, or null if there is to be no initial context node * @deprecated since 9.7.0.1 - use {@link #setGlobalContextItem} */ public void setInitialContextNode(XdmNode node) { if (primed) { throw new IllegalStateException("Stylesheet has already been evaluated"); } this.globalContextItem = node.getUnderlyingNode(); }
/** * The <code>equals()</code> relation between two XdmNode objects is true if they both represent the same * node. That is, it corresponds to the "is" operator in XPath. * * @param other the object to be compared * @return true if and only if the other object is an XdmNode instance representing the same node */ public boolean equals(Object other) { return other instanceof XdmNode && getUnderlyingNode().equals(((XdmNode) other).getUnderlyingNode()); }
/** * The hashcode is such that two XdmNode instances have the same hashCode if they represent the same * node. Note that the same node might be represented by different XdmNode objects, but these will * compare equal. * * @return a hashCode representing node identity */ public int hashCode() { return getUnderlyingNode().hashCode(); }
/** * Get the string value of a named attribute (in no namespace) of this element * * @param name the name of the required attribute, interpreted as a no-namespace name * @return null if this node is not an element, or if this element has no * attribute with the specified name. Otherwise return the string value of the * selected attribute node. * @since 9.9 */ public String attribute(String name) { return getUnderlyingNode().getAttributeValue("", name); }
/** * Get the column number of the node in a source document. For a document constructed using the document * builder, this is available only if the line numbering option was set when the document was built (and * then only for element nodes). If the column number is not available, the value -1 is returned. Column numbers * will typically be as reported by a SAX parser: this means that the column number for an element node is the * position of the closing ">" of the start tag. * * @return the column number of the node, or -1 if not available. */ public int getColumnNumber() { return getUnderlyingNode().getColumnNumber(); }
/** * Get the line number of the node in a source document. For a document constructed using the document * builder, this is available only if the line numbering option was set when the document was built (and * then only for element nodes). If the line number is not available, the value -1 is returned. Line numbers * will typically be as reported by a SAX parser: this means that the line number for an element node is the * line number containing the closing ">" of the start tag. * * @return the line number of the node, or -1 if not available. */ public int getLineNumber() { return getUnderlyingNode().getLineNumber(); }
private static Predicate<? super XdmNode> expandedNamePredicate(String ns, String local) { return item -> { NodeInfo node = item.getUnderlyingNode(); return node.getNodeKind() == Type.ELEMENT && node.getLocalPart().equals(local) && node.getURI().equals(ns); }; }
/** * Get the parent of this node * * @return the parent of this node (a document or element node), or null if this node has no parent. */ public XdmNode getParent() { NodeInfo p = getUnderlyingNode().getParent(); return p == null ? null : (XdmNode) XdmValue.wrap(p); }
@Override public Sequence<?> getPrimaryResult() throws XPathException { XdmNode node = destination.getXdmNode(); return node == null ? null : postProcess(baseOutputUri, node.getUnderlyingNode()); }
/** * Get the root of the tree containing this node (which may or may not be a document node) * * @return the root of the tree containing this node. Returns this node itself if it has no parent. * @since 9.9 */ public XdmNode getRoot() { NodeInfo p = getUnderlyingNode().getRoot(); return p == null ? null : (XdmNode) XdmValue.wrap(p); }
private static Predicate<? super XdmNode> localNamePredicate(String given) { if ("*".equals(given)) { return isElement(); } else { return item -> { NodeInfo node = item.getUnderlyingNode(); return node.getNodeKind() == Type.ELEMENT && node.getLocalPart().equals(given); }; } }
public static boolean evaluateBoolean(XPathExpression expression, XdmNode contextNode) { try { XPathDynamicContext context = expression.createDynamicContext(contextNode.getUnderlyingNode()); return expression.effectiveBooleanValue(context); } catch (XPathException e) { return false; } }
/** * Get the parent of this node * * @return the parent of this node (a document or element node), or null if this node has no parent. */ public XdmNode getParent() { NodeInfo p = getUnderlyingNode().getParent(); return p == null ? null : (XdmNode) XdmValue.wrap(p); }
/** * Get the root of the tree containing this node (which may or may not be a document node) * * @return the root of the tree containing this node. Returns this node itself if it has no parent. * @since 9.9 */ public XdmNode getRoot() { NodeInfo p = getUnderlyingNode().getRoot(); return p == null ? null : (XdmNode) XdmValue.wrap(p); }
@Override public Stream<XdmNode> apply(XdmItem item) { if (doc.getNodeKind() != XdmNodeKind.DOCUMENT) { throw new IllegalArgumentException("id() - argument is not a document node"); } NodeInfo target = doc.getUnderlyingNode().getTreeInfo().selectID(item.getStringValue(), true); return target==null ? Stream.empty() : Stream.of((XdmNode)XdmNode.wrap(target)); } };
/** * Get the string value of a named attribute of this element * * @param name the name of the required attribute * @return null if this node is not an element, or if this element has no * attribute with the specified name. Otherwise return the string value of the * selected attribute node. */ public String getAttributeValue(QName name) { NodeInfo node = getUnderlyingNode(); return node.getAttributeValue(name.getNamespaceURI(), name.getLocalName()); }
/** * Get an iterator over the nodes reachable from this node via a given axis. * * @param axis identifies which axis is to be navigated * @return an iterator over the nodes on the specified axis, starting from this node as the * context node. The nodes are returned in axis order, that is, in document order for a forwards * axis and in reverse document order for a reverse axis. */ public XdmSequenceIterator<XdmNode> axisIterator(Axis axis) { AxisIterator base = getUnderlyingNode().iterateAxis(axis.getAxisNumber()); return XdmSequenceIterator.ofNodes(base); }
private void serializeNodeToResult(XdmNode node, Result res) throws SaxonApiException { try { QueryResult.serialize(node.getUnderlyingNode(), res, getLocallyDefinedProperties()); } catch (XPathException e) { throw new SaxonApiException(e); } }
/** * Get an iterator over the nodes reachable from this node via a given axis. * * @param axis identifies which axis is to be navigated * @return an iterator over the nodes on the specified axis, starting from this node as the * context node. The nodes are returned in axis order, that is, in document order for a forwards * axis and in reverse document order for a reverse axis. */ public XdmSequenceIterator<XdmNode> axisIterator(Axis axis) { AxisIterator base = getUnderlyingNode().iterateAxis(axis.getAxisNumber()); return XdmSequenceIterator.ofNodes(base); }
public void addAttribute(XdmNode xdmattr, String newValue) { NodeInfo inode = xdmattr.getUnderlyingNode(); NodeName attrName = NameOfNode.makeName(inode); SimpleType typeCode = (SimpleType) inode.getSchemaType(); try { receiver.attribute(attrName, typeCode, newValue, VoidLocation.instance(), 0); } catch (XPathException e) { throw new XProcException(e); } }