Jump to content

Html5 In Xslt


brian

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> 

Link to comment
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

<!DOCTYPE HTML>

for

<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).

Link to comment
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 comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...