Using XML with XSL
XML markup documents (usually) include formatting information. The information in an XML document may not be in the desired form to present it. Therefore there must be something in addition to the XML document that provides information on how to present or otherwise process the XML.
Converting XML to HTML for display is probably the most common application of transformation today. Once you transform the XML data into HTML format, you can display it on any browser. There are two phases to the transformation process.
The first phase is a structural transformation, in which the data is converted from the structure of the incoming XML document to the structure of the desired output.
The second phase is a formatting transformation in which the new structure is changed to the required format (e.g., HTML, PDF, DB2, Oracle, etc.).
XSL
Originally, XSL's developers envisioned that XSL would be developed into a platform and media-independent formatting language composed of two parts, a formatting language and a transformation language. The formatting language was to be a set of XML elements that would describe the various parts of page media, such as tables, headers, and footnotes. These descriptive elements would be the "formatting objects". The transformation language was intended to convert an XML document into a result tree, consisting of the XSL formatting objects. The original XSL concept actually evolved into the following three XML-related languages :
XSL
The XML vocabulary for specifying formatting objectives and other semantics.
XSL Transformation (XSLT)
The language for transforming XML documents.
XML Path Language (XPath)
An expression language used to access or refer to parts of an XML document.
- The XSL-related languages
- XSL is a language for expressing style sheets.
- XSL stylesheet is a file that describes how to display an XML document of a given type.
- XSL shares the functionality and is compatible with CSS2, the latest version of CSS, although it uses a different syntax.
- XSL adds advanced styling features, expressed by an XML document type, that define two sets of elements: formatting objects and attributes.
- An XSL engine takes an XML document and an XSL stylesheet, and produces rendering of the document.
XPath
XML Path Language 1.0 is a language for addressing parts of an XML document
XPath is a language for finding the information in an XML document.
Using XPath, you can specify the locations of document, and then process the information using XSLT.
XSLT
XSLT is designed for transforming one XML document into another and uses its own kind of stylesheet to do so.
XSLT stylesheets actually change the structure and type of an XML document, for example, it automatically generate tables of contents, cross-references, indexes, etc.
XSLT stylesheets can also transform an XML document into another XML document, one using a different XML vocabulary from the original.
The XSLT stylesheet declares what output should be produced when a pattern in the XML document is matched.
For example, below is the source XML document :
The CONTACTS XML Document :
<?xml version = "1.0" encoding = "UTF-8"?>
<?DOCTYPE CONTACTS SYSTEM "contacts.dtd">
<?xml-stylesheet type-"text/xs1" href-"contacts.xslt"?>
<CONTACTS>
<SALES>
<NAME> Tim </NAME>
<ADDRESS> House no. 23 </ADDRESS>
<PHONE> 01800113456 </PHONE>
</SALES>
<SALES>
<NAME> Smith </NAME>
<ADDRESS> House no. 67 </ADDRESS>
<PHONE> 01800789234 </PHONE>
</SALES>
<SALES>
<NAME> John </NAME>
<ADDRESS>House no. 55 </ADDRESS>
<PHONE>01800678334 </PHONE>
</SALES>
</CONTACTS> |
|