@Override public void verify() throws TransformException { ItemList targets = mod.nearest(NodeTarget.class).targets(); List<Node> references = mod.references(); ItemList records = mod.supplementQuery().all("sort-proxy"); assert targets.size() == references.size(); assert records.size() == references.size(); for (int i = 0; i < targets.size(); i++) { Node target = targets.get(i).node(); Node restoredProxy = references.get(i); ItemList items = query.runOn(mod.scope(target.query())); if (items.size() != 1) throw new TransformException( "sort by corresponding node must select one node per target, but instead selected " + items.size() + ": " + items); Node proxy = items.get(0).node(); if (!restoredProxy.equals(proxy)) throw new TransformException("computed proxy changed"); if (!proxy .query() .single( "(count(preceding::*) + count(ancestor::*)) eq xs:integer($_1/@position)", records.get(i)) .booleanValue()) throw new SortingException("computed proxy moved"); } }
@Override public void restore() throws TransformException { List<Node> references = mod.references(); ItemList targets = mod.nearest(NodeTarget.class).targets(); proxies = new ArrayList<Pair<String, Node>>(references.size()); for (int i = 0; i < references.size(); i++) { proxies.add(Pair.of(targets.get(i).query().single("@xml:id").value(), references.get(i))); } }
@Override public void verify() throws TransformException { for (Pair<Node, List<Node>> pair : siblingsByTarget) { Node target = pair.first; List<Node> storedSiblings = pair.second; for (Node sibling : storedSiblings) { if (!target.query().single(".. is $_1/..", sibling).booleanValue()) throw new TransformException( "previously selected node is no longer a sibling: " + sibling); } List<Node> actualSiblings = query.runOn(mod.scope(target.query().single("..").query())).nodes().asList(); if (!actualSiblings.equals(storedSiblings)) throw new TransformException( "sibling list changed for target " + target.query().single("@xml:id").value()); // No need to check sibling order, since any change in the node's document will trigger a // sort. } }