2.6 XSL and XSLT: Making XML presentable


2.6 XSL and XSLT: Making XML presentable

Once you have an XML document, people invariably want to be able to display it on various devices ”with Web browsers and intelligent cell phones being in the lead in this respect. However, it does not end here. There is a lot of work currently taking place on VoiceXML for voice-based applications such as the voice response systems used by call centers. XML documents are typically displayed on a browser or cell phone by associating a stylesheet with the XML document. In some cases this can be achieved by using standard Cascading Stylesheets (CSS).

Stylesheets, or CSS, per se are not new concepts. They were introduced to enhance HTML in the early 1990s, with CSS Level 1 becoming a W3C recommendation in December 1996 (well before the advent of XML). CSS is a simple but powerful mechanism for adding style (i.e., different fonts, colors, spacing, borders, and backgrounds) to Web documents. Though it took some time before CSS was adequately supported by browsers, this is no longer an issue and full CSS support is available in contemporary versions of the popular browsers. Given that many Web page developers are now familiar with CSS, it provides a quick and easy way to add visual embellishments to an XML document.

XSL, however, is the more strategic approach for presenting XML documents, given that CSS uses a non-XML syntax. (There is a parallel here with DTDs and XML schema, where DTD s lack of XML compliance is one of the key reasons why XML schema is deemed to be more strategic than DTDs.) XSL defines the format for an XML document. XSL is divided into two parts : XSL Formatting Objects (XSL-FO) and XSL Transformations (XSLT). XSL-FO is deemed to be an XML application that can be used to precisely describe the layout of a page in terms of blocks of text, graphics, and horizontal lines. Most people, however, do not create XSL-FOs. Instead, they write an XSLT Stylesheet, which transforms the XML in your document into the corresponding XSL-FOs.

XSLT is also called an XML application. It specifies how one XML document can be transformed into another. XSLT works through the use of XSLT stylesheets, which are sometimes referred to as XSLT documents. XSLT stylesheets contain templates and are XML documents in their own right. XSLT works by comparing the elements in an input XML document being converted with the templates appearing in the stylesheet. When it finds a match, it creates a corresponding output per what is specified in the template. You can have multiple stylesheets for the same XML document: one for displaying the document in HTML form within a browser and another for displaying it in some type of WML form on an intelligent phone.

Internet Explorer 5.5 (and greater) has a built-in XSLT processor that enables it to accept XML documents and corresponding stylesheets and process the necessary XSLT transformations on the fly. If the browser does not support XSLT, a separate XSLT processor will have to be used ”for example, the open -source Apache Software Foundation s Xalan (in Java or C++) from http://www.apache.org.

XHTML per se, despite any connotations evoked by its name , is not a formatting- related adjunct to XML. Instead, it is an XML-based variant of HTML 4.0 ”and is an official W3C recommendation. It reformulates HTML 4.0 to ensure that it lives up to XML s syntax requirements. There are three DTDs available that describe HTML 4.0 in terms of XML. The big thing with XHTML is that it imposes strict discipline on HTML. First, unmatched tags are not allowed, so all start tags have to have matching end tags. All attribute values now have to appear within quotes. Whereas HTML is not case sensitive, XHTML, consistent with XML being case sensitive, enforces case sensitivity in the case of tags ”deeming < p > to be valid and < P > to be invalid. Most of today s browsers, irrespective of their vintage , can adequately render most XHTML documents.




Web Services[c] Theory and Practice
Web Services[c] Theory and Practice
ISBN: 1555582826
EAN: N/A
Year: 2006
Pages: 113

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net