code: protected Pair<String, String> createPrefix(Map<String, String> nss, String currentNamespace, String currentPrefix) {
          if (currentNamespace == null) {
              return Pair.of(null, null);
          }
          String pf = nss.get(currentNamespace);
          
          if (pf != null) {
              return Pair.of(pf, null);
          }
          int nsc = 0;
          pf = currentPrefix;
          if (pf == null) {
              pf = "ns" + nsc;
          }
          outer:
          while (!Thread.currentThread().isInterrupted()) {
              for (Map.Entry<String, String> e : nss.entrySet()) {
                  if (Objects.equals(e.getValue(), pf)) {
                      nsc++;
                      pf = "ns" + nsc;
                      continue outer;
                  }
              }
              // if we get here, the prefix is not yet used
              break;
          }
          
          nss.put(currentNamespace, pf);
          
          StringBuilder xmlns = new StringBuilder();
          xmlns.append(" xmlns").append(pf != null && pf.length() > 0 ? ":" : "")
          .append(pf != null && pf.length() > 0 ? pf : "").append("='")
          .append(sanitize(currentNamespace)).append("'");
          ;
          
          return Pair.of(pf, xmlns.toString());
      }
docs: Generate a new prefix if the current is empty or already exists but with a different URI.
  @param nss the namespace to prefix cache.
  @param currentNamespace the current namespace
  @param currentPrefix the current prefix
  @return a pair of the derived prefix and (the xmlns declaration if needed, null otherwise)