If your browser supports it, XSLT can be used to transform the document to XHTML in your browser.
Even if this works fine, it is not always desirable to include a style sheet reference in an XML file (e.g. it will not work in a non XSLT aware browser.)
A more versatile solution would be to use a JavaScript to do the transformation.
By using a JavaScript, we can:
That is the beauty of XSLT! One of the design goals for XSLT was to make it possible to transform data from one format to another, supporting different browsers and different user needs.
XSLT transformation on the client side is bound to be a major part of the browsers work tasks in the future, as we will see a growth in the specialized browser market (Braille, aural browsers, Web printers, handheld devices, etc.)
Look at the XML document that you have seen in the previous chapters:
And the accompanying XSL style sheet:
Notice that the XML file does not have a reference to the XSL file.
IMPORTANT: The above sentence indicates that an XML file could be transformed using many different XSL style sheets.
Here is the source code needed to transform the XML file to XHTML on the client:
Tip: If you don't know how to write JavaScript, you can study our JavaScript tutorial.
The loadXMLDoc() Function
The loadXMLDoc() function is used to load the XML and XSL files.
It checks what kind of browser the user has and loads the file.
The displayResult() Function
This function is used to display the XML file styled by the XSL file.
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.