tree data UPDATE additional support for opaque nodes
diff --git a/src/path.c b/src/path.c
index 548684a..516fe57 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1286,7 +1286,7 @@
 
 LY_ERR
 ly_path_eval_partial(const struct ly_path *path, const struct lyd_node *start, const struct lyxp_var *vars,
-        LY_ARRAY_COUNT_TYPE *path_idx, struct lyd_node **match)
+        ly_bool with_opaq, LY_ARRAY_COUNT_TYPE *path_idx, struct lyd_node **match)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct lyd_node *prev_node = NULL, *elem, *node = NULL, *target;
@@ -1338,7 +1338,13 @@
             }
         } else {
             /* we will use hashes to find one any/container/leaf instance */
-            lyd_find_sibling_val(start, path[u].node, NULL, 0, &node);
+            if (lyd_find_sibling_val(start, path[u].node, NULL, 0, &node) && with_opaq) {
+                if (!lyd_find_sibling_opaq_next(start, path[u].node->name, &node) &&
+                        (lyd_node_module(node) != path[u].node->module)) {
+                    /* non-matching opaque node */
+                    node = NULL;
+                }
+            }
         }
 
         if (!node) {
@@ -1390,7 +1396,7 @@
     LY_ERR ret;
     struct lyd_node *m;
 
-    ret = ly_path_eval_partial(path, start, vars, NULL, &m);
+    ret = ly_path_eval_partial(path, start, vars, 0, NULL, &m);
 
     if (ret == LY_SUCCESS) {
         /* last node was found */
diff --git a/src/path.h b/src/path.h
index aec1d36..9a9e342 100644
--- a/src/path.h
+++ b/src/path.h
@@ -211,6 +211,7 @@
  * @param[in] path Path structure specifying the target.
  * @param[in] start Starting node for relative paths, can be any for absolute paths.
  * @param[in] vars Array of defined variables to use in predicates, may be NULL.
+ * @param[in] with_opaq Whether to consider opaque nodes or not.
  * @param[out] path_idx Last found path segment index, can be NULL, set to 0 if not found.
  * @param[out] match Last found matching node, can be NULL, set to NULL if not found.
  * @return LY_ENOTFOUND if no nodes were found,
@@ -219,7 +220,7 @@
  * @return LY_ERR on another error.
  */
 LY_ERR ly_path_eval_partial(const struct ly_path *path, const struct lyd_node *start, const struct lyxp_var *vars,
-        LY_ARRAY_COUNT_TYPE *path_idx, struct lyd_node **match);
+        ly_bool with_opaq, LY_ARRAY_COUNT_TYPE *path_idx, struct lyd_node **match);
 
 /**
  * @brief Resolve the target defined by ly_path structure. Not supported for leafref!
diff --git a/src/tree_data.c b/src/tree_data.c
index 939bb6e..410eebd 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -3024,7 +3024,7 @@
     LY_CHECK_GOTO(ret, cleanup);
 
     /* evaluate the path */
-    ret = ly_path_eval_partial(lypath, ctx_node, NULL, NULL, match);
+    ret = ly_path_eval_partial(lypath, ctx_node, NULL, 0, NULL, match);
 
 cleanup:
     lyxp_expr_free(LYD_CTX(ctx_node), expr);
diff --git a/src/tree_data.h b/src/tree_data.h
index b3805a8..847f7d7 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -1468,6 +1468,7 @@
 #define LYD_NEW_PATH_CANON_VALUE 0x10   /**< Interpret the provided leaf/leaf-list @p value as being in the canonical
                                             (or JSON if no defined) ::LY_VALUE_CANON format. If it is not, it may lead
                                             to unexpected behavior. */
+#define LYD_NEW_PATH_WITH_OPAQ 0x20 /**< Consider opaque nodes normally when searching for existing nodes. */
 
 /** @} pathoptions */
 
diff --git a/src/tree_data_new.c b/src/tree_data_new.c
index d6a0b1f..e2e8fb8 100644
--- a/src/tree_data_new.c
+++ b/src/tree_data_new.c
@@ -1543,7 +1543,7 @@
 
     /* try to find any existing nodes in the path */
     if (parent) {
-        r = ly_path_eval_partial(p, parent, NULL, &path_idx, &node);
+        r = ly_path_eval_partial(p, parent, NULL, options & LYD_NEW_PATH_WITH_OPAQ, &path_idx, &node);
         if (r == LY_SUCCESS) {
             if (orig_count == LY_ARRAY_COUNT(p)) {
                 /* the node exists, are we supposed to update it or is it just a default? */