9
1 e MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

1 The MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

Embed Size (px)

Citation preview

Page 1: 1 The MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

1The MITRE Corporation @JICPAC

Using XSL to Generate XHTML Documents

Roger L. Costello

XML Technologies

Page 2: 1 The MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

2The MITRE Corporation @JICPAC

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

Page 3: 1 The MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

3The MITRE Corporation @JICPAC

<br>

<br class="empty"/>

HTML:

XHTML:

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 HTMLelement. The class attribute can have any value. So, weuse the class attribute simply to get the browser to "see"this element as a break element.

Page 4: 1 The MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

4The MITRE Corporation @JICPAC

<table> … </TABLE>

<table> … </table>

HTML:

XHTML:

XHTML specifies that all tags be in lower case.

Page 5: 1 The MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

5The MITRE Corporation @JICPAC

<body bgcolor=lightgrey>

<body bgcolor="lightgrey">

HTML:

XHTML:

Quote the attribute value!

Page 6: 1 The MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

6The MITRE Corporation @JICPAC

<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">

HTML:

XHTML:

1. Add a DOCTYPE declaration with a PUBLIC identifier2. Add a namespace declaration to the root element.

Page 7: 1 The MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

7The MITRE Corporation @JICPAC

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.

Page 8: 1 The MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

8The MITRE Corporation @JICPAC

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 declarationwill generate an identical defaultnamespace declaration in the output

These instruct the XSL Processor tocreate a DOCTYPE declaration inthe output, with a PUBLIC identifieras well as a SYSTEM identifier.

(see html-example25)

Page 9: 1 The MITRE Corporation @JICPAC Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies

9The MITRE Corporation @JICPAC

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 declaration2. There is a DOCTYPE declaration containing a PUBLIC identifier as well as a SYSTEM identifier3. There is a default namespace declaration4. We can validate this XHTML document