May 28, 2021 XSL T
Since not all browsers support XSLT, another solution is to convert XML to XHTML on the server.
In the previous sections, we explained how to use XSLT in your browser to convert from XML to XHTML. W e created a JavaScript that uses an XML parser to convert. JavaScript solutions do not work in browsers that do not have XML parsers.
In order for XML data to work for any type of browser, we have to convert the XML document on the server and send it back to the browser as XHMTL.
This is another advantage of XSLT. One of XSLT's design goals is to make it possible to convert data from one format to another on the server and return readable data to all types of browsers.
Take a look at this XML document that was shown in the previous section:
and the accompanying XSL style sheet:
Note that this XML file does not contain a reference to the XSL file.
Important: This sentence above means that XML files can be converted using several different XSL style sheets.
This is the source code used to convert XML files to XHTML on the server:
Tip: If you don't know how to write an ASP, you can take our ASP tutorial.
The first piece of code created an instance of Microsoft's XML Parser (XMLDOM) and loaded the XML file into memory. T he second piece of code creates another instance of the parser and loads the XSL file into memory. T he last line of code transforms the XML document using the XSL document and sends the results as XHTML to your browser. That's great!
In the following section, we'll show you how to edit XML!