code: public static XdmNode getContextFromLog(
              net.sf.saxon.s9api.DocumentBuilder builder, Document log)
              throws Exception {
          Element starttest = (Element) log.getElementsByTagName("starttest")
                  .item(0);
          NodeList nl = starttest.getElementsByTagName("context");
          if (nl == null || nl.getLength() == 0) {
              return null;
          } else {
              Element context = (Element) nl.item(0);
              Element value = (Element) context.getElementsByTagName("value")
                      .item(0);
              nl = value.getChildNodes();
              for (int i = 0; i < nl.getLength(); i++) {
                  Node n = nl.item(i);
                  if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
                      String s = DomUtils.serializeNode(value);
                      XdmNode xn = builder.build(new StreamSource(
                              new CharArrayReader(s.toCharArray())));
                      return (XdmNode) xn.axisIterator(Axis.ATTRIBUTE).next();
                  } else if (n.getNodeType() == Node.ELEMENT_NODE) {
                      Document doc = DomUtils.createDocument(n);
                      return builder.build(new DOMSource(doc));
                  }
              }
          }
          return null;
      }
docs: Returns the context node for a test from its log document