in src/main/java/org/apache/sling/scripting/sightly/impl/plugin/AttributePlugin.java [300:330]
private void writeAttribute(PushStream stream, String attrNameVar, String attrContentVar) {
String escapedContent = compilerContext.generateVariable("attrContentEscaped");
String shouldDisplayAttribute = compilerContext.generateVariable("shouldDisplayAttr");
stream.write(new VariableBinding.Start(
escapedContent, escapedExpression(new Identifier(attrContentVar), new Identifier(attrNameVar))));
stream.write(new VariableBinding.Start(
shouldDisplayAttribute,
new BinaryOperation(
BinaryOperator.AND,
new BinaryOperation(
BinaryOperator.AND,
new BinaryOperation(
BinaryOperator.NEQ, NullLiteral.INSTANCE, new Identifier(escapedContent)),
new BinaryOperation(
BinaryOperator.NEQ, StringConstant.EMPTY, new Identifier(escapedContent))),
new BinaryOperation(
BinaryOperator.AND,
new BinaryOperation(
BinaryOperator.NEQ, StringConstant.EMPTY, new Identifier(attrContentVar)),
new BinaryOperation(
BinaryOperator.NEQ,
BooleanConstant.FALSE,
new Identifier(attrContentVar))))));
stream.write(new Conditional.Start(shouldDisplayAttribute, true));
stream.write(new OutText(" ")); // write("attrName");
writeAttributeName(stream, attrNameVar);
writeAttributeValue(stream, escapedContent, attrContentVar);
stream.write(Conditional.END);
stream.write(VariableBinding.END);
stream.write(VariableBinding.END);
}