Class XPathEvalContext

java.lang.Object
org.libxmq.imp.xml.XPathEvalContext

public final class XPathEvalContext extends Object
An evaluation context, like XmlXPathContext in the C version (used by xslt): the document order index and the id tables of the trees seen so far are kept between evaluations, and variables and extension functions are resolved through callbacks. The trees must not change while the context knows them: call forget(XmlNode) before a tree is changed.
  • Constructor Details

    • XPathEvalContext

      public XPathEvalContext()
      A new context.
  • Method Details

    • setVariableLookup

      public void setVariableLookup(XPathEvalContext.VariableLookup lookup)
      Set the variable lookup.
      Parameters:
      lookup - The lookup, null for none.
    • setFunctionLookup

      public void setFunctionLookup(XPathEvalContext.FunctionLookup lookup)
      Set the extension function lookup.
      Parameters:
      lookup - The lookup, null for none.
    • forget

      public void forget(XmlNode root)
      Forget the indexes of the tree with this root, before it is changed.
      Parameters:
      root - The root of the tree.
    • eval

      public XPathResult eval(XPath comp, XmlNode node, long position, long size) throws XPathException
      Evaluate a compiled expression.
      Parameters:
      comp - The expression.
      node - The context node.
      position - The context position, -1 if unknown (then position() is an error).
      size - The context size, -1 if unknown (then last() is an error).
      Returns:
      The value.
      Throws:
      XPathException - On an error.
    • contextNode

      public XmlNode contextNode()
      The context node of the evaluation calling the function.
      Returns:
      The node or null.
    • position

      public long position()
      The context position of the evaluation calling the function.
      Returns:
      The position or -1.
    • size

      public long size()
      The context size of the evaluation calling the function.
      Returns:
      The size or -1.
    • lookupNamespace

      public String lookupNamespace(String prefix)
      Look up a prefix in the namespaces of the expression calling the function.
      Parameters:
      prefix - The prefix.
      Returns:
      The uri or null.
    • getId

      public XmlNode getId(XmlNode node, String id)
      The element with the id in the document of node.
      Parameters:
      node - A node of the document.
      id - The id.
      Returns:
      The element or null.
    • setError

      public void setError(int code)
      Set the error of a failing extension function (it returns null).
      Parameters:
      code - The XPathException code.
    • setErrorQuiet

      public void setErrorQuiet(int code)
      Set the error of a failing extension function that reported its own message.
      Parameters:
      code - The XPathException code.
    • sort

      public void sort(XPathResult r)
      Remove duplicates from a node set and sort it in document order, like a union.
      Parameters:
      r - The node set.