Skip to content

Commit

Permalink
Refactor XPath compilation to fix issue #143.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndw committed Apr 25, 2014
1 parent a85cda6 commit eb361d9
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/com/xmlcalabash/library/SplitSequence.java
Expand Up @@ -92,6 +92,21 @@ public void run() throws SaxonApiException {
DocumentSequenceIterator xsi = new DocumentSequenceIterator(); // See below
xsi.setLast(count);

XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler();
xcomp.setBaseURI(step.getNode().getBaseURI());

for (String prefix : test.getNamespaceBindings().keySet()) {
xcomp.declareNamespace(prefix, test.getNamespaceBindings().get(prefix));
}

XPathExecutable xexec = xcomp.compile(test.getString());

// From Michael Kay: http://markmail.org/message/vkb2vaq2miylgndu
//
// Underneath the s9api XPathExecutable is a net.sf.saxon.sxpath.XPathExpression.

XPathExpression xexpr = xexec.getUnderlyingExpression();

int pos = 0;
while (source.moreDocuments()) {
XdmNode doc = source.read();
Expand All @@ -100,21 +115,6 @@ public void run() throws SaxonApiException {
Item item = null;

try {
XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler();
xcomp.setBaseURI(step.getNode().getBaseURI());

for (String prefix : test.getNamespaceBindings().keySet()) {
xcomp.declareNamespace(prefix, test.getNamespaceBindings().get(prefix));
}

XPathExecutable xexec = xcomp.compile(test.getString());

// From Michael Kay: http://markmail.org/message/vkb2vaq2miylgndu
//
// Underneath the s9api XPathExecutable is a net.sf.saxon.sxpath.XPathExpression.

XPathExpression xexpr = xexec.getUnderlyingExpression();

// Call createDynamicContext() on this to get an XPathDynamicContext object;

XPathDynamicContext xdc = xexpr.createDynamicContext(doc.getUnderlyingNode());
Expand Down

0 comments on commit eb361d9

Please sign in to comment.