Transcript
Page 1: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents.

• The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML-based Stylesheet Language.

Page 2: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• CSS = Style Sheets for HTML

• HTML uses predefined tags, and the meaning of each tag is well understood.

• The <table> tag in HTML defines a table - and a browser knows how to display it.

• Adding styles to HTML elements are simple. Telling a browser to display an element in a special font or color, is easy with CSS.

Page 3: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• XSL = Style Sheets for XML

• XML does not use predefined tags (we can use any tag-names we like), and therefore the meaning of each tag is not well understood.

• A <table> tag could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it.

• XSL describes how the XML document should be displayed!

Page 4: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• XSL consists of three parts:

XSLT - a language for transforming XML documents

XPath - a language for navigating in XML documents

XSL-FO - a language for formatting XML documents

Page 5: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• XSLT = XSL Transformations

• XSLT is the most important part of XSL.

• XSLT is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by transforming each XML element into an (X)HTML element.

• With XSLT you can add/remove elements and attributes to or from the output file. You can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more.

• A common way to describe the transformation process is to say that XSLT transforms an XML source-tree into an XML result-tree

Page 6: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• XSLT Uses XPath

• XSLT uses XPath to find information in an XML document. XPath is used to navigate through elements and attributes in XML documents.

• XPath is used to navigate through elements and attributes in an XML document.

• In the transformation process, XSLT uses XPath to define parts of the source document that should match one or more predefined templates. When a match is found, XSLT will transform the matching part of the source document into the result document.

Page 7: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• Style Sheet Declaration

• The root element that declares the document to be an XSL style sheet is <xsl:stylesheet> or <xsl:transform>.

• Note: <xsl:stylesheet> and <xsl:transform> are completely synonymous and either can be used!

• The correct way to declare an XSL style sheet according to the W3C XSLT Recommendation is:

• <xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

• or:

• <xsl:transform version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

• The xmlns:xsl="http://www.w3.org/1999/XSL/Transform" points to the official W3C XSLT namespace. If you use this namespace, you must also include the attribute version="1.0”

Page 8: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• We want to transform the following XML document ("cdcatalog.xml") into XHTML:

• <?xml version="1.0" encoding="ISO-8859-1"?><catalog><cd><title>Lagaan</title><artist>Amir Khan</artist><country>India</country><company>Amir Khan Productions </company><price>10.90</price><year>2001</year></cd>..</catalog>

Page 9: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• Link the XSL Style Sheet to the XML Document

• Add the XSL style sheet reference to your XML document ("cdcatalog.xml"):

• <?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?><catalog> <cd><title>Lagaan</title><artist>Amir Khan</artist><country>India</country><company>Amir Khan Productions </company><price>10.90</price><year>2001</year></cd> ..</catalog>

Page 10: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• Then you create an XSL Style Sheet ("cdcatalog.xsl") with a transformation template:

• <?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">

<html><body><h2>My CD Collection</h2><table border="1"><tr bgcolor="#9acd32"><th>Title</th><th>Artist</th></tr><xsl:for-each select="catalog/cd"><tr><td><xsl:value-of select="title"/></td><td><xsl:value-of select="artist"/></td></tr></xsl:for-each></table></body></html>

</xsl:template></xsl:stylesheet>

Page 11: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• Since an XSL style sheet is an XML document, it always begins with the XML declaration: <?xml version="1.0" encoding="ISO-8859-1"?>.

• The next element, <xsl:stylesheet>, defines that this document is an XSLT style sheet document (along with the version number and XSLT namespace attributes).

• The <xsl:template> element defines a template. The match="/" attribute associates the template with the root of the XML source document.

• The content inside the <xsl:template> element defines some HTML to write to the output.

Page 12: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• The <xsl:value-of> Element

• The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation:

Page 13: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• The <xsl:for-each> element allows you to do looping in XSLT.

• The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set:

Page 14: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• Filtering the Output

• We can also filter the output from the XML file by adding a criterion to the select attribute in the <xsl:for-each> element.

<xsl:for-each select="catalog/cd[artist=’Amir Khan']">

• Legal filter operators are:

= (equal)

!= (not equal)

&lt; less than

&gt; greater than

Page 15: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• The <xsl:if> Element

• To put a conditional if test against the content of the XML file, add an <xsl:if> element to the XSL document.

• <xsl:for-each select="catalog/cd"><xsl:if test="price &gt; 10"><tr><td><xsl:value-of select="title"/></td><td><xsl:value-of select="artist"/></td></tr></xsl:if></xsl:for-each>

Page 16: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• What is XHTML?

• XHTML documents are XML conforming. As such, they are readily viewed, edited, and validated with standard XML tools. XHTML documents can be written to operate as well or better than they did before in existing HTML 4-conforming user agents as well as in new, XHTML 1.0 conforming user agents.

• XHTML documents can utilize applications (e.g. scripts and applets) that rely upon either the HTML Document Object Model or the XML Document Object Model [DOM].

Page 17: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

XHTML stands for EXtensible HyperText Markup Language

• XHTML is a combination of HTML and XML (EXtensible Markup Language).

• XHTML consists of all the elements in HTML 4.01, combined with the strict syntax of XML.

Page 18: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• XML is a markup language where everything must be marked up correctly, which results in "well-formed" documents.

• XML is designed to describe data, and HTML is designed to display data.

• Today's market consists of different browser technologies, some browsers run on computers, and some browsers run on mobile phones or other small devices. The last-mentioned do not have the resources or power to interpret a "bad" markup language.

• Therefore - by combining the strengths of HTML and XML, W3C recommended a markup language that is useful now and in the future - XHTML.

Page 19: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• Displaying XML with XSLT

• XSLT is the recommended style sheet language of XML.

• XSLT (eXtensible Stylesheet Language Transformations) is far more sophisticated than CSS.

• XSLT can be used to transform XML into HTML, before it is displayed by a browser:

Page 20: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• ISO-8859-1• ISO-8859-1 is the default character set in most

browsers.• The first 128 characters of ISO-8859-1 is the

original ASCII character-set (the numbers from 0-9, the uppercase and lowercase English alphabet, and some special characters).

• The higher part of ISO-8859-1 (codes from 160-255) contains the characters used in Western European countries and some commonly used special characters.

• Entities are used to implement reserved characters or to express characters that cannot easily be entered with the keyboard.

Page 21: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents.

• XSLT stands for XSL Transformations.

Page 22: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• It started with XSL and ended up with XSLT, XPath, and XSL-FO.

• It Started with XSL

• XSL stands for EXtensible Stylesheet Language.

• The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML-based Stylesheet Language.

• CSS = Style Sheets for HTML

• HTML uses predefined tags, and the meaning of each tag is well understood.

• The <table> tag in HTML defines a table - and a browser knows how to display it.

• Adding styles to HTML elements are simple. Telling a browser to display an element in a special font or color, is easy with CSS. 

• XSL = Style Sheets for XML

• XML does not use predefined tags (we can use any tag-names we like), and therefore the meaning of each tag is not well understood.

• A <table> tag in XML could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it.

Page 23: XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents

• XSL describes how the XML document should be displayed!

• XSL - More Than a Style Sheet Language

• XSL consists of three parts:

• XSLT - a language for transforming XML documents

• XPath - a language for navigating in XML documents

• XSL-FO - a language for formatting XML documents


Recommended