Tuesday, 7 December 2010

XSL generating XHTML

Discuss how XSL can be used to generate XHTML, with examples.

# XSL stands for Extensible Stylesheet Language. It is a language for creating style sheet that describes how data sent over the Web using the XML is to be presented to the user. For instance, in an XML page that describes the characteristics of one or more brand for a shoe company, a set of open and close tags might contain the name of a shoes manufacturer. Using XSL, you could tell the web browser that the shoe manufacturer name should be displayed, where to display it on a web page and also should be displayed in an italic font.
            Basically, it provides tools for developer to facilitate them by helping to describe exactly which data fields in an XML file to display and exactly where and how to display them. It consists of a number of subsets that allow using a markup language, such as HTML or XHTML to manage the presentation of the data contained within the XML document. There are three parts to XSL:
XSLT: It takes existing XML documents and transforms them into other XML documents, It allows an XML author to write content only once and put it in many different formats.
XPath: It defines parts of an XML documents. It allows XML author to link to very specific locations within an XML document.
XSL formatting objects: It is the part of the XSL specification, and they define the formatting for various objects or portions of the XML document.

XSLT is the language which most of the people keen to learn when starting to learn XSL. This is the quasi-scripting language of XSL. It allows converting one XML document into another. For instance, it allows converting XHTML to WML or SMIL to XHTML. Furthermore, it is broken down into two types of information: instructions and literals. Instructions are the XSLR elements and attributes that notify exactly, how XML content is to be transformed. Whereas, Literal are static pieces of information that are placed directly on the resulting document and therefore aren’t processed in any way. But it plays a significant role in XSLT to transform and XML document into an XHTML document for display in a web browser. To generate an XHTML document using XSLT, XHTM code must be placed throughout the style sheet as literal. XSL instructions are then used to transform XML content and place it within the XHTML code.
For example:
<?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>



No comments:

Post a Comment