Since not all browsers support XSLT, one solution is to transform the XML to XHTML on the server.
因为不是所有的浏览器都支持XSLT,所以人们提出了一个在服务器端把XML转换成XHTML的解决方案。
A Cross Browser Solution
一个交叉浏览器解决方案
In the previous chapter we explained how XSLT can be used to transform a document from XML to XHTML in the browser. We created a JavaScript that used an XML parser to do the transformation. The JavaScript solution will not work in a browser that doesn't have an XML parser.
在前一章我们解释了怎样在浏览器中用XSLT把文件从XML转换成XHTML。我们创建了一个用XML解析器来做转换的JavaScript。JavaScript解决程序将不会在没有XML解析器的浏览器上运行。
To make XML data available to all kind of browsers, we must transform the XML document on the SERVER and send it as XHTML back to the browser.
想使XML数据对各种浏览器都适用,我们必须在服务器上转换XML文件,并把它以XHTML的形式发送回浏览器。
That's another beauty of XSLT. One of the design goals for XSLT was to make it possible to transform data from one format to another on a server, returning readable data to all kinds of browsers.
这是XSLT的另一个魅力。XSLT的其中一个设计目标就是能够让它在服务器端将数据从一种格式转化为另一种格式,并把所有可读的数据返回到各种浏览器上。
The XML File and the XSLT File
XML文件和XSLT文件
Look at the XML document that you have seen in the previous chapters:
下面我们来回顾一下前一章使用过的XML文件:
<?xml version="1.0" encoding="ISO-8859-1"?> |
And the accompanying XSL style sheet:
附随的XSL样式表:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:template match="/"> </xsl:stylesheet> |
Notice that the XML file does not have a reference to the XSL file.
注意XML文件和XSL文件并无关联
IMPORTANT: The above sentence indicates that an XML file could be transformed using many different XSL style sheets.
重点:上面的句子指出:XML文件不应该通过不同的XSL样式表进行转换。
Transforming XML to XHTML on the Server
在服务器端把XML转换成XHTML
Here is the ASP source code needed to transform the XML file to XHTML on the server:
这儿的动态服务器主页(ASP)源代码需要在服务器端把XML文件转换成XHTML。
<% |
Tip: If you don't know how to write ASP, you can study our ASP tutorial.
提示: 如果你不知道怎样书写ASP,你可以了解一下ASP 教程
The first block of code creates an instance of the Microsoft XML parser (XMLDOM), and loads the XML file into memory. The second block of code creates another instance of the parser and loads the XSL file into memory. The last line of code transforms the XML document using the XSL document, and sends the result as XHTML to your browser. Nice!
第一块代码创建了一个微软XML解析器(XMLDOM)的实例,并把此文件加载到存储器里。第二块代码创建了另外一个解析器的实例,并把XSL文件加载到存储器中。最后一行代码通过使用XSL文件来转换XML文件,并将其以XHTML的形式把结果发到浏览器上。真棒!
436

被折叠的 条评论
为什么被折叠?



