Jump to content

Html5 In Xslt

Recommended Posts

Am trying to use <!DOCTYPE html > in xslt but it shows error anything am missing to correct form of html5 in xslt. please suggest.

<?xml version="1.0" encoding="utf-8"?><!-- Edited by XMLSpy® --><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/">  <!DOCTYPE html >   <body style="background-color:#CCCCCC">     <h2>My CD Collection</h2>	<table border="1" cellpadding="0" cellspacing="0">	  <tr bgcolor="#9acd32" style="text-indent:10px;">		<th>Title</th>		<th>Artist</th>		<th>Country</th>	  </tr>	  <xsl:for-each select="catalog/cd">	  <tr style="text-indent:10px;">		<td><xsl:value-of select="title"/></td>		<td><xsl:value-of select="artist"/></td>		<td><xsl:value-of select="country" /></td>	  </tr>	  </xsl:for-each>	</table>  </body>  </html></xsl:template></xsl:stylesheet> 

Edited by brian
Link to post
Share on other sites

Well the problem is that XSLT 1.0 dates from 1999 and XSLT 2.0 from 2007 while HTML5 is a moving target. I know that Saxon 9.3 does output



<xsl:output method="html" version="5.0"/>

but I don't think other XSLT processors do that.Putting the DOCTYPE node into a template in the stylesheet, as you have tried, is not allowed by the XML syntax of XSLT stylesheets.What you could try is

<xsl:template match="/">  <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE html>]></xsl:text>  ...</xsl:template>

at least as long as the XSLT result is serialized (which for instance the XSLT processor built into Mozilla browsers does not do).

Edited by Martin Honnen
Link to post
Share on other sites

You're also missing an opening <html> tag BTW. Remove that and the DTD, and the error will be gone.The generated document will not be a "valid" HTML5 document (well... not per the validator), but if XSLT is executing in the browser, that shouldn't really be a concern.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...