1 / 9

Using XSL to Generate XHTML Documents

Using XSL to Generate XHTML Documents. Roger L. Costello XML Technologies. What is XHTML?. With HTML you can omit end tags, use upper case for the start tag and then lower case for the end tag (i.e., HTML if case insensitive leave off the quotes around attribute values

misha
Télécharger la présentation

Using XSL to Generate XHTML Documents

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

  2. What is XHTML? • With HTML you can • omit end tags, • use upper case for the start tag and then lower case for the end tag (i.e., HTML if case insensitive • leave off the quotes around attribute values • Clearly, these all violate XML • XHTML is HTML that follows all the rules of XML

  3. HTML: <br> XHTML: <br class="empty"/> Most browsers today do not understand empty elements, e.g., <br/>. Consequently, we must "trick" the browser. You can put a class attribute on just about any HTML element. The class attribute can have any value. So, we use the class attribute simply to get the browser to "see" this element as a break element.

  4. HTML: <table> … </TABLE> XHTML: <table> … </table> XHTML specifies that all tags be in lower case.

  5. HTML: <body bgcolor=lightgrey> XHTML: <body bgcolor="lightgrey"> Quote the attribute value!

  6. HTML: <html> <!DOCTYPE html PUBLIC "-//W3//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> XHTML: 1. Add a DOCTYPE declaration with a PUBLIC identifier 2. Add a namespace declaration to the root element.

  7. Advantages of formatting your HTML as XHTML • Ever notice how some web sites are broken when viewed in Netscape, but work when viewed in IE (or vice-versa)? • That's oftentimes because the HTML has missing end tags and one browser is able to "fix it" while the other isn't • If it were written in XHTML then there would never be a problem with missing end tags • Many web masters will check their HTML by testing it against as many browsers as they can • There are many, many browsers, and many versions of browsers, so exhaustive testing is very difficult • If it were written in XHTML then it could be tested simply by validating against the XHTML DTD • Due to the relative randomness of HTML it is very difficult for applications such as screen scrapers to make use of it. • With XHTML the document is much more strictly organized and hence it is easier to parse and make use of it.

  8. Generating XHTML with your stylesheet <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0"> <xsl:output method="html" doctype-public="-//W3//DTD XHTML 1.0 Transitional//EN" doctype-system=" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> <xsl:template match="/"> <html> <head> <title>Welcome</title> </head> <body> Welcome! </body> </html> </xsl:template> </xsl:stylesheet> This default namespace declaration will generate an identical default namespace declaration in the output These instruct the XSL Processor to create a DOCTYPE declaration in the output, with a PUBLIC identifier as well as a SYSTEM identifier. (see html-example25)

  9. Here's what will be generated <!DOCTYPE html PUBLIC "-//W3//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome</title> </head> <body> Welcome! </body> </html> Notes: 1. There is no XML declaration 2. There is a DOCTYPE declaration containing a PUBLIC identifier as well as a SYSTEM identifier 3. There is a default namespace declaration 4. We can validate this XHTML document

More Related