schema tree BUGFIX input/output nodes should not be skipped
diff --git a/doc/transition.dox b/doc/transition.dox
index ec84904..966e26e 100644
--- a/doc/transition.dox
+++ b/doc/transition.dox
@@ -183,10 +183,10 @@
  * lys_is_key()                 | ::lysc_is_key()                 | Renamed to connect with the compiled schema tree.
  * -                            | ::lysc_is_userordered()         | Added functionality to simplify the examination of generic compiled schema nodes.
  * -                            | ::lysc_is_np_cont()             | ^
- * -                            | ::lysc_node_children()          | ^
+ * -                            | ::lysc_node_child()             | ^
  * -                            | ::lysc_node_actions()           | ^
  * -                            | ::lysc_node_notifs()            | ^
- * -                            | ::lysp_node_children()          | Added functionality to simplify the examination of generic parsed schema nodes.
+ * -                            | ::lysp_node_child()             | Added functionality to simplify the examination of generic parsed schema nodes.
  * -                            | ::lysp_node_actions()           | ^
  * -                            | ::lysp_node_notifs()            | ^
  * -                            | ::lysp_node_groupings()         | ^
diff --git a/src/path.c b/src/path.c
index b62ce58..2d1e868 100644
--- a/src/path.c
+++ b/src/path.c
@@ -558,7 +558,7 @@
 
         /* check that all keys were set */
         key_count = 0;
-        for (key = lysc_node_children(ctx_node, 0); key && (key->flags & LYS_KEY); key = key->next) {
+        for (key = lysc_node_child(ctx_node); key && (key->flags & LYS_KEY); key = key->next) {
             ++key_count;
         }
         if (LY_ARRAY_COUNT(*predicates) != key_count) {
diff --git a/src/printer_yang.c b/src/printer_yang.c
index a6c118d..5d58e71 100644
--- a/src/printer_yang.c
+++ b/src/printer_yang.c
@@ -1054,7 +1054,7 @@
     }
     ypr_open(ctx->out, flag);
 
-    ly_print_(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
+    ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
     LEVEL++;
 
     yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
@@ -1077,7 +1077,7 @@
 }
 
 static void
-yprc_inout(struct ypr_ctx *ctx, const struct lysc_node_action *action, const struct lysc_node_action_inout *inout, ly_bool *flag)
+yprc_inout(struct ypr_ctx *ctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct lysc_node *data;
@@ -1088,10 +1088,10 @@
     }
     ypr_open(ctx->out, flag);
 
-    ly_print_(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
+    ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
     LEVEL++;
 
-    yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input.exts : action->output.exts, NULL, 0);
+    yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
     LY_ARRAY_FOR(inout->musts, u) {
         yprc_must(ctx, &inout->musts[u], NULL);
     }
@@ -1222,8 +1222,8 @@
     ypr_description(ctx, action->dsc, action->exts, &flag);
     ypr_reference(ctx, action->ref, action->exts, &flag);
 
-    yprc_inout(ctx, action, &action->input, &flag);
-    yprc_inout(ctx, action, &action->output, &flag);
+    yprc_inout(ctx, &action->input, &flag);
+    yprc_inout(ctx, &action->output, &flag);
 
     LEVEL--;
     ypr_close(ctx, flag);
diff --git a/src/printer_yin.c b/src/printer_yin.c
index 6107c42..3db8433 100644
--- a/src/printer_yin.c
+++ b/src/printer_yin.c
@@ -567,7 +567,7 @@
     }
     ypr_close_parent(ctx, flag);
 
-    ypr_open(ctx, (inout->nodetype == LYS_INPUT ? "input" : "output"), NULL, NULL, *flag);
+    ypr_open(ctx, inout->name, NULL, NULL, *flag);
     LEVEL++;
 
     yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
@@ -586,7 +586,7 @@
     }
 
     LEVEL--;
-    ypr_close(ctx, (inout->nodetype == LYS_INPUT ? "input" : "output"), 1);
+    ypr_close(ctx, inout->name, 1);
 }
 
 static void
diff --git a/src/schema_compile_amend.c b/src/schema_compile_amend.c
index 5073e17..1f0e05a 100644
--- a/src/schema_compile_amend.c
+++ b/src/schema_compile_amend.c
@@ -1362,22 +1362,13 @@
 lysp_schema_nodeid_match_node(const struct lysc_node **node, const struct lys_module *mod, const char *name,
         size_t name_len)
 {
-    const char *node_name;
-
     /* compare with the module of the node */
     if ((*node)->module != mod) {
         return 0;
     }
 
     /* compare names */
-    if ((*node)->nodetype == LYS_INPUT) {
-        node_name = "input";
-    } else if ((*node)->nodetype == LYS_OUTPUT) {
-        node_name = "output";
-    } else {
-        node_name = (*node)->name;
-    }
-    if (ly_strncmp(node_name, name, name_len)) {
+    if (ly_strncmp((*node)->name, name, name_len)) {
         return 0;
     }
 
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index 95a91c6..d2c6d2f 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -2010,7 +2010,7 @@
     if (exclude->nodetype == LYS_CASE) {
         /* check restricted only to all the cases */
         assert(parent->nodetype == LYS_CHOICE);
-        LY_LIST_FOR(lysc_node_children(parent, 0), iter) {
+        LY_LIST_FOR(lysc_node_child(parent), iter) {
             if (CHECK_NODE(iter, exclude, name)) {
                 LOGVAL(ctx->ctx, LY_VCODE_DUPIDENT, name, "case");
                 return LY_EEXIST;
@@ -2092,16 +2092,23 @@
     node->parent = parent;
 
     if (parent) {
-        if (parent->nodetype & (LYS_ACTION | LYS_RPC)) {
-            assert(node->nodetype & (LYS_INPUT | LYS_OUTPUT));
-            /* inout nodes are part of the action and nothing more than setting the parent pointer is necessary */
+        if (node->nodetype == LYS_INPUT) {
+            assert(parent->nodetype & (LYS_ACTION | LYS_RPC));
+            /* input node is part of the action but link it with output */
+            node->next = &((struct lysc_node_action *)parent)->output.node;
+            node->prev = node->next;
+            return LY_SUCCESS;
+        } else if (node->nodetype == LYS_OUTPUT) {
+            /* output node is part of the action but link it with input */
+            node->next = NULL;
+            node->prev = &((struct lysc_node_action *)parent)->input.node;
             return LY_SUCCESS;
         } else if (node->nodetype == LYS_ACTION) {
             children = (struct lysc_node **)lysc_node_actions_p(parent);
         } else if (node->nodetype == LYS_NOTIF) {
             children = (struct lysc_node **)lysc_node_notifs_p(parent);
         } else {
-            children = lysc_node_children_p(parent, ctx->options);
+            children = lysc_node_child_p(parent);
         }
         assert(children);
 
@@ -3310,7 +3317,7 @@
         }
     } else { /* unset flag */
         for ( ; parent && parent->nodetype == LYS_CONTAINER && (parent->flags & LYS_MAND_TRUE); parent = parent->parent) {
-            for (iter = lysc_node_children(parent, 0); iter; iter = iter->next) {
+            for (iter = lysc_node_child(parent); iter; iter = iter->next) {
                 if (iter->flags & LYS_MAND_TRUE) {
                     /* there is another mandatory node */
                     return;
diff --git a/src/tree_data.c b/src/tree_data.c
index ca6b2e3..d429bdb 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -803,7 +803,7 @@
     va_start(ap, node);
 
     /* create and insert all the keys */
-    for (key_s = lysc_node_children(schema, 0); key_s && (key_s->flags & LYS_KEY); key_s = key_s->next) {
+    for (key_s = lysc_node_child(schema); key_s && (key_s->flags & LYS_KEY); key_s = key_s->next) {
         key_val = va_arg(ap, const char *);
 
         rc = lyd_create_term(key_s, key_val, key_val ? strlen(key_val) : 0, NULL, LY_PREF_JSON, NULL, LYD_HINT_DATA,
@@ -2500,7 +2500,7 @@
 
             if (!(node1->schema->flags & LYS_KEYLESS) && !(options & LYD_COMPARE_FULL_RECURSION)) {
                 /* lists with keys, their equivalence is based on their keys */
-                for (const struct lysc_node *key = lysc_node_children(node1->schema, 0);
+                for (const struct lysc_node *key = lysc_node_child(node1->schema);
                         key && (key->flags & LYS_KEY);
                         key = key->next) {
                     if (lyd_compare_single(iter1, iter2, options)) {
@@ -2704,7 +2704,7 @@
         } else if ((dup->schema->nodetype == LYS_LIST) && !(dup->schema->flags & LYS_KEYLESS)) {
             /* always duplicate keys of a list */
             child = orig->child;
-            for (const struct lysc_node *key = lysc_node_children(dup->schema, 0);
+            for (const struct lysc_node *key = lysc_node_child(dup->schema);
                     key && (key->flags & LYS_KEY);
                     key = key->next) {
                 if (!child) {
diff --git a/src/tree_schema.c b/src/tree_schema.c
index ba4af03..0e4d736 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -140,7 +140,7 @@
         /* get know where to start */
         if (parent) {
             /* schema subtree */
-            next = last = lysc_node_children(parent, (options & LYS_GETNEXT_OUTPUT) ? LYS_IS_OUTPUT : LYS_IS_INPUT);
+            next = last = lysc_node_child(parent);
         } else {
             /* top level data */
             next = last = module->data;
@@ -200,9 +200,9 @@
         goto repeat;
     case LYS_CONTAINER:
         if (!(next->flags & LYS_PRESENCE) && (options & LYS_GETNEXT_INTONPCONT)) {
-            if (lysc_node_children(next, 0)) {
+            if (lysc_node_child(next)) {
                 /* go into */
-                next = lysc_node_children(next, 0);
+                next = lysc_node_child(next);
             } else {
                 last = next;
                 next = next->next;
@@ -213,17 +213,35 @@
     case LYS_CHOICE:
         if (options & LYS_GETNEXT_WITHCHOICE) {
             break;
-        } else if ((options & LYS_GETNEXT_NOCHOICE) || !lysc_node_children(next, 0)) {
+        } else if ((options & LYS_GETNEXT_NOCHOICE) || !lysc_node_child(next)) {
             next = next->next;
         } else {
             if (options & LYS_GETNEXT_WITHCASE) {
-                next = lysc_node_children(next, 0);
+                next = lysc_node_child(next);
             } else {
                 /* go into */
                 lys_getnext_into_case(((struct lysc_node_choice *)next)->cases, &last, &next);
             }
         }
         goto repeat;
+    case LYS_INPUT:
+        if (options & LYS_GETNEXT_OUTPUT) {
+            /* skip */
+            next = next->next;
+        } else {
+            /* go into */
+            next = lysc_node_child(next);
+        }
+        goto repeat;
+    case LYS_OUTPUT:
+        if (!(options & LYS_GETNEXT_OUTPUT)) {
+            /* skip */
+            next = next->next;
+        } else {
+            /* go into */
+            next = lysc_node_child(next);
+        }
+        goto repeat;
     default:
         /* we should not be here */
         LOGINT(module ? module->mod->ctx : parent->module->ctx);
diff --git a/src/tree_schema.h b/src/tree_schema.h
index 2b0becb..410048f 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -105,11 +105,11 @@
  *
  * - ::lysc_has_when()
  *
- * - ::lysc_node_children()
+ * - ::lysc_node_child()
  * - ::lysc_node_actions()
  * - ::lysc_node_notifs()
  *
- * - ::lysp_node_children()
+ * - ::lysp_node_child()
  * - ::lysp_node_actions()
  * - ::lysp_node_notifs()
  * - ::lysp_node_groupings()
@@ -202,7 +202,7 @@
     if (LYSC_TREE_DFS_continue) { \
         (LYSC_TREE_DFS_next) = NULL; \
     } else { \
-        (LYSC_TREE_DFS_next) = (struct lysc_node *)lysc_node_children(ELEM, 0); \
+        (LYSC_TREE_DFS_next) = (struct lysc_node *)lysc_node_child(ELEM); \
     } \
     if (!(LYSC_TREE_DFS_next)) { \
         /* no children, try siblings */ \
@@ -222,15 +222,7 @@
         /* we are done, no next element to process */ \
         break; \
     } \
-    if ((ELEM)->nodetype == LYS_INPUT) { \
-        /* after input, get output */ \
-        (NEXT) = (struct lysc_node *)lysc_node_children((ELEM)->parent, LYS_IS_OUTPUT); \
-    } else if ((ELEM)->nodetype == LYS_OUTPUT) { \
-        /* no sibling of output */ \
-        (NEXT) = NULL; \
-    } else { \
-        (NEXT) = (ELEM)->next; \
-    }
+    (NEXT) = (ELEM)->next;
 
 /* *INDENT-ON* */
 
@@ -1619,9 +1611,8 @@
             uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
             struct lys_module *module; /**< module structure */
             struct lysc_node *parent;/**< parent node (NULL in case of top level node) */
-            struct lysc_node *next;  /**< NULL */
-            struct lysc_node *prev;  /**< pointer to the node itself - compatibility with ::lysc_node, input and output are
-                                          supposed to be a separated subtrees, so they do not link each other as siblings. */
+            struct lysc_node *next;  /**< next sibling node (output node for input, NULL for output) */
+            struct lysc_node *prev;  /**< pointer to the previous sibling node (input and output node pointing to each other) */
             const char *name;        /**< "input" or "output" */
             const char *dsc;         /**< ALWAYS NULL, compatibility member with ::lysc_node */
             const char *ref;         /**< ALWAYS NULL, compatibility member with ::lysc_node */
@@ -1993,7 +1984,7 @@
  * @param[in] node Node to examine.
  * @return The node's children linked list if any, NULL otherwise.
  */
-const struct lysp_node *lysp_node_children(const struct lysp_node *node);
+const struct lysp_node *lysp_node_child(const struct lysp_node *node);
 
 /**
  * @brief Get the actions/RPCs linked list of the given (compiled) schema node.
@@ -2014,12 +2005,14 @@
 /**
  * @brief Get the children linked list of the given (compiled) schema node.
  *
+ * Note that ::LYS_CHOICE has only ::LYS_CASE children.
+ * Also, ::LYS_RPC and ::LYS_ACTION have the first child ::LYS_INPUT, its sibling is ::LYS_OUTPUT.
+ *
  * @param[in] node Node to examine.
- * @param[in] flags Flag to distinguish input (LYS_IS_INPUT) and output (LYS_IS_OUTPUT) child in case of RPC/action node.
  * @return Children linked list if any,
  * @return NULL otherwise.
  */
-const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
+const struct lysc_node *lysc_node_child(const struct lysc_node *node);
 
 /**
  * @brief Get the must statements list if present in the @p node
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index 72357c9..9d46ffe 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -881,7 +881,7 @@
                 } else if (node->nodetype == LYS_NOTIF) {
                     iter = (struct lysc_node *)lysc_node_notifs(node->parent);
                 } else {
-                    iter = (struct lysc_node *)lysc_node_children(node->parent, node->flags & LYS_IS_OUTPUT);
+                    iter = (struct lysc_node *)lysc_node_child(node->parent);
                 }
                 LY_CHECK_ERR_RET(!iter, LOGINT(ctx), );
             } else if (node->nodetype == LYS_RPC) {
@@ -902,7 +902,7 @@
             } else if (node->nodetype == LYS_NOTIF) {
                 child_p = (struct lysc_node **)lysc_node_notifs_p(node->parent);
             } else {
-                child_p = lysc_node_children_p(node->parent, node->flags & LYS_IS_OUTPUT);
+                child_p = lysc_node_child_p(node->parent);
             }
         } else if (node->nodetype == LYS_RPC) {
             child_p = (struct lysc_node **)&node->module->compiled->rpcs;
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index 042798a..873ab83 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -1230,7 +1230,7 @@
 }
 
 struct lysp_node **
-lysp_node_children_p(struct lysp_node *node)
+lysp_node_child_p(struct lysp_node *node)
 {
     assert(node);
     switch (node->nodetype) {
@@ -1257,17 +1257,17 @@
 }
 
 API const struct lysp_node *
-lysp_node_children(const struct lysp_node *node)
+lysp_node_child(const struct lysp_node *node)
 {
-    struct lysp_node **children;
+    struct lysp_node **child;
 
     if (!node) {
         return NULL;
     }
 
-    children = lysp_node_children_p((struct lysp_node *)node);
-    if (children) {
-        return *children;
+    child = lysp_node_child_p((struct lysp_node *)node);
+    if (child) {
+        return *child;
     } else {
         return NULL;
     }
@@ -1415,9 +1415,10 @@
 }
 
 struct lysc_node **
-lysc_node_children_p(const struct lysc_node *node, uint16_t flags)
+lysc_node_child_p(const struct lysc_node *node)
 {
-    assert(node);
+    assert(node && !(node->nodetype & (LYS_RPC | LYS_ACTION)));
+
     switch (node->nodetype) {
     case LYS_CONTAINER:
         return &((struct lysc_node_container *)node)->child;
@@ -1427,14 +1428,6 @@
         return &((struct lysc_node_case *)node)->child;
     case LYS_LIST:
         return &((struct lysc_node_list *)node)->child;
-    case LYS_RPC:
-    case LYS_ACTION:
-        if (flags & LYS_IS_OUTPUT) {
-            return &((struct lysc_node_action *)node)->output.child;
-        } else {
-            /* LYS_IS_INPUT, but also the default case */
-            return &((struct lysc_node_action *)node)->input.child;
-        }
     case LYS_INPUT:
     case LYS_OUTPUT:
         return &((struct lysc_node_action_inout *)node)->child;
@@ -1446,29 +1439,24 @@
 }
 
 API const struct lysc_node *
-lysc_node_children(const struct lysc_node *node, uint16_t flags)
+lysc_node_child(const struct lysc_node *node)
 {
-    struct lysc_node **children;
+    struct lysc_node **child;
 
     if (!node) {
         return NULL;
     }
 
-    if ((node->nodetype == LYS_RPC) || (node->nodetype == LYS_ACTION)) {
-        if (flags & LYS_IN_OUTPUT) {
-            return (struct lysc_node *)&((struct lysc_node_action *)node)->output;
-        } else {
-            /* LYS_IN_INPUT, but also the default case */
-            return (struct lysc_node *)&((struct lysc_node_action *)node)->input;
-        }
+    if (node->nodetype & (LYS_RPC | LYS_ACTION)) {
+        return &((struct lysc_node_action *)node)->input.node;
     } else {
-        children = lysc_node_children_p(node, flags);
-        if (children) {
-            return *children;
-        } else {
-            return NULL;
+        child = lysc_node_child_p(node);
+        if (child) {
+            return *child;
         }
     }
+
+    return NULL;
 }
 
 struct lysc_must **
diff --git a/src/tree_schema_internal.h b/src/tree_schema_internal.h
index 4828e82..6759cb9 100644
--- a/src/tree_schema_internal.h
+++ b/src/tree_schema_internal.h
@@ -321,8 +321,8 @@
 
 /**
  * @brief Get address of a node's actions list if any.
- *
  * Decides the node's type and in case it has an actions list, returns its address.
+ *
  * @param[in] node Node to check.
  * @return Address of the node's actions member if any, NULL otherwise.
  */
@@ -330,8 +330,8 @@
 
 /**
  * @brief Get address of a node's notifications list if any.
- *
  * Decides the node's type and in case it has a notifications list, returns its address.
+ *
  * @param[in] node Node to check.
  * @return Address of the node's notifs member if any, NULL otherwise.
  */
@@ -339,16 +339,17 @@
 
 /**
  * @brief Get address of a node's child pointer if any.
- *
  * Decides the node's type and in case it has a children list, returns its address.
+ *
  * @param[in] node Node to check.
  * @return Address of the node's child member if any, NULL otherwise.
  */
-struct lysp_node **lysp_node_children_p(struct lysp_node *node);
+struct lysp_node **lysp_node_child_p(struct lysp_node *node);
 
 /**
  * @brief Get the address of the node's musts member, if any.
  * Decides the node's type and in case it has a musts member, returns its address.
+ *
  * @param[in] node Node to examine.
  * @return The address of the node's musts member if any, NULL otherwise.
  */
@@ -357,6 +358,7 @@
 /**
  * @brief Get the node's musts member, if any.
  * Decides the node's type and in case it has a musts member, returns its address.
+ *
  * @param[in] node Node to examine.
  * @return The node's musts member if any, NULL otherwise.
  */
@@ -365,6 +367,7 @@
 /**
  * @brief Get the address of the node's when member, if any.
  * Decides the node's type and in case it has a when, returns it.
+ *
  * @param[in] node Node to examine.
  * @return The address of the node's when member if any, NULL otherwise.
  */
@@ -373,6 +376,7 @@
 /**
  * @brief Get the node's when member, if any.
  * Decides the node's type and in case it has a when, returns it.
+ *
  * @param[in] node Node to examine.
  * @return The node's when member if any, NULL otherwise.
  */
@@ -380,18 +384,19 @@
 
 /**
  * @brief Get address of a node's child pointer if any.
- *
  * Decides the node's type and in case it has a children list, returns its address.
+ *
+ * Do not use for RPC and action nodes.
+ *
  * @param[in] node Node to check.
- * @param[in] flags Flag to distinguish input (LYS_IN_INPUT) and output (LYS_IN_OUTPUT) data in case of RPC/action node.
  * @return Address of the node's child member if any, NULL otherwise.
  */
-struct lysc_node **lysc_node_children_p(const struct lysc_node *node, uint16_t flags);
+struct lysc_node **lysc_node_child_p(const struct lysc_node *node);
 
 /**
  * @brief Get address of a node's notifs pointer if any.
- *
  * Decides the node's type and in case it has a notifs array, returns its address.
+ *
  * @param[in] node Node to check.
  * @return Address of the node's notifs member if any, NULL otherwise.
  */
@@ -399,8 +404,8 @@
 
 /**
  * @brief Get address of a node's actions pointer if any.
- *
  * Decides the node's type and in case it has a actions array, returns its address.
+ *
  * @param[in] node Node to check.
  * @return Address of the node's actions member if any, NULL otherwise.
  */
@@ -408,8 +413,8 @@
 
 /**
  * @brief Get address of a node's when member if any.
- *
  * Decides the node's type and in case it has a when member, returns its address.
+ *
  * @param[in] node Node to check.
  * @return Address of the node's when member if any, NULL otherwise.
  */
@@ -417,8 +422,8 @@
 
 /**
  * @brief Get address of a node's musts member if any.
- *
  * Decides the node's type and in case it has a musts member, returns its address.
+ *
  * @param[in] node Node to check.
  * @return Address of the node's musts member if any, NULL otherwise.
  */
@@ -438,6 +443,7 @@
 
 /**
  * @brief Get the covering schema module structure for the given parsed module structure.
+ *
  * @param[in] ctx libyang context to search.
  * @param[in] mod Parsed schema structure.
  * @return Corresponding lys_module structure for the given parsed schema structure.
diff --git a/src/xpath.c b/src/xpath.c
index b3302b2..8f10af7 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -5858,7 +5858,12 @@
 next_iter:
             /* TREE DFS NEXT ELEM */
             /* select element for the next run - children first */
-            next = lysc_node_children(elem, options & LYXP_SCNODE_OUTPUT ? LYS_IS_OUTPUT : LYS_IS_INPUT);
+            next = lysc_node_child(elem);
+            if (next && (next->nodetype == LYS_INPUT) && (options & LYXP_SCNODE_OUTPUT)) {
+                next = next->next;
+            } else if (next && (next->nodetype == LYS_OUTPUT) && !(options & LYXP_SCNODE_OUTPUT)) {
+                next = next->next;
+            }
             if (!next) {
 skip_children:
                 /* no children, so try siblings, but only if it's not the start,
@@ -6900,7 +6905,7 @@
         if (ctx_node->flags & LYS_KEYLESS) {
             return LY_EINVAL;
         }
-        for (key_count = 0, key = lysc_node_children(ctx_node, 0); key && (key->flags & LYS_KEY); key = key->next, ++key_count) {}
+        for (key_count = 0, key = lysc_node_child(ctx_node); key && (key->flags & LYS_KEY); key = key->next, ++key_count) {}
         assert(key_count);
 
         /* learn where the predicates end */
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 52cee54..6ce0c6d 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -1571,7 +1571,7 @@
             "container default-address{leaf ifname{type leafref{ path \"../../interface/name\";}}"
             "leaf address {type leafref{ path \"../../interface[  name = current()/../ifname ]/address/ip\";}}}}",
             LYS_IN_YANG, &mod));
-    type = ((struct lysc_node_leaf *)(*lysc_node_children_p(mod->compiled->data->prev, 0))->prev)->type;
+    type = ((struct lysc_node_leaf *)(*lysc_node_child_p(mod->compiled->data->prev))->prev)->type;
     assert_non_null(type);
     assert_int_equal(1, type->refcount);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
@@ -2086,9 +2086,9 @@
     assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; grouping grp {container g;}"
             "container top {uses grp {augment g {leaf x {type int8;}}}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
-    assert_non_null(child = lysc_node_children(mod->compiled->data, 0));
+    assert_non_null(child = lysc_node_child(mod->compiled->data));
     assert_string_equal("g", child->name);
-    assert_non_null(child = lysc_node_children(child, 0));
+    assert_non_null(child = lysc_node_child(child));
     assert_string_equal("x", child->name);
 
     assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {yang-version 1.1;namespace urn:e;prefix e; grouping grp {action g { description \"super g\";}}"
@@ -2144,7 +2144,7 @@
     assert_string_equal("g", child->name);
     cont = (const struct lysc_node_container *)child;
     assert_string_equal("dsc", cont->dsc);
-    assert_non_null(child = lysc_node_children(child, 0));
+    assert_non_null(child = lysc_node_child(child));
     assert_string_equal("x", child->name);
 
     /* invalid */
@@ -2374,11 +2374,11 @@
     assert_non_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "d"));
     assert_non_null(node = mod->compiled->data);
     assert_string_equal(node->name, "top");
-    assert_non_null(node = lysc_node_children(node, 0));
+    assert_non_null(node = lysc_node_child(node));
     assert_string_equal(node->name, "a");
     assert_non_null(node = node->next);
     assert_string_equal(node->name, "c");
-    assert_non_null(node = lysc_node_children(node, 0));
+    assert_non_null(node = lysc_node_child(node));
     assert_string_equal(node->name, "c");
     assert_non_null(node = node->next);
     assert_string_equal(node->name, "d");
@@ -2414,7 +2414,7 @@
     assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;grouping g {leaf a {type string;}}"
             "container c;"
             "augment /c {uses g;}}", LYS_IN_YANG, &mod));
-    assert_non_null(node = lysc_node_children(mod->compiled->data, 0));
+    assert_non_null(node = lysc_node_child(mod->compiled->data));
     assert_string_equal(node->name, "a");
 
     ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule gsub {belongs-to g {prefix g;}"
@@ -2537,7 +2537,7 @@
     assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "a")));
     assert_non_null(node = mod->compiled->data);
     assert_string_equal(node->name, "top");
-    assert_non_null(node = lysc_node_children(node, 0));
+    assert_non_null(node = lysc_node_child(node));
     assert_string_equal(node->name, "a");
     assert_non_null(node = node->next);
     assert_string_equal(node->name, "c");
@@ -2700,7 +2700,7 @@
     assert_non_null(node = node->next);
     assert_string_equal("top", node->name);
     assert_true(node->flags & LYS_CONFIG_R);
-    assert_non_null(node = lysc_node_children(node, 0));
+    assert_non_null(node = lysc_node_child(node));
     assert_string_equal("x", node->name);
     assert_true(node->flags & LYS_CONFIG_R);
     assert_non_null(node = node->next);
@@ -2717,7 +2717,7 @@
     assert_non_null(node = node->next);
     assert_string_equal("top", node->name);
     assert_true(node->flags & LYS_CONFIG_W);
-    assert_non_null(node = lysc_node_children(node, 0));
+    assert_non_null(node = lysc_node_child(node));
     assert_string_equal("x", node->name);
     assert_true(node->flags & LYS_CONFIG_W);
 
@@ -2729,11 +2729,11 @@
     assert_non_null(node = mod->compiled->data);
     assert_string_equal("a", node->name);
     assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_TRUE);
-    assert_true((lysc_node_children(node, 0)->flags & LYS_MAND_MASK) == LYS_MAND_TRUE);
+    assert_true((lysc_node_child(node)->flags & LYS_MAND_MASK) == LYS_MAND_TRUE);
     assert_non_null(node = node->next);
     assert_string_equal("b", node->name);
     assert_false(node->flags & LYS_MAND_MASK);     /* just unset on container */
-    assert_true((lysc_node_children(node, 0)->flags & LYS_MAND_MASK) == LYS_MAND_FALSE);
+    assert_true((lysc_node_child(node)->flags & LYS_MAND_MASK) == LYS_MAND_FALSE);
 
     assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module n {yang-version 1.1; namespace urn:n;prefix n;"
             "leaf a {default test; type string;}"
@@ -2877,7 +2877,7 @@
             "leaf al2 {type leafref {path \"/y:bl2\";}}"
             "}", LYS_IN_YANG, NULL));
     assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "y")));
-    assert_non_null(leaf = (struct lysc_node_leaf *)lysc_node_children(mod->compiled->data, 0));
+    assert_non_null(leaf = (struct lysc_node_leaf *)lysc_node_child(mod->compiled->data));
     assert_string_equal("l", leaf->name);
     assert_int_equal(LY_TYPE_LEAFREF, leaf->type->basetype);