void writeformattedItem(XdmItem item, ProcessContext context, OutputStream out) throws TransformerFactoryConfigurationError, TransformerException, IOException { if (item.isAtomicValue()) { out.write(item.getStringValue().getBytes(UTF8)); } else { // item is an XdmNode XdmNode node = (XdmNode) item; switch (node.getNodeKind()) { case DOCUMENT: case ELEMENT: Transformer transformer = TransformerFactory.newInstance().newTransformer(); final Properties props = getTransformerProperties(context); transformer.setOutputProperties(props); transformer.transform(node.asSource(), new StreamResult(out)); break; default: out.write(node.getStringValue().getBytes(UTF8)); } } }
public static XdmNode getDocumentElement(XdmNode doc) { if (doc.getNodeKind() == XdmNodeKind.DOCUMENT) { for (XdmNode node : new AxisNodes(doc, Axis.CHILD, AxisNodes.SIGNIFICANT)) { if (node.getNodeKind() == XdmNodeKind.ELEMENT) { return node; // There can be only one, this is an XML document } } return null; } else { return doc; } }
public static XdmNode getDocumentElement(XdmNode doc) { if (doc.getNodeKind() == XdmNodeKind.DOCUMENT) { for (XdmNode node : new AxisNodes(doc, Axis.CHILD, AxisNodes.SIGNIFICANT)) { if (node.getNodeKind() == XdmNodeKind.ELEMENT) { return node; // There can be only one, this is an XML document } } return null; } else { return doc; } }
public static void assertDocument(XdmNode doc) { if (doc.getNodeKind() == XdmNodeKind.DOCUMENT) { S9apiUtils.assertDocumentContent(doc.axisIterator(Axis.CHILD)); } else if (doc.getNodeKind() == XdmNodeKind.ELEMENT) { // this is ok } else { throw XProcException.dynamicError(1, "Document root cannot be " + doc.getNodeKind()); } }
static boolean shouldPropagateBreak(XdmNode element, BreakPosition.Side side) { for (XdmItem i : SaxonHelper.axisIterable(element, side == BreakPosition.Side.BEFORE ? Axis.PRECEDING_SIBLING : Axis.FOLLOWING_SIBLING)) { XdmNode n = (XdmNode)i; if (n.getNodeKind() == XdmNodeKind.ELEMENT) return false; else if (n.getNodeKind() == XdmNodeKind.TEXT && !isWhiteSpaceNode(n)) return false; } return true; }
public static void assertDocument(XdmNode doc) { if (doc.getNodeKind() == XdmNodeKind.DOCUMENT) { S9apiUtils.assertDocumentContent(doc.axisIterator(Axis.CHILD)); } else if (doc.getNodeKind() == XdmNodeKind.ELEMENT) { // this is ok } else { throw XProcException.dynamicError(1, "Document root cannot be " + doc.getNodeKind()); } }
private String getLang(XdmNode node) { String lang = null; while (lang == null && node.getNodeKind() == XdmNodeKind.ELEMENT) { lang = node.getAttributeValue(XProcConstants.xml_lang); node = node.getParent(); } return lang; } }
private String extractText(XdmNode doc) { String content = ""; XdmSequenceIterator iter = doc.axisIterator(Axis.CHILD); while (iter.hasNext()) { XdmNode child = (XdmNode) iter.next(); if (child.getNodeKind() == XdmNodeKind.ELEMENT || child.getNodeKind() == XdmNodeKind.TEXT) { content += child.getStringValue(); } } return content; }
private static void dumpTreeNode(XdmNode node, String indent) { if (node.getNodeKind() == XdmNodeKind.ELEMENT) { System.err.println(indent + node.getNodeName() + ": " + node.getBaseURI()); XdmSequenceIterator iter = node.axisIterator(Axis.CHILD); while (iter.hasNext()) { XdmNode child = (XdmNode) iter.next(); dumpTreeNode(child, indent + " "); } } else if (node.getNodeKind() == XdmNodeKind.TEXT) { System.err.println(indent + "text: ..."); } }
private static void dumpTreeNode(XdmNode node, String indent) { if (node.getNodeKind() == XdmNodeKind.ELEMENT) { System.err.println(indent + node.getNodeName() + ": " + node.getBaseURI()); XdmSequenceIterator iter = node.axisIterator(Axis.CHILD); while (iter.hasNext()) { XdmNode child = (XdmNode) iter.next(); dumpTreeNode(child, indent + " "); } } else if (node.getNodeKind() == XdmNodeKind.TEXT) { System.err.println(indent + "text: ..."); } }
@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)); } };
@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)); } };
XdmValue matchList = xPathSelector.evaluate(); XdmItem firstItem = matchList.itemAt(0); if (firstItem instanceof XdmNode) { XdmNode xdmNode = (XdmNode) firstItem; XdmNodeKind nodeKind = xdmNode.getNodeKind(); if (nodeKind == XdmNodeKind.ELEMENT) { return xdmNode.toString(); } } return firstItem.getStringValue();
public DeclareStep usePipeline(XdmNode node) { if (node.getNodeKind() == XdmNodeKind.DOCUMENT) { node = S9apiUtils.getDocumentElement(node); } DeclareStep decl = readDeclareStep(node); parseDeclareStepBodyPassTwo(decl); return decl; }
public DeclareStep usePipeline(XdmNode node) { if (node.getNodeKind() == XdmNodeKind.DOCUMENT) { node = S9apiUtils.getDocumentElement(node); } DeclareStep decl = readDeclareStep(node); parseDeclareStepBodyPassTwo(decl); return decl; }
private List<String> getMarkNames(XdmNode ssml){ XdmSequenceIterator iter = ssml.axisIterator(Axis.DESCENDANT); ArrayList<String> markNames = new ArrayList<String>(); while (iter.hasNext()){ XdmNode elt = (XdmNode) iter.next(); if (elt.getNodeKind() == XdmNodeKind.ELEMENT && "mark".equals(elt.getNodeName().getLocalName())){ markNames.add(elt.getAttributeValue(new QName("name"))); } } return markNames; }
Predicate<XdmNode> parseOption(RuntimeValue option) throws XPathException { if (!option.getString().equals("/*")) { XPathExpression matcher = SaxonHelper.compileExpression(option.getString(), option.getNamespaceBindings(), config); return n -> n.getNodeKind() == XdmNodeKind.ELEMENT && SaxonHelper.evaluateBoolean(matcher, n); } else return n -> false; }
private void computeSize(XdmNode node) { if (node.getNodeKind() == XdmNodeKind.TEXT) { mSize += CharMatcher.WHITESPACE.removeFrom(node.getStringValue()).length(); } else { XdmSequenceIterator iter = node.axisIterator(Axis.CHILD); while (iter.hasNext()) { computeSize((XdmNode) iter.next()); } } }
private String extractText(XdmNode doc) { String content = ""; XdmSequenceIterator iter = doc.axisIterator(Axis.CHILD); while (iter.hasNext()) { XdmNode child = (XdmNode) iter.next(); if (child.getNodeKind() != XdmNodeKind.TEXT) { throw XProcException.stepError(28); } content += child.getStringValue(); } return content; }
private String extractText(XdmNode doc) { String content = ""; XdmSequenceIterator iter = doc.axisIterator(Axis.CHILD); while (iter.hasNext()) { XdmNode child = (XdmNode) iter.next(); if (child.getNodeKind() != XdmNodeKind.TEXT) { throw XProcException.stepError(28); } content += child.getStringValue(); } return content; }