1 / 23

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. CSS = Style Sheets for HTML

takara
Télécharger la présentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. 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.

  3. 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!

  4. 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

  5. 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

  6. 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.

  7. 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”

  8. 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>

  9. 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>

  10. 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>

  11. 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.

  12. 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:

  13. 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:

  14. 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

  15. 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>

  16. 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].

  17. 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.

  18. 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.

  19. 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:

  20. 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.

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

  22. 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.

  23. 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

More Related