code: public static String removeLastComplexXpathElement(String path) {
  
          int pos = path.lastIndexOf('/');
          if (pos < 0) {
              return path;
          }
          // count ' chars
          int p = pos;
          int count = -1;
          while (p > 0) {
              count++;
              p = path.indexOf("\'", p + 1);
          }
          String parentPath = path.substring(0, pos);
          if ((count % 2) == 0) {
              // if substring is complete
              return parentPath;
          }
          // if not complete
          p = parentPath.lastIndexOf("'");
          if (p >= 0) {
              // complete it if possible
              return removeLastComplexXpathElement(parentPath.substring(0, p));
          }
          return parentPath;
      }
docs: Removes the last complex Xpath element from the path.<p>
  
  The same as {@link #removeLastXpathElement(String)} both it works with more complex xpaths.
  
  <p>Example:<br>
  <code>system/backup[@date='23/10/2003']/resource[path='/a/b/c']</code> becomes <code>system/backup[@date='23/10/2003']</code><p>
  
  @param path the Xpath to remove the last element from
  
  @return the path with the last element removed