Permalink
Browse files

Only one xi:fallback is allowed, even if the include succeeds

  • Loading branch information...
ndw committed Apr 15, 2016
1 parent aced79b commit 206d518d116e7b9f0657c239ca1a50a40ba28850
Showing with 13 additions and 9 deletions.
  1. +13 −9 src/main/java/com/xmlcalabash/library/XInclude.java
@@ -185,6 +185,16 @@ public boolean processStartElement(XdmNode node) throws SaxonApiException {
// FIXME: Take accept and accept_language into consideration when retrieving resources
XdmNode fallback = null;
for (XdmNode child : new AxisNodes(node, Axis.CHILD, AxisNodes.SIGNIFICANT)) {
if (child.getNodeKind() == XdmNodeKind.ELEMENT && xi_fallback.equals(child.getNodeName())) {
if (fallback != null) {
throw new XProcException(step.getNode(), "XInclude element must contain at most one xi:fallback element.");
}
fallback = child;
}
}
XPointer xpointer = null;
XdmNode subdoc = null;
@@ -417,21 +427,15 @@ public XdmNode readXML(String href, String base) {
public void fallback(XdmNode node, String href) {
logger.trace(MessageFormatter.nodeMessage(node, "fallback: " + node.getNodeName()));
boolean valid = true;
// N.B. We've already tested for at most one xi:fallback element
XdmNode fallback = null;
for (XdmNode child : new AxisNodes(node, Axis.CHILD, AxisNodes.SIGNIFICANT)) {
if (child.getNodeKind() == XdmNodeKind.ELEMENT) {
valid = valid && xi_fallback.equals(child.getNodeName()) && (fallback == null);
if (child.getNodeKind() == XdmNodeKind.ELEMENT && xi_fallback.equals(child.getNodeName())) {
fallback = child;
} else {
valid = false;
}
}
if (!valid) {
throw new XProcException(step.getNode(), "XInclude element must contain exactly one xi:fallback element.");
}
if (fallback == null) {
if (mostRecentException != null) {
throw new XProcException(step.getNode(), "XInclude resource error (" + href + ") and no fallback provided.", mostRecentException);

0 comments on commit 206d518

Please sign in to comment.