public static Value create(com.icl.saxon.expr.Value v, Context context) throws XPathException {
      if (v instanceof NodeSetValue) {
        if (v instanceof FragmentValue) {
          final FragmentValue value = (FragmentValue)v;
          final boolean b = value.isGeneralUseAllowed();
          try {
            if (!b) value.allowGeneralUse();

            final DocumentInfo node = value.getRootNode();
            final GeneralOutputter outputter = new GeneralOutputter(node.getNamePool());
            final StringWriter writer = new StringWriter();
            final Properties props = new Properties();
            props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            outputter.setOutputDestination(props, new StreamResult(writer));
            node.copy(outputter);

            return new MyValue(writer.toString(), v.getDataType());
          } catch (TransformerException e) {
            return new MyValue(v.asString(), v.getDataType());
          } finally {
            if (!b && fGeneralUseAllowed != null) {
              resetGeneralUseAllowed(value);
            }
          }
        } else if (v instanceof TextFragmentValue) {
          // this really is just a string
          return new MyValue(v.asString(), com.icl.saxon.expr.Value.STRING);
        }

        final List<Node> list = new ArrayList<>();
        final NodeEnumeration nodeEnumeration = ((NodeSetValue)v).enumerate();
        while (nodeEnumeration.hasMoreElements()) {
          final NodeInfo node = nodeEnumeration.nextElement();
          final String path = Navigator.getPath(node);
          final String id = node.getSystemId();
          if (id != null) {
            try {
              list.add(new Node(new URI(id.replaceAll(" ", "%20")).normalize().toASCIIString(), node.getLineNumber(), path,
                                node.getStringValue()));
            } catch (URISyntaxException e) {
              debug(e);
              list.add(new Node(id, node.getLineNumber(), path, node.getStringValue()));
            }
          } else {
            list.add(new Node(null, -1, path, node.getStringValue()));
          }
        }
        return new MyValue(new NodeSet(v.asString(), list), v.getDataType());
      } else if (v instanceof ObjectValue) {
        final Object o = ((ObjectValue)v).getObject();
        return new MyValue(o, o != null ? o.getClass().getName() : "null");
      } else if (v != null) {
        return new MyValue(v.evaluateAsString(context), v.getDataType());
      } else {
        return new MyValue("", "<uninitialized>");
      }
    }
public static Value create(com.icl.saxon.expr.Value v, Context context)