简体   繁体   English

xslt中的W3C验证错误

[英]w3c validation error in xslt

My xsl file is like: 我的xsl文件就像:

<img> 
     <xsl:attribute name="id">poster_<xsl:value-of select="position()"/></xsl:attribute>      
     <xsl:attribute name="alt"><xsl:value-of select="movie-title"/></xsl:attribute>     
     <xsl:attribute name="src"><xsl:value-of select="../poster-verylarge-image"/><xsl:value-of    select="movie-photo-name"/></xsl:attribute> 
</img>

And I am getting a W3C error as: 我收到一个W3C错误,如下所示:

Line 508, Column 234: end tag for "img" omitted, but OMITTAG NO was specified 第508行,第234列:省略了“ img”的结束标签,但指定了OMITTAG NO
…artini.com/user_uploads/moviereview/420_265/7876579_1342029293_79940.jpeg"> …artini.com / user_uploads / moviereview / 420_265 / 7876579_1342029293_79940.jpeg“>

Please help me out. 请帮帮我。

Although you haven't shown the full XSLT, or the output HTML, I suspect that in your XSLT document you have specified the output be HTML 尽管您没有显示完整的XSLT或输出HTML,但我怀疑您在XSLT文档中将输出指定为HTML

<xsl:output method="html" />

According to the W3C website: 根据W3C网站:

The html output method should not output an end-tag for empty elements. html输出方法不应为空元素输出结束标记。 For HTML 4.0, the empty elements are area, base, basefont, br, col, frame, hr, img, input, isindex, link, meta and param. 对于HTML 4.0,空元素是area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta和param。 For example, an element written as <br/> or <br></br> in the stylesheet should be output as <br> . 例如,样式表中写为<br/><br></br>的元素应输出为<br>

In your small sample you are outputing an image tag, which will probably be output as follows: 在您的小样本中,您正在输出图像标签,该标签可能会输出如下:

<img id="img1" src="test.html" alt="test">

If you are validating your document as XHTML using the W3C validator, this will fail as the image tag is not closed. 如果使用W3C验证程序将文档验证为XHTML,则将失败,因为未关闭image标签。 When it is an XHTML document it means the HTML must also conform to being a well-formed XML document. 当它是XHTML文档时,这意味着HTML还必须符合格式良好的XML文档。

There a number of ways to resolve this. 有很多方法可以解决此问题。 Firstly, if you are using XSLT2.0, you can specify an output method of xhtml, and this should close the tags 首先,如果您使用的是XSLT2.0,则可以指定xhtml的输出方法,这将关闭标记

<xsl:output method="xhtml" />

Alternatively, as XHTML should be well-formed XML, you could just specify an output method of xml. 另外,由于XHTML应该是格式正确的XML,因此您只需指定xml的输出方法即可。 This will still output the HTML you require, but it will also be well-formed XML. 这仍然会输出您需要的HTML,但它也是格式正确的XML。

<xsl:output method="xml" />

However, it might be preferable to specify the doctype of the output html, so that the W3C validator knows exactly what version of HTML it is validating. 但是,最好指定输出html的文档类型,以便W3C验证程序确切知道它要验证的HTML版本。 For example: 例如:

<xsl:output method="html" 
   doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" 
   doctype-system="http://www.w3.org/TR/html4/loose.dtd" />

When you do this, an HTML document with non-closed tags should validate 执行此操作时,带有未关闭标签的HTML文档应进行验证

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<META http-equiv="Content-Type" content="text/html">
<title>Test</title></head>
<body><img id="img1" src="test.html" alt="test"></body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM