Added tests for formatting using element attribute or text and fixed bugs in library