XML/XSLT

2,534 views

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,534
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
157
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

XML/XSLT

  1. 1. XML/XSLT Aravinda.J
  2. 2. Contents <ul><li>Introduction to XML </li></ul><ul><li>XML in web application </li></ul><ul><li>Java Parsers </li></ul><ul><li>XSLT </li></ul><ul><li>XSLT:FO </li></ul><ul><li>Examples </li></ul><ul><li>Usage of XML,XSLT,XSLT:FO in EDI </li></ul>
  3. 3. XML <ul><li>What is XML? </li></ul><ul><ul><li>XML stands for E X tensible M arkup L anguage </li></ul></ul><ul><ul><li>XML is a markup language much like HTML </li></ul></ul><ul><ul><li>XML was designed to describe data </li></ul></ul><ul><ul><li>XML tags are not predefined. You must define your own tags </li></ul></ul><ul><ul><li>XML uses a Document Type Definition (DTD) or an XML Schema to describe the data </li></ul></ul><ul><ul><li>XML was designed to store, carry, and exchange data. XML was not designed to display data. </li></ul></ul>
  4. 4. The main difference between XML and HTML <ul><li>XML is not a replacement for HTML. </li></ul><ul><li>XML and HTML were designed with different goals: </li></ul><ul><li>XML was designed to describe data and to focus on what data is. HTML was designed to display data and to focus on how data looks. </li></ul>
  5. 5. The following example is a note to Tove from Jani, stored as XML: <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> </li></ul><ul><li><note> </li></ul><ul><li><to>Tove</to> </li></ul><ul><li><from>Jani</from> </li></ul><ul><li><heading>Reminder</heading> </li></ul><ul><li><body>Don't forget me this weekend!</body> </li></ul><ul><li></note> </li></ul>
  6. 6. How can XML be Used? <ul><li>It is important to understand that XML was designed to store, carry, and exchange data. XML was not designed to display data. </li></ul><ul><li>With XML, your data is stored outside your HTML. </li></ul><ul><li>With XML, data can be exchanged between incompatible systems. </li></ul>
  7. 7. XML and B2B <ul><li>With XML, financial information can be exchanged over the Internet. </li></ul><ul><li>XML can be used to Share Data </li></ul><ul><li>XML can be used to Store Data </li></ul><ul><li>XML is the mother of WAP and WML. </li></ul><ul><li>The Wireless Markup Language (WML), used to markup Internet applications for handheld devices like mobile phones, is written in XML. </li></ul>
  8. 8. XML Syntax <ul><li>The syntax rules of XML are very simple and very strict. The rules are very easy to learn, and very easy to use. </li></ul><ul><li>The first line in the document - the XML declaration - defines the XML version and the character encoding used in the document. In this case the document conforms to the 1.0 specification of XML and uses the ISO-8859-1 (Latin-1/West European) character set. </li></ul><ul><li>The next line describes the root element of the document (like it was saying: &quot;this document is a note&quot;): </li></ul>
  9. 9. XML SYNTAX <ul><li>All XML elements must have a closing tag </li></ul><ul><li>XML tags are case sensitive </li></ul><ul><li>All XML elements must be properly nested </li></ul><ul><li>All XML documents must have a root element </li></ul><ul><li>Attribute values must always be quoted </li></ul>
  10. 10. DISPLAYING XML CONTENT THROUGH XSL/JAVA/CSS <ul><li>XSL stands for e X tensible S tylesheet L anguage. </li></ul><ul><li>The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML based Stylesheet Language. </li></ul><ul><li>XML does not use predefined tags (we can use any tags we like) and the meanings of these tags are not well understood . </li></ul><ul><li>The <table> could mean an HTML table or a piece of furniture, and a browser does not know how to display it . </li></ul><ul><li>There must be something in addition to the XML document that describes how the document should be displayed; and that is XSL! </li></ul>
  11. 11. XSLT Demonstration XML Doc XML Processor (xsltproc) XSLT Stylesheet PDF XML HTML
  12. 12. XSL - More Than a Style Sheet Language <ul><li>XSLT is a language for transforming XML documents </li></ul><ul><li>Think of XSL as a set of languages that can transform XML into XHTML, filter and sort XML data, define parts of an XML document, format XML data based on the data value, like displaying negative numbers in red, and output XML data to different media, like screens, paper, or voice.  </li></ul><ul><li>XPath is a language for defining parts of an XML document </li></ul><ul><li>XSL-FO is a language for formatting XML documents </li></ul>
  13. 13. WORKING OF XSLT <ul><li>XSLT Uses XPath </li></ul><ul><li>XSLT uses XPath to define the matching patterns for transformations. </li></ul><ul><li>If you want to study XPath first, please read our XPath Tutorial . </li></ul><ul><li>How does it Work? </li></ul><ul><li>In the transformation process, XSLT uses XPath to define parts of the source document that 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. The parts of the source document that do not match a template will end up unmodified in the result document. </li></ul>
  14. 14. Examples: <ul><li>cdcatalog.xml </li></ul><ul><li>cdcatalog.xsl </li></ul>
  15. 15. Elements in XSLT <ul><li>apply-imports </li></ul><ul><li>apply-templates </li></ul><ul><li>call-template </li></ul><ul><li>choose </li></ul><ul><li>decimal-format </li></ul><ul><li>for-each </li></ul><ul><li>if </li></ul><ul><li>otherwise </li></ul><ul><li>value-of </li></ul>
  16. 16. Inherited XPath Functions <ul><li>count() –Returns the no of nodes </li></ul><ul><li>substring() -------- substring(string,start,length) </li></ul><ul><li>name() </li></ul><ul><li>Position() </li></ul><ul><li>Concat() </li></ul><ul><li>contains() </li></ul><ul><li>Starts-with() </li></ul><ul><li>String() </li></ul><ul><li>String-length() </li></ul>
  17. 17. Processing of XML through Java <ul><li>Rerquirements </li></ul><ul><li>Set classpath to Xalan.jar/Xerces.jar parser. </li></ul><ul><li>Import javax.xml.transform.*; </li></ul><ul><li>Import javax.xml.parsers.*; </li></ul><ul><li>Import org.w3c.dom.traversal.*; </li></ul><ul><li>import org.w3c.dom.*; </li></ul>
  18. 18. Processing ways <ul><li>DOM  A DOM parser reads an entire document. It then makes the tree for the entire document available to program code for reading and updating </li></ul><ul><li>SAX  Reading a document one piece at a time. It process the document on event based. </li></ul>
  19. 19. XML Transformation <ul><li>JAXP support transformation of xml and xslt in to a response tree. </li></ul>
  20. 20. Using CSS: <ul><li>Cascading Style Sheet (CSS) is a relatively simple tool that allows the developer to assign styles to HTML elements. CSS duplicates formatting built into HTML. It provides web developers with access to a large variety of formatting properties such as margins, line-height, word spacing and much more. </li></ul><ul><li>CSS is easy to learn and style sheets can be included directly in xml documents or can be saved as standalone text files. </li></ul>
  21. 21. Using CSS <ul><ul><ul><li><LINK HREF=”MyStylesheet.css” REL=”stylesheet” type=”text/css”> </li></ul></ul></ul><ul><ul><li>cd{ </li></ul></ul><ul><ul><li>display: block; </li></ul></ul><ul><ul><li>font-size:24pt; </li></ul></ul><ul><ul><li>padding:20pt; </li></ul></ul><ul><ul><li>font-wieght: bold; </li></ul></ul><ul><ul><li>color: blue; </li></ul></ul><ul><ul><li>Text-align: center; </li></ul></ul><ul><ul><li>} </li></ul></ul>
  22. 22. <ul><ul><li>title{ </li></ul></ul><ul><ul><li>display:inline; </li></ul></ul><ul><ul><li>font-size:14pt; </li></ul></ul><ul><ul><li>padding:20pt; </li></ul></ul><ul><ul><li>font-weight:bold; </li></ul></ul><ul><ul><li>color:red; </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>artist{ </li></ul></ul><ul><ul><li>display:block; </li></ul></ul><ul><ul><li>text-align:center; </li></ul></ul><ul><ul><li>font-size:14pt; </li></ul></ul><ul><ul><li>padding:20pt; </li></ul></ul><ul><ul><li>font-weight:bold; </li></ul></ul><ul><ul><li>color:green; </li></ul></ul><ul><ul><li>} </li></ul></ul>
  23. 23. XSL:FO Introduction <ul><li>XSL-FO is an XML based markup language describing the formatting of XML data for output to screen, paper or other media. </li></ul><ul><li>XSL-FO stands for Extensible Stylesheet Language Formatting Objects </li></ul><ul><li>XSL-FO is a W3C Recommendation </li></ul>
  24. 24. XSL-FO Documents <ul><li>XSL-FO documents are XML files with output information. They contain information about the output layout and output contents. </li></ul><ul><li>XSL-FO documents are stored in files with a *.fo or a *.fob extension. It is also quite normal to see XSL-FO documents stored with the *.xml extension, because this makes them more accessible to XML editors. </li></ul>
  25. 25. Structure of XSL:FO <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> </li></ul><ul><li><fo:root xmlns:fo=&quot;http://www.w3.org/1999/XSL/Format&quot;><fo:layout-master-set> </li></ul><ul><li><fo:simple-page-master master-name=&quot;A4&quot;> </li></ul><ul><li><!-- Page template goes here --> </li></ul><ul><li></fo:simple-page-master> </li></ul><ul><li></fo:layout-master-set> </li></ul><ul><li><fo:page-sequence master-reference=&quot;A4&quot;> </li></ul><ul><li><!-- Page content goes here --></fo:page-sequence> </li></ul><ul><li></fo:root> </li></ul>
  26. 26. Examples: <ul><li>Invoice.xml </li></ul><ul><li>invoice.xsl </li></ul><ul><li>Invoice.fo </li></ul>
  27. 27. <ul><li>THANK YOU .. </li></ul>

×