XSLT< XSL:输出>支持主流浏览器 [英] XSLT <xsl:output> support in main browsers

查看:207
本文介绍了XSLT< XSL:输出>支持主流浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过XSLT将输入XML文档转换为XHTML。在我的样式表,我使用的xsl:输出以下属性:

I want to transform an input XML document into XHTML via XSLT. In my stylesheet I'm using xsl:output with the following attributes:

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />

转变成XTHML 1.0严格工作正常,当我使用像XML编辑器复制或Editix编辑XSLT处理器。它的工作原理,当我使用命令行xsltproc的,也符合市场预期。

The transformation into XTHML 1.0 Strict works fine when I use the XSLT Processor in editors like XML Copy Editor or Editix. It works as expected when I use the command line xsltproc, too.

但是,当我在我的样式表(myfile.xsl)链接到原始XML文档(将myfile.xml)是这样的:

But when I link my stylesheet ("myfile.xsl") into the original XML document ("myfile.xml") like this:

<?xml-stylesheet type="text/xsl" href="myfile.xsl"?>

如果我尝试在主流浏览器(Chrome浏览器,IE或Mozilla),到现在看myfile.xml中,他们没有能够在预期的XHTML转换的XML文档。使用Opera,但是,它完美的作品。

if I try to watch now "myfile.xml" in the major browsers (Chrome, IE or Mozilla), none of them is capable of transforming the XML document in the expected XHTML. With Opera, however, it works perfectly.

这是一个错误在我的XSLT(即在xsl:输出)或这是在XSLT实现的主流浏览器(IE,浏览器,Mozilla)的一个漏洞?

Is there something wrong in my XSLT (namely in the xsl:output) or is this a flaw in the XSLT implementation of the major browsers (IE, Chrome, Mozilla)?

只有当我使用属性的方法=XML出现问题。如果我使用method =HTML,它工作在所有浏览器。但是,我需要生成XHTML,HTML没有,这就是为什么我使用method =XML的DOCTYPE系统和放一起;在XSL DOCTYPE公共属性:输出

The problem occurs only when I use the attribute method="xml" in . If I use method="html", it works in all browsers. But I need to generate XHTML, not HTML, that's why I use method="xml" along with the doctype-system & doctype-public attributes in xsl:output

推荐答案

那么你还没有真正告诉我们在浏览器无法何种方式。如果你想创建XHTML输出然后确保你使用XHTML命名空间为您的结果元素即把

Well you haven't really told us in what way the browsers fail. If you want to create XHTML output then make sure you use the XHTML namespace for your result elements i.e. put

<xsl:stylesheet
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />


<xsl:template match="/">
  <html>...<xsl:apply-templates/>...</html>
</xsl:template>

</xsl:stylesheet>

在code,以确保结果元素是XHTML元素(而不是XML元素没有命名空间碰巧有地方的名称,如HTML,但不识别为XHTML)。

in your code to make sure the result elements are XHTML elements (and not XML elements in no namespace that happen to have local names like 'html' but are not recognizable as XHTML).

我是pretty确保火狐/ Mozilla浏览器与输出方式方法 XML 识别XHTML元素。而IE 9和10以及我在想,我与有限的XHTML支持将工作不知道旧版本的IE。

I am pretty sure that Firefox/Mozilla browsers that way with output method xml recognize the XHTML elements. And IE 9 and 10 as well I think, I am not sure older versions of IE with limited XHTML support will work.

要举个例子,XML输入 HTTP://home.arcor由Matchi.com提供回到/ martin.honnen / XSLT / test2013040601.xml 转化为 XML 通过的 http://home.arcor.de/martin.honnen/xslt/test2013040601.xsl 并正常工作与IE 10和当前版本的Firefox和Chrome在Windows 8上。

To give you an example, the XML input http://home.arcor.de/martin.honnen/xslt/test2013040601.xml is transformed to xml output via http://home.arcor.de/martin.honnen/xslt/test2013040601.xsl and works fine with IE 10 and current version of Firefox and Chrome on Windows 8.

这篇关于XSLT&LT; XSL:输出&GT;支持主流浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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