开发者

Generate boolean custom attribute for HTML5 in XSLT

开发者 https://www.devze.com 2023-03-06 02:14 出处:网络
Im working with XSLT and I\'m outputting an HTML5 document. In my document I need a custom attribute.

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 开发者_StackOverflowto 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.

<xsl:attribute name="data-template">true</xsl:attribute>  

should produce

<div class="row" data-template="true"></div>

which looks a little less ugly.


Did you already tried:

<xsl:attribute name="data-template">data-template</xsl:attribute>

However I think is not possible to get rid of key-value pairs

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号