diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c
index 77adca38..f637d184 100644
--- a/lib/src/clixon_xml_sort.c
+++ b/lib/src/clixon_xml_sort.c
@@ -221,9 +221,8 @@ xml_cmp(const void* arg1,
cxobj *x1b;
cxobj *x2b;
- if (x1==NULL || x2==NULL){
+ if (x1==NULL || x2==NULL)
goto done; /* shouldnt happen */
- }
y1 = xml_spec(x1);
y2 = xml_spec(x2);
nr1 = xml_enumerate_get(x1);
@@ -232,7 +231,7 @@ xml_cmp(const void* arg1,
equal = nr1-nr2;
goto done;
}
- if (y1 != y2){
+ if (y1 != y2){
yi1 = yang_order(y1);
yi2 = yang_order(y2);
if ((equal = yi1-yi2) != 0)
@@ -289,6 +288,7 @@ xml_cmp(const void* arg1,
break;
}
done:
+ clicon_debug(2, "%s %s %s %d", __FUNCTION__, xml_name(x1), xml_name(x2), equal);
return equal;
}
diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c
index 962e3800..f4d93e15 100644
--- a/lib/src/clixon_yang.c
+++ b/lib/src/clixon_yang.c
@@ -663,8 +663,11 @@ yang_choice(yang_stmt *y)
}
/*! Find matching y in yp:s children, return 0 and index or -1 if not found.
- * @retval 0 not found
- * @retval 1 found
+ * @param[in] yp Parent
+ * @param[in] y Yang datanode to find
+ * @param[out] index Index of y in yp:s list of children
+ * @retval 0 not found (must be datanode)
+ * @retval 1 found
*/
static int
order1(yang_node *yp,
@@ -686,29 +689,41 @@ order1(yang_node *yp,
}
/*! Return order of yang statement y in parents child vector
- * @retval i Order of child with specified argument
- * @retval -1 Not found
+ * @param[in] y Find position of this data-node
+ * @param[out] index Index of y in yp:s list of children
+ * @retval >=0 Order of child with specified argument
+ * @retval -1 Not found
+ * @note special handling if y is child of (sub)module
*/
int
yang_order(yang_stmt *y)
{
yang_node *yp;
yang_node *ypp;
- yang_node *yn;
+ yang_stmt *ym;
int i;
int j=0;
+ int tot = 0;
yp = y->ys_parent;
+ /* XML nodes with yang specs that are children of modules are special -
+ * In clixon, they are seen as an "implicit" container where the XML can come from different
+ * modules. The order must therefore be global among yang top-symbols to be unique.
+ * Example:
+ * The order of x and y cannot be compared within a single yang module since they belong to different
+ */
if (yp->yn_keyword == Y_MODULE || yp->yn_keyword == Y_SUBMODULE){
- ypp = yp->yn_parent;
- for (i=0; iyn_len; i++){
- yn = (yang_node*)ypp->yn_stmt[i];
- if (order1(yn, y, &j) == 1)
- return j;
+ ypp = yp->yn_parent; /* yang spec */
+ for (i=0; iyn_len; i++){ /* iterate through other modules */
+ ym = ypp->yn_stmt[i];
+ if (yp == ym)
+ break;
+ tot += ym->ys_len;
}
}
- order1(yp, y, &j);
- return j;
+ if (order1(yp, y, &j) == 1)
+ return tot + j;
+ return -1;
}
/*! Reset flag in complete tree, arg contains flag */
diff --git a/test/test_upgrade.sh b/test/test_upgrade.sh
index 8029cabb..b397f6c6 100755
--- a/test/test_upgrade.sh
+++ b/test/test_upgrade.sh
@@ -24,8 +24,6 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example
-
-
cfg=$dir/conf_yang.xml
fyangA0=$dir/A@0814-01-28.yang
fyangA1=$dir/A@2019-01-01.yang