Introduction to XSL Hudson Ummem Veloso (huv) Luciano de Moura Silva (lms4)
12/02/ Introduction What is XSL? –XSL stands for E X tensible S tylesheet L anguage –XSL is a style sheet language applied in archives XML But what is a Style Sheet? –A list of page format specifications, including typographic and layout specifications, that, when applied to structured information, provides a particular rendering of that information. –Different style sheets may be applied to the same piece of structured information to produce different presentations of the information.
12/02/ Introduction How XSL will be used in the BrazilIP? –Formatting of archives XML –Create the PDF files for documentation –Create the HTML files to make use in the Internet Why to use XML and XSL? –The XML validation can be automatized –The XSL is recommended for W3C for formatting the XML files –The XSL is more powerfull than CSS
12/02/ Introduction XSL components –XSLT - a language for transforming XML documents –XPath - a language for navigating in XML documents –XSL-FO - a language for formatting XML documents
12/02/ XSLT What is XSLT? –XSLT stands for XSL Transformations –XSLT transforms an XML document into another XML document –XSLT uses XPath to navigate in XML documents
12/02/ XSLT How does it works –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. Brazil IP...
12/02/ XSLT – Transformation How to create a HTML document with the following XML document? example.xml Brazil IP Fênix Configuração rgo drm 5 …
12/02/ XSLT - Transformation Create the XSL template example1.xsl (open the example.xml with browser) GroupName: NumberofMembers:
12/02/ XSLT – The element is used to extract the value of a selected node Modif link (href) in the example.xml for example2.xsl and view with browser GroupName: LeaderOne:
12/02/ XSLT - The element allows you to do looping in XSLT Modif link (href) in the example.xml for example3.xsl and view with browser GroupName: NumberofMembers:
12/02/ XSLT - The element is used to sort the output. Modif link (href) in the example.xml for example4.xsl and view with browser GroupName: NumberofMembers:
12/02/ XSLT - The element is used to put a conditional test against the content of the XML file. –Syntaxe: Where to put the element? –To add a conditional test, add the element inside the element in the XSL file:......some output if the expression is true......
12/02/ XSLT - View the example above Modif link (href) in the example.xml for example5.xsl and view with browser GroupName:
12/02/ XSLT - The element is used in conjunction with and to express multiple conditional tests. The element is used for simulation of if then else structure –Syntaxe : Where to put the Choose Condition? –To insert a conditional choose test against the content of the XML file, add the,, and elements to the XSL file:... some output some output....
12/02/ XSLT - Modif link (href) in the example.xml for example6.xsl and view with browser GroupName: GroupName:
12/02/ XSLT - The element applies a template to the current element or to the current element's child nodes. Modif link (href) in the example.xml for example7.xsl and view with browser GroupName:
12/02/ XPath and XSLT – basics functions Context functions: Modif link (href) in the example.xml for example8.xsl and view with browser GroupName: NumberofMembers:
12/02/ XPath and XSLT – basics functions Functions on Boolean values: Modif link (href) in the example.xml for example9.xsl and view with browser GroupName: NumberofMembers:
12/02/ XPath and XSLT – basics functions Arithmetic functions: –sum(node set) - this function sums up all the values in the set of nodes –floor(number) returns the largest integer that is not greater than number Example: floor(2.5) returns 2 –ceiling(number) returns the smallest integer that is not less than number Example. Ceiling(2.5) returns 3 –round(number) returns the integer closest to number Example. round(2.3) returns 2 NumberofMembers in the USB host project:
12/02/ XPath and XSLT – basics functions String functions: –string(arg) - returns the string value of the argument. The argument could be a number, boolean, or node-set Example: string(314) –Result: “314” –string-length(string) - returns the length of the specified string. Example: string-lenght(‘Brazil-IP’) –Result: 9 –concat(string,string,...) - returns the concatenation of the strings Example: concat(‘Brazil’,‘-’,’IP’,) –Result: “Brazil-IP” –translate(string1,string2,string3) – Converts string1 by replacing the characters in string2 with the characters in string3 Example: translate('12:30',‘0123',‘abcd') –Result: “bc:da”
12/02/ XPath and XSLT – basics functions Group Name Leader1 Leader2 Length String Modif link (href) in the example.xml for example11.xsl and view with browser
12/02/ XSLT - elements –The element is used to add attributes to elements. yellow Modif link (href) in the example.xml for example12.xsl and view with browser
12/02/ XSLT - elements –The element writes a message to the output. This element is primarily used to report errors This line is pair Modif link (href) in the example.xml for example13.xsl and view with browser
12/02/ XSLT XSLT Processors –Saxon ( is a free processor written in Javahttp://saxon.sourceforge.net/ –Xalan ( is part of the Apache XML Project. It has versions written in both Java and C++, both of them freehttp://xml.apache.org/xalan-j/index.html –xsltproc ( processor is written in C. It is free and is considered the fastest of the processorshttp://xmlsoft.org/XSLT/ –Microsoft's MSXML ( engine includes an XSLT processor. It is reported to be fast, but only runs on Windowshttp://msdn.microsoft.com/xml/
12/02/ XSLT How to generate a HTML file from a XML and a XSL files –First we have to get the fop.zip from Apache.orgApache.org –Then use the xalan command xalan -in inputFile.xml -out outputFile.html
12/02/ XSL-FO What is XSL-FO? –XSL-FO stands for Extensible Stylesheet Language Formatting Objects –XSL-FO is an XML-based markup language describing the formatting of XML data for output to screen, paper or other media.
12/02/ XSL-FO XSL-FO document structure
12/02/ XSL-FO XSL-FO Areas –XSL-FO uses rectangules boxes (areas) to display output Pages Regions Block areas Line areas Inline areas
12/02/ XSL-FO XSL-FO Areas –Pages contain margin-top margin-bottom margin-left margin-right Regions –Regions contain region-body region-before region-after region-start region-end Block areas
12/02/ XSL-FO
12/02/ XSL-FO XSL-FO Areas –Block Areas Block areas defines small block elements like paragraphs, tables and lists Can contain other Block areas, but most often they contain Line areas –Line Areas Define text lines inside Block areas Contain Inline areas –Inline Areas Define text inside Lines (bullets, single character, graphics)
12/02/ XSL-FO A real XSL-FO example Hello Brazil_IP
12/02/ XSL-FO Templates <fo:simple-page-master master-name="capa" page-width="297mm" page-height="210mm" margin-top="3cm" margin-bottom="3cm" margin-left="2cm" margin-right="2cm"> <fo:simple-page-master master-name="A4" page-width="297mm" page-height="210mm" margin-top="1cm" margin-bottom="1cm" margin-left="1cm" margin-right="1cm">
12/02/ XSL-FO XSL-FO Processors –XSL Formatter ( –Xinc Beta Release ( A Swing based XSL-FO viewer allows you to view and print XSL-FO files as well as generate PDF files with the click of a button. –FOP ( It is a free Java application that reads a formatting object (FO) tree and renders the resulting pages to a specified output.
12/02/ XSL-FO How to generate a PDF file from a XML and a XSL files –Use the xalan command to create the FO file –Then use the fop comand to generate the PDF xalan -in inputFile.xml -out outputFile.fo fop -fo inputFile.fo -pdf outputFile.pdf
12/02/ XSL-FO You also can generate a PS file –Use the xalan command to create the FO file –Then use the fop comand to generate the PS xalan -in inputFile.xml -out outputFile.fo fop -fo inputFile.fo -ps outputFile.ps
12/02/ Study Bibliography – This site have some tutorials about XML, HTML, CSS and XSL for beginners. – A reference guide about XSL. – A guide to generate PDF files from a XSL-FO. – A complete source with tutorials an reference guides about XML, XSLT, XSL-FO, CSS and others. – Where to download the FOP XSL-FO Processor.