RFC:通过XSLT从XHTML到HTML [英] RFC: From XHTML to HTML via XSLT

查看:78
本文介绍了RFC:通过XSLT从XHTML到HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,XHTML是更好的HTML,您可以将XHTML内容作为HTML提供。

但是,由于各种原因,第二种说法是不正确的;

足以说HTML验证器不能容忍XML样式的空标签。

似乎向浏览器提供XHTML没有任何优势,可能会导致严重的问题如果浏览器不理解差异。

这引发了将XHTML降级为HTML的问题。

我在WWW公司找不到任何相关的指令,所以我决定用XSLT自己动手。

我附上XSLT代码,我请求评论(因为我是这方面的新手)。

请注意,必须复制所有标签和属性,剥离napespace;

< xsl:copydoes无法按预期工作,因为我得到< br>< / brinstead of< bronly。

我决定明确复制评论

,以便能够将Internet Explorer条件包含注释嵌入到输出中。

Chris


< xsl:stylesheet version = 1.0


xmlns:xsl =" http://www.w3.org/1999/XSL/Transform">


< xsl:output


method =" html" doctype-public =" - // W3C // DTD HTML 4.01 Transitional // EN"


doctype-system =" http://www.w3.org/TR/ html4 / loose.dtd"


/>


< xsl:template match =" @ *"< xsl: attribute name =" {name()}" < xsl:value-of select ="。" /< / xsl:attribute>


< / xsl:template>


< xsl:template match =" *" ;


< xsl:element name =" {name()}"< xsl:apply-templates select =" @ * |节点()" /< / xsl:element


< / xsl:template< xsl:template match =" comment()"< xsl:copy /< / xsl:template> ;


< / xsl:stylesheet>

解决方案

在我们的上一集中, < et *********** @ news2.ipartners.pl> ;,可爱且有价值的优惠K?i1tof?elechovski在

comp播出.infosystems。 www.authoring.html:


众所周知,XHTML更好HTML



不,它不是。


-

Lars Eighner< http://larseighner.com/<tp://myspace.com/larseighner>

倒计时:670天。




Uzytkownik" Lars Eighner" < us **** @ larseighner.comnapisal w wiadomosci news:sl ******************* @ goodwill.larseighner.co m ...
< blockquote class =post_quotes>
在我们的最后一集中,< et *********** @ news2.ipartners.pl>,可爱的和

才华横溢K?i1tof?elechovski在

comp.infosystems上播出。 www.authoring。 html:


>众所周知,XHTML更好HTML



否,它不是。



这不是更好的HTML,但它是一个普遍的看法。

Chris


< blockquote> K ?? i ?? tof ?? elechovski,comp.infosystems。 www.authoring.html:


doctype-public =" - // W3C // DTD HTML 4.01 Transitional // EN"

doctype-系统= QUOT; HTTP://www.w3.org/TR/html4/loose.dtd"



理想情况下,您应该从

XHTML文档中保留DTD类型(Transitional / Strict),但遗憾的是无法做到这在XSLT中。


< xsl:template match =" @ *"< xsl:attribute name =" {name()}" >

< xsl:value-of select ="。" /< / XSL:属性< / XSL:模板>



我不确定这是一个好策略:实际上,你可能想要

只保留默认命名空间中的属性(例如,删除

xml:lang / xml:space):


< xsl:template match =" @ * [namespace -uri()='''''">

< xsl:copy />

< / xsl:template>


< xsl:template match =" @ *" />


< xsl:template match =" *">


< xsl:element name =" {name()}"< xsl:apply-templates select =" @ * |节点()" /< / xsl:element>


< / xsl:template>



在这里,您可能只想保留xhtml

名称空间的元素;另请注意使用local-name()而不是name(),以防原始的XHTML文档使用名称空间前缀:


< xsl: template match =" * [namespace-uri()=''http://www.w3.org/1999/xhtml'']">

< xsl:element name = " {local-name()}">

< xsl:apply-templates select =" @ * | node()" />

< / xsl:element>

< / xsl:template>


未经测试。

It is common knowledge that XHTML is better HTML and you can serve XHTML content as HTML.
However, the second statement is incorrect, for various reasons;
it is enough to say that the HTML validator does not tolerate XML-style empty tags.
It seems serving XHTML to the browser is of no advantage and can cause serious problems if the browser does not understand the difference.
This raises the question of downgrading XHTML to HTML.
I could not find any relevant instruction at the WWW Corporation so I decided I have to roll my own with XSLT.
I attach the XSLT code and I kindly ask for comments (because I am a novice in this area).
Please note that all tags and attributes have to be copied stripping the napespace;
<xsl:copydoes not work as expected because I get <br></brinstead of <bronly.
I decided to copy the comments explicitly
in order to be able to embed Internet Explorer conditional inclusion comments into the output.
Chris

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output

method="html" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"

doctype-system="http://www.w3.org/TR/html4/loose.dtd"

/>

<xsl:template match="@*"<xsl:attribute name="{name()}" <xsl:value-of select="." /</xsl:attribute>

</xsl:template>

<xsl:template match="*"

<xsl:element name="{name()}"<xsl:apply-templates select="@* | node()" /</xsl:element

</xsl:template<xsl:template match="comment()"<xsl:copy /</xsl:template>

</xsl:stylesheet>

解决方案

In our last episode, <et***********@news2.ipartners.pl>, the lovely and
talented K?i1tof ?elechovski broadcast on
comp.infosystems.www.authoring.html:

It is common knowledge that XHTML is better HTML

No, it isn''t.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 670 days to go.



Uzytkownik "Lars Eighner" <us****@larseighner.comnapisal w wiadomosci news:sl*******************@goodwill.larseighner.co m...

In our last episode, <et***********@news2.ipartners.pl>, the lovely and
talented K?i1tof ?elechovski broadcast on
comp.infosystems.www.authoring.html:

>It is common knowledge that XHTML is better HTML

No, it isn''t.

It is not better HTML but it is a common opinion.
Chris


K??i??tof ??elechovski ,comp.infosystems.www.authoring.html:

doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
doctype-system="http://www.w3.org/TR/html4/loose.dtd"

Ideally, you should keep the DTD kind (Transitional/Strict) from the
XHTML document, but there is unfortunately no way to do this in XSLT.

<xsl:template match="@*"<xsl:attribute name="{name()}" >
<xsl:value-of select="." /</xsl:attribute</xsl:template>

I am not sure this is the good strategy: actually, you''d probably want to
keep only attributes in the default namespace (so as to remove
xml:lang/xml:space, for instance):

<xsl:template match="@*[namespace-uri()='''']">
<xsl:copy />
</xsl:template>

<xsl:template match="@*" />

<xsl:template match="*">

<xsl:element name="{name()}"<xsl:apply-templates select="@* | node()" /</xsl:element>

</xsl:template>

Same here, you probably want to keep only elements of the xhtml
namespace; note also the use of local-name() instead of name(), in case
your original XHTML document use namespace prefixes:

<xsl:template match="*[namespace-uri()=''http://www.w3.org/1999/xhtml'']">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>

Untested.


这篇关于RFC:通过XSLT从XHTML到HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆