code: @Override
      public XPath createXPath(final Document... document) {
          final XPath xPath = createXPathFactory().newXPath();
          if ((document == null) || (document.length == 0) || (!NamespacePhilosophy.HEDONISTIC.equals(namespacePhilosophy))) {
              return xPath;
          }
          // For hedonistic name space philosophy we aspire a reasonable name space mapping.
          final Map<String, String> nameSpaceMapping = DOMHelper.getNamespaceMapping(document[0]);
          final NamespaceContext ctx = new NamespaceContext() {
              @Override
              public String getNamespaceURI(final String prefix) {
                  if (prefix == null) {
                      throw new IllegalArgumentException("null not allowed as prefix");
                  }
                  if (nameSpaceMapping.containsKey(prefix)) {
                      return nameSpaceMapping.get(prefix);
                  }
                  if (USER_DEFINED_MAPPING.containsKey(prefix)) {
                      return USER_DEFINED_MAPPING.get(prefix);
                  }
                  // Default is a global unique string uri to prevent xpath expression exeptions on
                  // nonexisting ns.
                  return NON_EXISTING_URL;
              }
  
              @Override
              public String getPrefix(final String uri) {
                  for (Entry<String, String> e : nameSpaceMapping.entrySet()) {
                      if (e.getValue().equals(uri)) {
                          return e.getKey();
                      }
                  }
                  for (Entry<String, String> e : USER_DEFINED_MAPPING.entrySet()) {
                      if (e.getValue().equals(uri)) {
                          return e.getKey();
                      }
                  }
                  return null;
              }
  
              @Override
              public Iterator<String> getPrefixes(final String val) {
                  return new UnionIterator<String>(nameSpaceMapping.keySet().iterator(), USER_DEFINED_MAPPING.keySet().iterator());
              }
          };
          xPath.setNamespaceContext(ctx);
          return xPath;
      }
docs: {@inheritDoc}