Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
  XML/XSLT Aravinda.J
Contents Introduction to XML XML in web application Java Parsers  XSLT XSLT:FO Examples Usage of XML,XSLT,XSLT:FO in EDI
XML What is XML? XML stands for E X tensible  M arkup  L anguage  XML is a  markup language  much like HTML  XML was designed to  describe data   XML tags are not predefined. You must  define your own tags   XML uses a  Document Type Definition  (DTD) or an  XML Schema  to describe the data  XML was designed to store, carry, and exchange data. XML was not designed to display data.
The main difference between  XML and HTML XML is not a replacement for HTML. XML and HTML were designed with different goals: 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.
The following example is a note to Tove from Jani, stored as XML: <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>  <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
How can XML be Used? It is important to understand that XML was designed to store, carry, and exchange data. XML was not designed to display data. With XML, your data is stored outside your HTML. With XML, data can be exchanged between incompatible systems.
XML and B2B With XML, financial information can be exchanged over the Internet. XML can be used to Share Data XML can be used to Store Data XML is the mother of WAP and WML. The Wireless Markup Language (WML), used to markup Internet applications for handheld devices like mobile phones, is written in XML.
XML Syntax The syntax rules of XML are very simple and very strict. The rules are very easy to learn, and very easy to use. 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.  The next line describes the root element of the document (like it was saying: &quot;this document is a note&quot;):
XML SYNTAX All XML elements must have a closing tag XML tags are case sensitive All XML elements must be properly nested All XML documents must have a root element Attribute values must always be quoted
DISPLAYING XML CONTENT THROUGH XSL/JAVA/CSS XSL stands for e X tensible  S tylesheet  L anguage. The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML based Stylesheet Language.  XML does not use predefined tags (we can use any tags we like) and the meanings of these tags are  not well understood . The <table> could mean an HTML table or a piece of furniture, and a browser  does not know how to display it . There must be something in addition to the XML document that describes how the document should be displayed; and that is XSL!
XSLT Demonstration XML Doc XML Processor (xsltproc) XSLT Stylesheet PDF XML HTML
XSL - More Than a Style Sheet Language XSLT is a language for transforming XML documents  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.  XPath is a language for defining parts of an XML document  XSL-FO is a language for formatting XML documents
WORKING OF XSLT XSLT Uses XPath XSLT uses XPath to define the matching patterns for transformations. If you want to study XPath first, please read our  XPath Tutorial . How does it Work? 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.
Examples: cdcatalog.xml cdcatalog.xsl
Elements in XSLT apply-imports   apply-templates   call-template   choose   decimal-format   for-each   if   otherwise   value-of
Inherited XPath Functions   count()  –Returns the no of nodes substring()  -------- substring(string,start,length)  name()   Position()   Concat()   contains()   Starts-with()   String()   String-length()
Processing of XML through Java Rerquirements Set classpath to Xalan.jar/Xerces.jar parser. Import javax.xml.transform.*; Import javax.xml.parsers.*; Import org.w3c.dom.traversal.*; import org.w3c.dom.*;
Processing ways 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  SAX   Reading a document one piece at a time. It process the document on event based.
XML Transformation JAXP support transformation of xml and xslt in to a response tree.
Using CSS: 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. CSS is easy to learn and style sheets can be included directly in xml documents or can be saved as standalone text files.
Using CSS <LINK HREF=”MyStylesheet.css” REL=”stylesheet” type=”text/css”> cd{ display: block; font-size:24pt; padding:20pt; font-wieght: bold; color: blue; Text-align: center; }
title{ display:inline; font-size:14pt; padding:20pt; font-weight:bold; color:red; } artist{ display:block; text-align:center; font-size:14pt; padding:20pt; font-weight:bold; color:green; }
XSL:FO Introduction XSL-FO is an XML based markup language describing the formatting of XML data for output to screen, paper or other media. XSL-FO stands for Extensible Stylesheet Language Formatting Objects  XSL-FO is a W3C Recommendation
XSL-FO Documents XSL-FO documents are XML files with output information. They contain information about the output layout and output contents. 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.
Structure of XSL:FO <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <fo:root xmlns:fo=&quot;http://www.w3.org/1999/XSL/Format&quot;><fo:layout-master-set>  <fo:simple-page-master master-name=&quot;A4&quot;> <!-- Page template goes here -->  </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference=&quot;A4&quot;>  <!-- Page content goes here --></fo:page-sequence> </fo:root>
Examples: Invoice.xml invoice.xsl Invoice.fo
THANK YOU ..

More Related Content

XML/XSLT

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