Note that an attribute (either literal or set via data-sly-attribute) whose value evaluates to the empty string will be removed in the final markup. The one exception to this rule is that a literal attribute set to a literal empty string will be preserved. For example,
For example,
<div class="${''}" data-sly-attribute.id="${''}"></div>
produces,
<div></div>
but,
<div class="" data-sly-attribute.id=""></div>
produces,
<div class=""></div>
So, try to set a literal value to the attribute if its null.