XSL and XSLTXSL an acronym for the eXstensible Stylesheet Language. The XSL Transformation Language makes it possible to convert XML documents into other formats such as HTML, regular text or any other document type that is described by an XML vocabulary. XSLT is part of XSL and is meant to transform documents and because of that reason it only deals with how the information in an XML document is displayed. XSL and XSLT will handle the presentation while the information is within the XML document. In this way it becomes possible to separate the data (usually stored within an XML document) from the presenation (stored within the XSL document). Actually an XSL document is an XML document, but with a set of rules of how another XML document should be treated during conversion. An XML/XSL parser can be used to transform XML document A using XSL document B into another document C. The result document, document C, can be a text document, an HTML or XHTML document, another XML document or a document of any format that is defined by an XML vocabulary. Since an XSL document is an XML document, the same rules of an XML document apply to an XSL document. An XSL document has to be well-structured just as an XML document. All elements have a beginning and a closing tag. The values of all attributes have to placed between quotes, etc. And ofcourse: Each XSL document starts with the XML declaration which is similar to this: <?xml version="1.0" standalone="yes"?> XSL is a language that is used to express stylesheets. XSL consists of three parts:
An XSL stylesheet specifies the presentation of a class of XML documents by describing how an instance of the class is transformed into an XML document that uses the formatting vocabulary. Below is shown how an example XML document and a corresponding XSL document are used to create a resulting XHTML document.
If you have an XSLT compliant browser it can be used to transform XML into XHTML. In that case clicking on this link will show you the result of the transformation of the XML in the example above using the XSLT as displayed above. The example above is just meant to give an idea of what XSLT does and how it's used. To fully understand what happens here, you should think of the structure of the XML document as a tree. The <booklist> element is the root element and also the root of the corresponding tree. Each <book> element is a branch of the tree (and can have one or more leaves). To make it more clear: <booklist> element is a parent element and the <book> elements are children of the <booklist> element. The XSLT document has a rule matching for each <booklist> element in the XML document. Everything within that <xsl:template match="booklist"> tag will be processed. So all the HTML tags are displayed in the result. But within that element is another XSL element, the <xsl:for-each select="book"> element. This rule says that for each <book> element in the XML document the contents of that tag should be parsed. The <xsl:for-each select="book"> element in the XSL document has two <xsl:value-of> children. An <xsl:value-of> element is to display the value of a specified element or attribute within the XML document. The <xsl:value-of select="@title"> element tells that the value of the title attribute of the current <book> tag within the XML document should be displayed and the <xsl:value-of select="@price"> tag is to display the value of the price attribute. Since the <xsl:value-of> elements are children of a <xsl:for-each select="book"> all of the <book> elements will be parsed. Relevant links
See AlsoContact the author: Send an electronic mail to: pajtroon@dds.nl. This page: Copyright © 2002 - 2005 Peter A. J. Troon Note: This page is part of the Peter Troon Site. |