Im working with XSLT and I’m outputting an HTML5 document. In my document I need a custom attribute.
I want to achieve this:
<div class="row" data-template>...</div>
So far I have managed to do it using CDATA, like so:
<xsl:text disable-output-escaping="yes"><![CDATA[<div class="row" data-template></div>]]></xsl:text>
Whilst this produces valid markup, the problem arises here when you need to work with the actual node, such as setting the ID dynamically. One of my cohorts suggested the following output:
<div class="row" data-template=""></div>
using:
<xsl:attribute name="data-template" />
Again this is valid, but looks somewhat ugly. Is there another method that allows me to output valid custom data attributes for HTML5?
You might want to live with the fact that
<xsl:attribute>produces a name-value pair attribute but make it semantically sensible as a boolean value.should produce
which looks a little less ugly.