out BUGFIX empty container printing

Fixes #1647
diff --git a/src/out.c b/src/out.c
index 4590f26..4c72b10 100644
--- a/src/out.c
+++ b/src/out.c
@@ -49,6 +49,21 @@
                 return 0;
             }
         }
+    } else if ((node->flags & LYD_DEFAULT) && (node->schema->nodetype == LYS_CONTAINER)) {
+        if (options & LYD_PRINT_KEEPEMPTYCONT) {
+            /* explicit request to print */
+            return 1;
+        }
+
+        /* avoid empty default containers */
+        LYD_TREE_DFS_BEGIN(node, elem) {
+            if ((elem != node) && ly_should_print(elem, options)) {
+                return 1;
+            }
+            assert(elem->flags & LYD_DEFAULT);
+            LYD_TREE_DFS_END(node, elem)
+        }
+        return 0;
     } else if ((node->flags & LYD_DEFAULT) && !(options & LYD_PRINT_WD_MASK) && !(node->schema->flags & LYS_CONFIG_R)) {
         /* LYD_PRINT_WD_EXPLICIT, find out if this is some input/output */
         if (!(node->schema->flags & (LYS_IS_INPUT | LYS_IS_OUTPUT | LYS_IS_NOTIF)) && (node->schema->flags & LYS_CONFIG_W)) {
@@ -63,16 +78,6 @@
             }
         }
         return 0;
-    } else if ((node->flags & LYD_DEFAULT) && (node->schema->nodetype == LYS_CONTAINER) && !(options & LYD_PRINT_KEEPEMPTYCONT)) {
-        /* avoid empty default containers */
-        LYD_TREE_DFS_BEGIN(node, elem) {
-            if (elem->schema->nodetype != LYS_CONTAINER) {
-                return 1;
-            }
-            assert(elem->flags & LYD_DEFAULT);
-            LYD_TREE_DFS_END(node, elem)
-        }
-        return 0;
     }
 
     return 1;