SlideShare a Scribd company logo
1 of 89
Download to read offline
XSL
Dr.S.Roselin Mary
HOD/CSE
ANAND INSTITUTE OF HIGHER TECHNOLOGY
• XSL stands for EXtensible Stylesheet Language. It is similar to XML
as CSS is to HTML.
Need for XSL
• In case of HTML document, tags are predefined such as table, div,
and span; and the browser knows how to add style to them and
display those using CSS styles.
• But in case of XML documents, tags are not predefined. In order to
understand and style an XML document, World Wide Web
Consortium (W3C) developed XSL which can act as XML based
Stylesheet Language.
• An XSL document specifies how a browser should render an XML
document.
• Following are the main parts of XSL −
– XSLT − used to transform XML document into various other types of
document.
– XPath − used to navigate XML document.
– XSL-FO − used to format XML document.
What is XSLT
• XSLT, Extensible Stylesheet Language Transformations, provides the ability
to transform XML data from one format to another automatically.
How XSLT Works
• An XSLT stylesheet is used to define the transformation rules to be applied
on the target XML document.
• XSLT stylesheet is written in XML format. XSLT Processor takes the XSLT
stylesheet and applies the transformation rules on the target XML
document and then it generates a formatted document in the form of
XML, HTML, or text format.
• This formatted document is then utilized by XSLT formatter to generate
the actual output which is to be displayed to the end-user.
Advantages
• Independent of programming. Transformations are written in a separate
xsl file which is again an XML document.
• Output can be altered by simply modifying the transformations in xsl file.
No need to change any code. So Web designers can edit the stylesheet
and can see the change in the output quickly.
students.xml
<?xml version = "1.0"?>
<class>
<student rollno = "393">
<firstname>Dinkar</firstname>
<lastname>Kad</lastname>
<nickname>Dinkar</nickname>
<marks>85</marks>
</student>
<student rollno = "493">
<firstname>Vaneet</firstname>
<lastname>Gupta</lastname>
<nickname>Vinni</nickname>
<marks>95</marks>
</student>
<student rollno = "593">
<firstname>Jasvir</firstname>
<lastname>Singh</lastname>
<nickname>Jazz</nickname>
<marks>90</marks>
</student>
</class>
We need to define an XSLT style sheet document for the above XML document to
meet the following criteria −
•Page should have a title Students.
•age should have a table of student details.
•Columns should have following headers: Roll No, First Name, Last
Name, Nick Name, Marks
Step 1: Create XSLT document
Create an XSLT document to meet the above requirements, name it as students.xsl and save it in the same location
where students.xml lies.
students.xsl
<?xml version = "1.0" encoding = "UTF-8"?>
<!-- xsl stylesheet declaration with xsl namespace:
Namespace tells the xlst processor about which
element is to be processed and which is used for output purpose only
-->
<xsl:stylesheet version = "1.0“ xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<!-- xsl template declaration:
template tells the xlst processor about the section of xml
document which is to be formatted. It takes an XPath expression.
In our case, it is matching document root element and will
tell processor to process the entire document with this template.
-->
<xsl:template match = "/">
<!-- HTML tags
Used for formatting purpose. Processor will skip them and browser
will simply render them.
-->
<html>
<body>
<h2>Students</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Roll No</th>
<th>First Name</th>
<!-- for-each processing instruction
Looks for each element matching the XPath expression
-->
<xsl:for-each select="class/student">
<tr>
<!-- value-of processing instruction
process the value of the element matching the XPath expression
-->
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "nickname"/></td>
<td><xsl:value-of select = "marks"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Step 2: Link the XSLT Document to the XML Document
Update student.xml document with the following xml-stylesheet tag. Set href value to students.xsl
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "students.xsl"?>
<class>
...
</class>
Step 3: View the XML Document in Internet Explorer
students.xml
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "students.xsl"?>
<class>
<student rollno = "393">
<firstname>Dinkar</firstname>
<lastname>Kad</lastname>
<nickname>Dinkar</nickname>
<marks>85</marks>
</student>
<student rollno = "493">
<firstname>Vaneet</firstname>
<lastname>Gupta</lastname>
<nickname>Vinni</nickname>
<marks>95</marks>
</student>
<student rollno = "593">
<firstname>Jasvir</firstname>
<lastname>Singh</lastname>
<nickname>Jazz</nickname>
<marks>90</marks>
</student>
</class>
XSLT Features
XSLT <template>
Name & Description
1
name
Name of the element on which template is to be applied.
2
match
Pattern which signifies the element(s) on which template is to be applied.
3
priority
Priority number of a template. Matching template with low priority is not considered in from in front of high priority
template.
4
mode
Allows element to be processed multiple times to produce a different result each time.
<xsl:template> defines a way to reuse templates in order to generate the desired output for nodes
of a particular type/context.
Declaration
Following is the syntax declaration of <xsl:template> element.
<xsl:template
name = Qname
match = Pattern
priority = number
mode = QName >
</xsl:template>
Attributes
Number of occurrences Unlimited
Parent elements xsl:stylesheet, xsl:transform
Child elements
xsl:apply-imports,xsl:apply-templates,xsl:attribute, xsl:call-template, xsl:choose,
xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:fallback, xsl:for-each, xsl:if,
xsl:message, xsl:number, xsl:param, xsl:processing-instruction, xsl:text, xsl:value-
of, xsl:variable, output elements
Elements
students_imports.xsl
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>Students</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Roll No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Nick Name</th>
<th>Marks</th>
</tr>
<xsl:for-each select = "class/student">
<tr>
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "nickname"/></td>
<td><xsl:value-of select = "marks"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XSLT <value-of>
Sr.No Name & Description
1
Select
XPath Expression to be evaluated in current context.
2
disable-outputescaping
Default-"no". If "yes", output text will not escape xml characters from text.
<xsl:value-of> tag puts the value of the selected node as per XPath expression, as text.
Declaration
Following is the syntax declaration of <xsl:value-of> element.
<xsl:value-of
select = Expression
disable-output-escaping = "yes" | "no" >
</xsl:value-of>
Attributes
Number of Occurrences Unlimited
Parent elements xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if,
xsl:message, xsl:otherwise, xsl:param, xsl:processing instruction, xsl:template,
xsl:variable, xsl:when, xsl:with-param, output elements
Child elements None
Elements
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>Students</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Roll No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Nick Name</th>
<th>Marks</th>
</tr>
<xsl:for-each select = "class/student">
<tr>
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "nickname"/></td>
<td><xsl:value-of select = "marks"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XSLT <sort>
Sr.No Name & Description
1
select
Sorting key of the node.
2
lang
Language alphabet used to determine sort order.
3
data-type
Data type of the text.
4
order
Sorting order. Default is "ascending".
5
case-order
<xsl:sort> tag specifies a sort criteria on the nodes.
Declaration
Following is the syntax declaration of <xsl:sort> element.
<xsl:sort
select = string-expression
lang = { nmtoken }
data-type = { "text" | "number" | QName }
order = { "ascending" | "descending" }
case-order = { "upper-first" | "lower-first" } >
</xsl:sort>
Attributes
Number of occurrences Unlimited
Parent elements xsl:apply-templates, xsl:for-each
Child elements None
Elements
students.xsl
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>Students</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Roll No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Nick Name</th>
<th>Marks</th>
</tr>
<xsl:for-each select = "class/student">
<xsl:sort select = "firstname"/>
<tr>
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "nickname"/></td>
<td><xsl:value-of select = "marks"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XSLT <if>
Sr.No Name & Description
1
test
The condition in the xml data to test.
Number of Occurrences Unlimited
Parent elements
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if,
xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template,
xsl:variable, xsl:when, xsl:with-param, output elements
Child elements
xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy,
xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text,
xsl:value-of, xsl:variable, output elements
<xsl:if> tag specifies a conditional test against the content of nodes.
Declaration
Following is the syntax declaration of <xsl:if> element.
<xsl:if
test = boolean-expression >
</xsl:if>
Attributes
Elements
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>Students</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Roll No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Nick Name</th>
<th>Marks</th>
</tr>
<xsl:for-each select = "class/student">
<xsl:if test = "marks > 90">
<tr>
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "nickname"/></td>
<td><xsl:value-of select = "marks"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XSLT processors
Two techniques for performing XSLT processing
• client-side processing
• server-side processing.
Client-side XSLT processing
• Client-side XSLT processing commonly occurs in a Web browser.
• The Web browser includes an XSLT processor and retrieves the XML
document and XSL style sheet
• The client-side technique offloads the XSLT processing to the client
machine. This minimizes the workload on the Web server.
• However, the Web browser must provide XSLT support.
• E.g: Netscape Communicator 6 , Microsoft Internet Explorer 6
support the XSLT 1.0 specification
• For client-side processing, the XML document
requires a special processing instruction to
reference the XSL style sheet.
• The processing instruction is <?xml-
stylesheet>
– it has two attributes: type and href.
• The type attribute specifies the content type of the
document to be retrieved (in this case, text/xsl).
• The href attribute is a URL reference to the style sheet.
The href attribute supports absolute and relative URL
references.
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "students.xsl"?>
<class>
<student rollno = "393">
<firstname>Dinkar</firstname>
<lastname>Kad</lastname>
<nickname>Dinkar</nickname>
<marks>85</marks>
</student>
<student rollno = "493">
<firstname>Vaneet</firstname>
<lastname>Gupta</lastname>
<nickname>Vinni</nickname>
<marks>95</marks>
</student>
<student rollno = "593">
<firstname>Jasvir</firstname>
<lastname>Singh</lastname>
<nickname>Jazz</nickname>
<marks>90</marks>
</student>
</class>
Students.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>Students</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Roll No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Nick Name</th>
<th>Marks</th>
</tr>
<xsl:for-each select = "class/student">
<tr>
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "nickname"/></td>
<td><xsl:value-of select = "marks"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Students.xsl
Output at the web browser
• Server-side XSLT processing occurs on the Web server or application server.
• A serverside process such as an Active Server Page (ASP), JavaServer Page
(JSP), or Java servlet will retrieve the XML document and XSL style sheet and
pass them to an XSLT processor.
• The output of the XSLT processor is sent to the client Web browser for
presentation.
• The output is generally a markup language, such as HTML, that is understood
by the client browser.
server-side XSLT processing
• An advantage of the server-side technique is browser
independence. This technique supports the older browser versions
and makes the application more robust and versatile.
• Also, by utilizing the server-side technique, the application can
support a diverse collection of clients.
• The application can detect the user-agent, such as a WAP-enabled
mobile phone, and send back a document containing a Wireless
Markup Language (WML) tag.
• The WAP-enabled phone can render the content using the built-in
WML mini-browser.
• A number of server-side technologies are available, including Common
Gateway Interface (CGI), ColdFusion, Hypertext Processor (PHP), and so
on.
• Microsoft’s Active Server Pages (ASP) and Sun Microsystems’ JavaServer
Pages (JSP).
ASP: Server-Side XSLT Processing
Required components:
– Microsoft IIS Web Server 5.0. This version of IIS is included with Microsoft
Windows 2000 Professional. We can also use IIS 4.0 or Personal Web Server
(PWS); But, we have to install the Windows NT Option Pack 4.
– Microsoft XML Parser 3.0 If we have IE 6 installed on our server machine, then
Microsoft XML Parser 3.0 is included. The MS XML Parser 3.0 is also available
as a separate download from http://msdn.microsoft.com.
• we have two options for publishing the source code on the IIS server:
– Copy the students.xml and students.xsl files in to c:Inetpubwwwroot.
– Set up a virtual directory that points to the xml file location
<%@ Language=VBScript %>
<%
set xml = Server.CreateObject(“Microsoft.XMLDOM”)
xml.load(Server.MapPath(“students.xml”))
set xsl = Server.CreateObject(“Microsoft.XMLDOM”)
xsl.load(Server.MapPath(“students.xsl”))
Response.Write(xml.transformNode(xsl))
%>
Students.asp
A Web browser rendering HTML
JSP: Server-Side XSLT Processing
• Sun Microsystems provides a server-side technology that is
very similar to ASP. The server-side scripting is
accomplished in Java.
Required components:
– Sun Microsystems’ Software Development Kit (SDK) 1.3 (or
higher). The SDK is available at Sun’s Web site,
http://java.sun.com/j2se. Follow the installation instructions
provided with the SDK.
– Apache Tomcat Server 4. Apache Tomcat 4 is the official
reference implementation for JSP 1.2 and Java Servlets 2.3.
– If the application server already supports JSP 1.1 or higher,
there is no requirement to install Tomcat. Apache Tomcat 4 is
available from the Apache Web site,
http://jakarta.apache.org/tomcat. Follow the
– installation instructions provided with the Tomcat server.
• Once Tomcat 4 is installed, add a new Web
application that points to the source code
directory. This is done by editing the file
<tomcat_install_dir>confserver.xml
• Move to the section where the <Context>
elements are listed and then add the following
entry:
<Context path=”/myapp”
docBase=”c://documents/mypgm/serverpgm”
debug=”0”
reloadable=”true” />
• Restart the Tomcat server to pick up the new configuration. By
default, the Tomcat server is listening on port 8080.
• we can access files for the myapp Web application using the
URL http://localhost:8080/myapp/students.jsp.
• A JSP custom tag is a special tag that is created by a developer.
• When the JSP server encounters the custom tag, it executes
the handler code associated with the tag.
• JSP custom tags are conceptually similar to ASP server objects.
• However, the custom action is represented in the JSP page as a
custom tag instead of scripting code.
• The Apache <jakarta:apply> tag provides the XSLT processing.
<%@ taglib uri=”http://jakarta.apache.org/taglibs/xsl-1.0” prefix=”jakarta” %>
<jakarta:apply xml=”students.xml” xsl=”students.xsl” />
c://documents/mypgm/serverpgm/students.jsp
• The first line in this example informs the JSP server to use the tag
library that is identified by the URI
http://jakarta.apache.org/taglibs/xsl-1.0. This URI is defined in the
Web application’s deployment description.
– The URI is actually mapped to the file jakarta-xsl.tld, located in the
directory c://documents/mypgm/serverpgm/WEBINF.
– The file jakarta-xsl.tld is the Tag Library Descriptor (TLD). The TLD file
provides a description of the custom tags available in the class library.
It also provides a mapping between the custom tag name and the tag
handler class.
– The tag handler class is located in the directory
c://documents/mypgm/serverpgmWEB-INFlib.
• The next line of code is the actual <jakarta:apply> tag. This tag has
two attributes—
– one defines the XML input source and the other defines the XSL style
sheet.
• The results of the XSLT process are returned to the Web browser.
To test this example, make sure the Tomcat server is running. In a
Web browser, access the JSP with the URL
http://localhost:8080/myapp/students.jsp.
XSL for Business-to-Business (B2B)
Communication
• XSLT can also be used in for B2B communication—the
process of exchanging data between two different
companies.
• Developers can leverage XML to describe the data in a
vendor-independent fashion. In the ideal case, both
companies will agree upon a standard vocabulary for
describing the data using a DTD or schema.
• The vocabulary is composed of the XML element names used
in the XML document.
• However, in certain cases one of the companies might like to
use a different vocabulary. This is where XSL enters the
picture.
Scenario
• The computer training company maintains a database for
the students that have attended its courses. The training
company has developed an XML application that produces
the list of students for a given class.
• The management team at software development company
would like to retrieve this list from the training company’s
XML application.
• However, once the data is retrieved, software
development company would like to store the data in a
different XML format using its own XML element names.
• The XML application at the training company is accessible using the
HTTP protocol.
• The first step is to request the XML document from the training
company.
• In step 2, the XML document is retrieved.
• In step 3, the document is transformed using the supplied XSLT style
sheet.
• Finally, the desired output document is produced in step 4.
Training
company
Software
development
company
<?xml version=”1.0”?>
<trainingclass>
<title>J2EE Essentials</title>
<start_date>24 Sep 2001</start_date>
<end_date>28 Sep 2001</end_date>
<location>Philadelphia, PA</location>
<student>
<first_name>Riley</first_name>
<last_name>Scott</last_name>
<email>riley@acmesoft.web</email>
</student>
<student>
<first_name>Torrance</first_name>
<last_name>Lee</last_name>
<email>torrance.lee@acmesoft.web</email>
</student>
</trainingclass>
Training company’s XML
<?xml version=”1.0”?>
<employeelist>
<course_title>J2EE Essentials</course_title>
<course_date start=”24 Sep 2001” end=”28 Sep 2001” />
<location>Philadelphia, PA</location>
<employee>
<name>
<first>Riley</first>
<last>Scott</last>
</name>
<email>riley.scott@acmesoft.web</email>
</employee>
<employee>
<name>
<first>Torrance</first>
<last>Lee</last>
</name>
<email>torrance.lee@acmesoft.web</email>
</employee>
</employeelist>
Software development company’s xml
• Therefore, a mechanism is needed to convert an XML
document to another XML format.
• XSLT offers a solution to this problem. An XSL style sheet
can be developed to convert the <trainingclass> document
to the <employeelist> document.
• This approach will not require any changes by the training
company. The training company can continue to publish
XML documents for its training classes.
• The development team can develop an XSL style sheet that
contains the transformation rules.
• Once the style sheet is developed, the XML document and
style sheet can be passed to the XSLT processor, which will
generate the desired XML document for <employeelist>.
• The training company describes the date for the class using the elements
<start_date> and <end_date>, as shown here:
<start_date>24 Sep 2001</start_date>
<end_date>28 Sep 2001</end_date>
• S/W development company stores the date as a single element with two attributes
for the start and end:
<course_date start=”24 Sep 2001” end=”28 Sep 2001” />
• In this case, <xsl:attribute> can be used to create attributes for <course_date>:
<course_date>
<xsl:attribute name=”start”>
<xsl:value-of select=”start_date”/>
</xsl:attribute>
<xsl:attribute name=”end”>
<xsl:value-of select=”end_date”/>
</xsl:attribute>
</course_date>
The <xsl:attribute> element creates attributes for the parent element. In this example,
the parent element is course_date. This transformation will result in the following
code:
<course_date start=”24 Sep 2001” end=”28 Sep 2001” />
<?xml version=”1.0”?>
<xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” version=”1.0”>
<xsl:template match=”/trainingclass”>
<employeelist>
<course_title><xsl:value-of select=”title” /></course_title>
<!-- create attributes for the start and end course dates -->
<course_date>
<xsl:attribute name=”start”>
<xsl:value-of select=”start_date”/>
</xsl:attribute>
<xsl:attribute name=”end”>
<xsl:value-of select=”end_date”/>
</xsl:attribute>
</course_date>
<location><xsl:value-of select=”location” /></location>
train2employee.xsl
<!-- Perform a loop for each student in the training class -->
<xsl:for-each select=”student”
<employee>
<name>
<first><xsl:value-of select=”first_name”/></first>
<last><xsl:value-of select=”last_name”/></last>
</name>
<email><xsl:value-of select=”email”/></email>
</employee>
</xsl:for-each>
</employeelist>
</xsl:template>
</xsl:stylesheet>
import org.apache.xalan.xslt.*;
/**
* Usage: java XslTester <input XML> <input XSL> <output file>
*/
public class XslTester
{
public static void main(String[] args)
{
try
{
// Verify the correct arguments are passed in
if (args.length != 3)
{
System.out.println(“Usage: java XslTester <input XML> <input XSL> <output file>”);
System.exit(1);
}
System.out.println(“Processing: “ + args[0] + “ and “ + args[1]);
// Step 1: Get a reference to the XSLT Processor
XSLTProcessor myEngine = XSLTProcessorFactory.getProcessor();
// Step 2: Get the XML input document
XSLTInputSource xmlSource = new XSLTInputSource(args[0]);
xslTester.java
// Step 3: Get the XSL style sheet
XSLTInputSource xslStylesheet = new XSLTInputSource(args[1]);
// Step 4: Setup the output target
XSLTResultTarget xmlOutput = new XSLTResultTarget(args[2]);
// Step 5: Now process it!
myEngine.process(xmlSource, xslStylesheet, xmlOutput);
System.out.println(“Created => “ + args[2]);
System.out.println(“Done!”);
}
catch (Exception exc) {
exc.printStackTrace();
}
}
}
XSL FO
7/29/2019 47Dr.S.Roselin Mary HOD/CSE
XSL Formatting Objects
• XSL-FO was designed to assist with the printing and displaying of XML
data.
• The main emphasis is on the document layout and structure. This includes
the dimensions of the output document, including page headers, footers,
and margins.
• XSL-FO also allows the developer to define the formatting rules for the
content, such as font, style, color, and positioning.
• XSL-FO is a sophisticated version of Cascading Style Sheets (CSS). In fact,
XSL-FO borrows a lot of the terminology and elements from CSS.
• XSL-FO documents are well-formed XML documents. An XSL-FO formatting
engine processes XSL-FO documents.
• Two techniques for creating XSL-FO documents:
1. simply develop the XSL-FO file with the included data.
2. dynamically create the XSL-FO file using an XSLT translation.
7/29/2019 48Dr.S.Roselin Mary HOD/CSE
XSL-FO Formatting Engines
7/29/2019 49Dr.S.Roselin Mary HOD/CSE
Basic Document Structure
XSL-FO elements use the following namespace: http://www.w3.org/1999/XSL/Format
<?xml version=”1.0” encoding=”utf-8”?>
<fo:root xmlns:fo=”http://www.w3.org/1999/XSL/Format”>
<!-- layout master set -->
<!-- page masters: size and layout -->
<!-- page sequences and content -->
</fo:root>
• The element <fo:root> is the root element for the XSL-FO document. An XSL-
FO document can contain the following components:
– • Page master  describes the page size and layout
– • Page master set  refers to the collection of page masters
– • Page sequences  defines a series of printed pages. The page sequence
contains the actual content for the document
7/29/2019 50Dr.S.Roselin Mary HOD/CSE
• The <fo:simple-page-master> element defines
the layout of a page.
<fo:simple-page-master master-name=”simple”
page-height=”11in”
page-width=”8.5in”
margin-top=”1in”
margin-bottom=”1in”
margin-left=”1.25in”
margin-right=”1.25in” >
</fo:simple-page-master>
7/29/2019 51Dr.S.Roselin Mary HOD/CSE
XSL-FO Dimensions
7/29/2019 52Dr.S.Roselin Mary HOD/CSE
• To set the page height to 210 millimeters, use the
following syntax:
page-height=”210mm”
• The <fo:simple-page-master> element can also be used
to describe an A4 letter (height 210 mm and width 297
mm):
<fo:simple-page-master master-name=”A4-example”
page-height=”210mm”
page-width=”297mm”
margin-top=”0.5in”
margin-bottom=”0.5in”
margin-left=”0.5in”
margin-right=”0.5in” >
</fo:simple-page-master>
7/29/2019 53Dr.S.Roselin Mary HOD/CSE
• Each page is divided into five regions. Regions serve as containers for the
document content.
• The region-before and region-after areas are commonly used for page
headers and footers.
• The region-body area is the center of the page and contains the main
content.
• The region-start and region-end sections are commonly used for left and
right sidebars, respectively.
• In the definition of a page master, specify the size of the regions using the
following elements:
• <fo:region-before>
• <fo:region-after>
• <fo:region-body>
• <fo:region-start>
• <fo:region-end>
7/29/2019 54Dr.S.Roselin Mary HOD/CSE
7/29/2019 55Dr.S.Roselin Mary HOD/CSE
<fo:simple-page-master master-name=”simple”
page-height=”11in”
page-width=”8.5in” >
<fo:region-body margin-top=”0.5in”/>
<fo:region-before extent=”0.5in”/>
<fo:region-after extent=”0.5in”/>
</fo:simple-page-master>
• The extent attribute has a different meaning,
depending on the region.
• For <fo:region-end> and <fo:region-start>, the
extent attribute specifies the width.
• For <fo:region-before> and <fo:region-after>, it
specifies the height.
7/29/2019 56Dr.S.Roselin Mary HOD/CSE
Page Master Set: <fo:page-master-set>
• A document can be composed of multiple pages, each with its own
dimensions.
• The page master set refers to the collection of page masters.
<fo:layout-master-set>
<fo:simple-page-master master-name=”simple”
page-height=”11in”
page-width=”8.5in”
margin-top=”1in”
margin-bottom=”1in”
margin-left=”1.25in”
margin-right=”1.25in”>
<fo:region-body margin-top=”0.5in”/>
<fo:region-before extent=”3cm”/>
<fo:region-after extent=”1.5cm”/>
</fo:simple-page-master>
</fo:layout-master-set>
7/29/2019 57Dr.S.Roselin Mary HOD/CSE
<?xml version=”1.0” encoding=”utf-8”?>
<fo:root xmlns:fo=”http://www.w3.org/1999/XSL/Format”>
<!-- layout master set -->
<fo:layout-master-set>
<!-- page masters: size and layout -->
<fo:simple-page-master master-name=”simple”
page-height=”11in”
page-width=”8.5in”
margin-top=”1in”
margin-bottom=”1in”
margin-left=”1.25in”
margin-right=”1.25in”>
<fo:region-body margin-top=”0.5in”/>
<fo:region-before extent=”3cm”/>
<fo:region-after extent=”1.5cm”/>
</fo:simple-page-master>
</fo:layout-master-set>
<!-- page sequences and content -->
</fo:root>
Simplepagemaster.fo
7/29/2019 58Dr.S.Roselin Mary HOD/CSE
Page Sequences: <fo:page-sequence>
• A page sequence defines a series of printed
pages.
• Each page sequence refers to a page master
for its dimensions.
• The page sequence contains the actual
content for the document.
• The <fo:page-sequence> element contains
– <fo:static-content>
– <fo:flow>
7/29/2019 59Dr.S.Roselin Mary HOD/CSE
1. The <fo:static-content> element is used for page headers
and footers.
E.g:
we can define a header for the company name and page
number, and this information will appear on every page.
2. The <fo:flow> element contains a collection of text blocks.
– The <fo:flow> element is similar to a collection of paragraphs.
– A body of text is defined using the <fo:block> element.
• The <fo:block> element is a child element of <fo:flow>.
• The <fo:block> element contains free-flowing text that will wrap to
the next line in a document if it overflows.
• In this example
7/29/2019 60Dr.S.Roselin Mary HOD/CSE
<fo:page-sequence master-name=”simple”>
<fo:flow flow-name=”xsl-region-body”>
<!-- this defines a level 1 heading with orange background -->
<fo:block font-size=”18pt”
font-family=”sans-serif”
line-height=”24pt”
space-after.optimum=”15pt”
background-color=”orange”
color=”white”
text-align=”center”
padding-top=”3pt”>
Ez Books Online
</fo:block>
<!-- Paragraph that contains info about the company -->
<fo:block font-size=”12pt”
font-family=”sans-serif”
line-height=”15pt”
space-after.optimum=”14pt”
text-align=”justify”>
Welcome to Ez Books Online, the world’s smallest online book store.
Our company’s mission is to sell books on Java, Thrillers and Romance.
We have something for everyone...so we think. Feel free to browse our
catalog and if you find a book of interest then send us an e-mail.
Thanks for visiting!
</fo:block>
</fo:flow>
</fo:page-sequence>
7/29/2019 61Dr.S.Roselin Mary HOD/CSE
• The <fo:flow> element has to specify a region for its
content.
E.g: the content is placed in the main body region.
• The first <fo:block> element defines a heading with an
orange background.
• The content of each <fo:block> can be customized
using font and line attributes.
• The second <fo:block> element contains information
about the company.
• The text for <fo:block> is free flowing. The text will
automatically wrap.
• Ample space is provided at the end of the paragraph
using the space-after.optimum attribute.
7/29/2019 62Dr.S.Roselin Mary HOD/CSE
<?xml version=”1.0” encoding=”utf-8”?>
<fo:root xmlns:fo=”http://www.w3.org/1999/XSL/Format”>
<!-- layout master set -->
<fo:layout-master-set>
<!-- page masters: size and layout -->
<fo:simple-page-master master-name=”simple”
page-height=”11in”
page-width=”8.5in”
margin-top=”1in”
margin-bottom=”1in”
margin-left=”1.25in”
margin-right=”1.25in”>
<fo:region-body margin-top=”0.5in”/>
<fo:region-before extent=”3cm”/>
<fo:region-after extent=”1.5cm”/>
</fo:simple-page-master>
</fo:layout-master-set>
<!-- page sequences and content -->
<fo:page-sequence master-name=”simple”>
<fo:flow flow-name=”xsl-region-body”>
Simple.fo
7/29/2019 63Dr.S.Roselin Mary HOD/CSE
<!-- this defines a level 1 heading with orange background -->
<fo:block font-size=”18pt”
font-family=”sans-serif”
line-height=”24pt”
space-after.optimum=”15pt”
background-color=”orange”
color=”white”
text-align=”center”
padding-top=”3pt”>
Ez Books Online
</fo:block>
<!-- Paragraph that contains info about the company -->
<fo:block font-size=”12pt”
font-family=”sans-serif”
line-height=”15pt”
space-after.optimum=”14pt”
text-align=”justify”>
Welcome to Ez Books Online, the world’s smallest online book store.
Our company’s mission is to sell books on Java, Thrillers and Romance.
We have something for everyone...so we think. Feel free to browse our
catalog and if you find a book of interest then send us an e-mail.
Thanks for visiting!
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
7/29/2019 64Dr.S.Roselin Mary HOD/CSE
Generating a PDF Document
• Convert the XSL-FO document simple.fo to a PDF file.
• we are using the open-source Apache-FOP formatting engine.
• Apache-FOP requires the Java Development Kit from Sun
Microsystems.
• The Adobe Acrobat Reader is required to view the PDF documents.
• The Acrobat Reader is freely available at http://www.adobe.com.
Steps to generate a PDF document from simple.fo:
1. Open an MS-DOS window.
2. Move to the directory where simple.fo is stored
3. Set up the Java classpath by typing setpaths.
4. Execute Apache-FOP by typing fop simple.fo simple.pdf.
5. The Apache-FOP formatter now reads the input file simple.fo and
generates the output file simple.pdf.
6. View the simple.pdf file in Adobe Acrobat Reader.
7/29/2019 65Dr.S.Roselin Mary HOD/CSE
7/29/2019 66Dr.S.Roselin Mary HOD/CSE
Page Headers and Footers
• The <fo:static-content> element defines content that
should appear on every page.
• The <fo:static-content> element is commonly used to set
up page headers and footers.
• The <fo:static-content> element is a component of
<fo:page-sequence>.
• In the following example, we’ll define a page header
that contains the company name and current page
number. We’ll also define a footer that lists the
company’s Web site. This example is also composed of
multiple pages to illustrate the fact that the header and
footer are repeated on each page.
7/29/2019 67Dr.S.Roselin Mary HOD/CSE
The header is defined using the following code fragment:
<!-- header -->
<fo:static-content flow-name =”xsl-region-before”>
<fo:block text-align=”end”
font-size=”10pt”
font-family=”serif”
line-height=”14pt” >
Ez Books Catalog - page
<fo:page-number/>
</fo:block>
</fo:static-content>
• The content for the header is placed in xsl-region-before, which is the top
of the page in this example.
• The <fo:block> element uses the text-align attribute to place the text at
the end of the region. This example uses the English language, so the text
is right justified.
• The current page number is determined using the <fo:page-number>
element
Page Header
7/29/2019 68Dr.S.Roselin Mary HOD/CSE
<!-- header -->
<fo:static-content flow-name =”xsl-region-before”>
<fo:block text-align=”end”
font-size=”10pt”
font-family=”serif”
line-height=”14pt” >
Ez Books Catalog - page
<fo:page-number/>
</fo:block>
</fo:static-content>
The footer is defined using the following code fragment:
<!-- footer -->
<fo:static-content flow-name=”xsl-region-after”>
<fo:block text-align=”center”
font-size=”10pt”
font-family=”serif”
line-height=”14pt” >
Visit our website http://www.ezbooks.web
</fo:block>
</fo:static-content>
• The footer content is placed at the bottom of the page in xsl-region-
after.
• A message containing the company’s Web site is listed in the footer.
Page Footer
7/29/2019 69Dr.S.Roselin Mary HOD/CSE
<!-- footer -->
<fo:static-content flow-name=”xsl-region-after”>
<fo:block text-align=”center”
font-size=”10pt”
font-family=”serif”
line-height=”14pt” >
Visit our website http://www.ezbooks.web
</fo:block>
</fo:static-content>
• New pages are generated using <fo:block break-before=”page”>.
• The static content, header, and footer will also appear on the new
page.
• The following code fragment generates a page break before the
content is rendered.
<!-- insert page break for second page -->
<fo:block break-before=”page”>
A page break is inserted before this block.
Notice we have the headers and footers
in place. This was accomplished with the
fo-static-content elements. We can continue
on...business as usual.
</fo:block>
Page Break
7/29/2019 70Dr.S.Roselin Mary HOD/CSE
<!-- insert page break for second page -->
<fo:block break-before=”page”>
A page break is inserted before this block.
Notice we have the headers and footers
in place. This was accomplished with the
fo-static-content elements. We can continue
on...business as usual.
</fo:block>
Full Coding
7/29/2019 71Dr.S.Roselin Mary HOD/CSE
7/29/2019 72Dr.S.Roselin Mary HOD/CSE
7/29/2019 73Dr.S.Roselin Mary HOD/CSE
Graphics
• XSL-FO also allows for the insertion of external graphic
images.
• The graphic formats supported are dependent on the XSL-FO
formatting engine.
• The Apache-FOP formatting engine supports the popular
graphics formats: GIF, JPEG, and BMP.
Code to insert the image smiley.jpg:
<fo:block text-align=”center”>
<fo:external-graphic src=”smiley.jpg” width=”200px” height=”200px”/>
</fo:block>
7/29/2019 74Dr.S.Roselin Mary HOD/CSE
Tables
7/29/2019 75Dr.S.Roselin Mary HOD/CSE
Write code fragments for the
following page
7/29/2019 76Dr.S.Roselin Mary HOD/CSE
<fo:table>
<!-- define column widths -->
<fo:table-column column-width=”120pt”/>
<fo:table-column column-width=”200pt”/>
<fo:table-column column-width=”80pt”/>
<fo:table-header>
<fo:table-row>
<fo:table-cell>
<fo:block font-weight=”bold”>Author</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight=”bold”>Title</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight=”bold”>Price (USD)</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<!-- insert table body and rows here -->
</fo:table>
Coding to create and define the column
width & table headers
7/29/2019 77Dr.S.Roselin Mary HOD/CSE
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>Michael Daconta</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>XML Development with Java 2</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>37.99</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>E. Lynn Harris</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Any Way The Wind Blows</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>19.95</fo:block>
</fo:table-cell>
</fo:table-row>
Coding to include the data in the table cells
for each row
7/29/2019 78Dr.S.Roselin Mary HOD/CSE
<fo:table-row>
<fo:table-cell>
<fo:block>Tom Clancy</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Executive Orders</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>7.99</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
7/29/2019 79Dr.S.Roselin Mary HOD/CSE
table.fo
<?xml version=”1.0” encoding=”utf-8”?>
<fo:root xmlns:fo=”http://www.w3.org/1999/XSL/Format”>
<fo:layout-master-set>
<!-- layout information 
<fo:simple-page-master master-name=”simple”
page-height=”11in”
page-width=”8.5in”
margin-top=”1in”
margin-bottom=”1in”
margin-left=”1.25in”
margin-right=”1.25in”>
<fo:region-body margin-top=”0.5in”/>
<fo:region-before extent=”3cm”/>
<fo:region-after extent=”1.5cm”/>
</fo:simple-page-master>
</fo:layout-master-set>
7/29/2019 80Dr.S.Roselin Mary HOD/CSE
<fo:page-sequence master-name=”simple”>
<fo:flow flow-name=”xsl-region-body”>
<!-- this defines a level 1 heading with orange background -->
<fo:block font-size=”18pt”
font-family=”sans-serif”
line-height=”24pt”
space-after.optimum=”15pt”
background-color=”orange”
color=”white”
text-align=”center”
padding-top=”3pt”>
Ez Books Online
</fo:block>
7/29/2019 81Dr.S.Roselin Mary HOD/CSE
<fo:table>
<!-- define column widths -->
<fo:table-column column-width=”120pt”/>
<fo:table-column column-width=”200pt”/>
<fo:table-column column-width=”80pt”/>
<fo:table-header>
<fo:table-row>
<fo:table-cell>
<fo:block font-weight=”bold”>Author</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight=”bold”>Title</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight=”bold”>Price (USD)</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<!-- insert table body and rows here -->
</fo:table>7/29/2019 82Dr.S.Roselin Mary HOD/CSE
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>Michael Daconta</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>XML Development with Java 2</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>37.99</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>E. Lynn Harris</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Any Way The Wind Blows</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>19.95</fo:block>
</fo:table-cell>
</fo:table-row>
7/29/2019 83Dr.S.Roselin Mary HOD/CSE
<fo:table-row>
<fo:table-cell>
<fo:block>Tom Clancy</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Executive Orders</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>7.99</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<!-- table end -->
</fo:flow>
</fo:page-sequence>
</fo:root>
7/29/2019 84Dr.S.Roselin Mary HOD/CSE
Generating XSL-FO Tables Using XSLT
• the size of the document if we wanted to list
500 books, the document would be extremely
large and verbose.
• So, we’ll use XSLT to automatically generate
the XSL-FO document.
• The file, booklist.xml, contains a list of the
books.
• We can develop an XSL style sheet that will
automatically construct the XSL-FO document.
7/29/2019 85Dr.S.Roselin Mary HOD/CSE
7/29/2019 86Dr.S.Roselin Mary HOD/CSE
• After reviewing the XSL-FO document for the book table, you can see that the
dynamic portion is the construction of each table row.
• We can use the element <xsl:for-each> to loop over each book and build the table
row.
This is accomplished with the following code:
<!-- Perform loop for each book in the book list -->
<xsl:for-each select=”booklist/book” >
<fo:table-row>
<fo:table-cell>[sr]
<fo:block><xsl:value-of select=”author” /> </fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block> <xsl:value-of select=”title” /> </fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block> <xsl:value-of select=”price” /> </fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
7/29/2019 87Dr.S.Roselin Mary HOD/CSE
Generating a PDF Document
• The first step involves XSLT processing the booklist.xml document
with booklist_table.xsl.
• The second step involves converting the output of the XSLT
conversion to a PDF file using XSL-FO.
• The Apache-FOP product can perform both of these steps internally.
All we have to do is provide the XML document and XSL style sheet.
• Follow these steps to generate the PDF document:
– 1. Open an MS-DOS window.
– 2. Move to the directory <install_dir>ch9_xslxsl_fodynamictable.
– 3. Set up the Java classpath by typing setpaths.
– 4. Execute Apache-FOP by typing the following:
– fop -xml booklist.xml -xsl booklist_table.xsl dyntable.pdf
– 5. View the dyntable.pdf file in Adobe Acrobat Reader.
7/29/2019 88Dr.S.Roselin Mary HOD/CSE
7/29/2019 89Dr.S.Roselin Mary HOD/CSE

More Related Content

What's hot (18)

Xml 2
Xml  2 Xml  2
Xml 2
 
Web Service Workshop - 3 days
Web Service Workshop - 3 daysWeb Service Workshop - 3 days
Web Service Workshop - 3 days
 
Xml part4
Xml part4Xml part4
Xml part4
 
intro for sql
intro for sql intro for sql
intro for sql
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Sql - Structured Query Language
Sql - Structured Query LanguageSql - Structured Query Language
Sql - Structured Query Language
 
Xml schema
Xml schemaXml schema
Xml schema
 
SXML: S-expression eXtensible Markup Language
SXML: S-expression eXtensible Markup LanguageSXML: S-expression eXtensible Markup Language
SXML: S-expression eXtensible Markup Language
 
Xml schema
Xml schemaXml schema
Xml schema
 
Schemas 2 - Restricting Values
Schemas 2 - Restricting ValuesSchemas 2 - Restricting Values
Schemas 2 - Restricting Values
 
Structured Query Language (SQL)
Structured Query Language (SQL)Structured Query Language (SQL)
Structured Query Language (SQL)
 
Object Based Databases
Object Based DatabasesObject Based Databases
Object Based Databases
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
sql statements & joins
sql statements & joinssql statements & joins
sql statements & joins
 
Xml schema
Xml schemaXml schema
Xml schema
 
XML DTD and Schema
XML DTD and SchemaXML DTD and Schema
XML DTD and Schema
 
Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)
 

Similar to Service Oriented Architecture - Unit II

Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...Allison Jai O'Dell
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)Serhii Kartashov
 
XSLT and XPath - without the pain!
XSLT and XPath - without the pain!XSLT and XPath - without the pain!
XSLT and XPath - without the pain!Bertrand Delacretaz
 
IWMW 2001: XML and XSLT
IWMW 2001: XML and XSLT IWMW 2001: XML and XSLT
IWMW 2001: XML and XSLT IWMW
 
Introduction of xml and xslt
Introduction of xml and xsltIntroduction of xml and xslt
Introduction of xml and xsltTUSHAR VARSHNEY
 
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld BookNet Canada
 
In Pursuit of the Grand Unified Template
In Pursuit of the Grand Unified TemplateIn Pursuit of the Grand Unified Template
In Pursuit of the Grand Unified Templatehannonhill
 
Java Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsJava Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsAnton Keks
 
"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slidesRussell Ward
 
Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLTMalintha Adikari
 
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriyaIntegrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriyaVijiPriya Jeyamani
 

Similar to Service Oriented Architecture - Unit II (20)

Xml p5 Lecture Notes
Xml p5 Lecture NotesXml p5 Lecture Notes
Xml p5 Lecture Notes
 
XSLT for Web Developers
XSLT for Web DevelopersXSLT for Web Developers
XSLT for Web Developers
 
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)
 
XSLT and XPath - without the pain!
XSLT and XPath - without the pain!XSLT and XPath - without the pain!
XSLT and XPath - without the pain!
 
IWMW 2001: XML and XSLT
IWMW 2001: XML and XSLT IWMW 2001: XML and XSLT
IWMW 2001: XML and XSLT
 
Introduction of xml and xslt
Introduction of xml and xsltIntroduction of xml and xslt
Introduction of xml and xslt
 
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
 
In Pursuit of the Grand Unified Template
In Pursuit of the Grand Unified TemplateIn Pursuit of the Grand Unified Template
In Pursuit of the Grand Unified Template
 
XPATH_XSLT-1.pptx
XPATH_XSLT-1.pptxXPATH_XSLT-1.pptx
XPATH_XSLT-1.pptx
 
Xml
XmlXml
Xml
 
Java Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsJava Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & Servlets
 
XSL - XML STYLE SHEET
XSL - XML STYLE SHEETXSL - XML STYLE SHEET
XSL - XML STYLE SHEET
 
"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLT
 
Xml PPT
Xml PPTXml PPT
Xml PPT
 
XSLT.ppt
XSLT.pptXSLT.ppt
XSLT.ppt
 
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriyaIntegrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya
 
XML XSLT
XML XSLTXML XSLT
XML XSLT
 

More from Roselin Mary S

Unit 2 hci in software process
Unit 2   hci in software processUnit 2   hci in software process
Unit 2 hci in software processRoselin Mary S
 
Unit1 17-08-2020 HUMAN COMPUTER INTERACTION
Unit1  17-08-2020 HUMAN COMPUTER INTERACTIONUnit1  17-08-2020 HUMAN COMPUTER INTERACTION
Unit1 17-08-2020 HUMAN COMPUTER INTERACTIONRoselin Mary S
 
Unit 1 defects classes
Unit 1 defects classesUnit 1 defects classes
Unit 1 defects classesRoselin Mary S
 
IT 8076 Software Testing Unit1
IT 8076 Software Testing Unit1IT 8076 Software Testing Unit1
IT 8076 Software Testing Unit1Roselin Mary S
 
Service Oriented Architecture -Unit II - Modeling databases in xml
Service Oriented Architecture -Unit II - Modeling databases in xml Service Oriented Architecture -Unit II - Modeling databases in xml
Service Oriented Architecture -Unit II - Modeling databases in xml Roselin Mary S
 
Service Oriented Architecture - Unit II - Sax
Service Oriented Architecture - Unit II - Sax Service Oriented Architecture - Unit II - Sax
Service Oriented Architecture - Unit II - Sax Roselin Mary S
 
Service oriented architeture Unit 1
Service oriented architeture  Unit 1Service oriented architeture  Unit 1
Service oriented architeture Unit 1Roselin Mary S
 

More from Roselin Mary S (8)

Unit 2 hci in software process
Unit 2   hci in software processUnit 2   hci in software process
Unit 2 hci in software process
 
Unit1 17-08-2020 HUMAN COMPUTER INTERACTION
Unit1  17-08-2020 HUMAN COMPUTER INTERACTIONUnit1  17-08-2020 HUMAN COMPUTER INTERACTION
Unit1 17-08-2020 HUMAN COMPUTER INTERACTION
 
Unit 1 defects classes
Unit 1 defects classesUnit 1 defects classes
Unit 1 defects classes
 
Unit 1 part 2
Unit 1 part 2Unit 1 part 2
Unit 1 part 2
 
IT 8076 Software Testing Unit1
IT 8076 Software Testing Unit1IT 8076 Software Testing Unit1
IT 8076 Software Testing Unit1
 
Service Oriented Architecture -Unit II - Modeling databases in xml
Service Oriented Architecture -Unit II - Modeling databases in xml Service Oriented Architecture -Unit II - Modeling databases in xml
Service Oriented Architecture -Unit II - Modeling databases in xml
 
Service Oriented Architecture - Unit II - Sax
Service Oriented Architecture - Unit II - Sax Service Oriented Architecture - Unit II - Sax
Service Oriented Architecture - Unit II - Sax
 
Service oriented architeture Unit 1
Service oriented architeture  Unit 1Service oriented architeture  Unit 1
Service oriented architeture Unit 1
 

Recently uploaded

(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...Call girls in Ahmedabad High profile
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 

Recently uploaded (20)

(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 

Service Oriented Architecture - Unit II

  • 2. • XSL stands for EXtensible Stylesheet Language. It is similar to XML as CSS is to HTML. Need for XSL • In case of HTML document, tags are predefined such as table, div, and span; and the browser knows how to add style to them and display those using CSS styles. • But in case of XML documents, tags are not predefined. In order to understand and style an XML document, World Wide Web Consortium (W3C) developed XSL which can act as XML based Stylesheet Language. • An XSL document specifies how a browser should render an XML document. • Following are the main parts of XSL − – XSLT − used to transform XML document into various other types of document. – XPath − used to navigate XML document. – XSL-FO − used to format XML document.
  • 3. What is XSLT • XSLT, Extensible Stylesheet Language Transformations, provides the ability to transform XML data from one format to another automatically. How XSLT Works • An XSLT stylesheet is used to define the transformation rules to be applied on the target XML document. • XSLT stylesheet is written in XML format. XSLT Processor takes the XSLT stylesheet and applies the transformation rules on the target XML document and then it generates a formatted document in the form of XML, HTML, or text format. • This formatted document is then utilized by XSLT formatter to generate the actual output which is to be displayed to the end-user. Advantages • Independent of programming. Transformations are written in a separate xsl file which is again an XML document. • Output can be altered by simply modifying the transformations in xsl file. No need to change any code. So Web designers can edit the stylesheet and can see the change in the output quickly.
  • 4.
  • 5. students.xml <?xml version = "1.0"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class> We need to define an XSLT style sheet document for the above XML document to meet the following criteria − •Page should have a title Students. •age should have a table of student details. •Columns should have following headers: Roll No, First Name, Last Name, Nick Name, Marks
  • 6. Step 1: Create XSLT document Create an XSLT document to meet the above requirements, name it as students.xsl and save it in the same location where students.xml lies. students.xsl <?xml version = "1.0" encoding = "UTF-8"?> <!-- xsl stylesheet declaration with xsl namespace: Namespace tells the xlst processor about which element is to be processed and which is used for output purpose only --> <xsl:stylesheet version = "1.0“ xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <!-- xsl template declaration: template tells the xlst processor about the section of xml document which is to be formatted. It takes an XPath expression. In our case, it is matching document root element and will tell processor to process the entire document with this template. --> <xsl:template match = "/"> <!-- HTML tags Used for formatting purpose. Processor will skip them and browser will simply render them. --> <html> <body> <h2>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th>
  • 7. <!-- for-each processing instruction Looks for each element matching the XPath expression --> <xsl:for-each select="class/student"> <tr> <!-- value-of processing instruction process the value of the element matching the XPath expression --> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
  • 8. Step 2: Link the XSLT Document to the XML Document Update student.xml document with the following xml-stylesheet tag. Set href value to students.xsl <?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> ... </class>
  • 9. Step 3: View the XML Document in Internet Explorer students.xml <?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
  • 11. XSLT <template> Name & Description 1 name Name of the element on which template is to be applied. 2 match Pattern which signifies the element(s) on which template is to be applied. 3 priority Priority number of a template. Matching template with low priority is not considered in from in front of high priority template. 4 mode Allows element to be processed multiple times to produce a different result each time. <xsl:template> defines a way to reuse templates in order to generate the desired output for nodes of a particular type/context. Declaration Following is the syntax declaration of <xsl:template> element. <xsl:template name = Qname match = Pattern priority = number mode = QName > </xsl:template> Attributes
  • 12. Number of occurrences Unlimited Parent elements xsl:stylesheet, xsl:transform Child elements xsl:apply-imports,xsl:apply-templates,xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:number, xsl:param, xsl:processing-instruction, xsl:text, xsl:value- of, xsl:variable, output elements Elements students_imports.xsl <?xml version = "1.0" encoding = "UTF-8"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "/"> <html> <body> <h2>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr>
  • 13. <xsl:for-each select = "class/student"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
  • 14. XSLT <value-of> Sr.No Name & Description 1 Select XPath Expression to be evaluated in current context. 2 disable-outputescaping Default-"no". If "yes", output text will not escape xml characters from text. <xsl:value-of> tag puts the value of the selected node as per XPath expression, as text. Declaration Following is the syntax declaration of <xsl:value-of> element. <xsl:value-of select = Expression disable-output-escaping = "yes" | "no" > </xsl:value-of> Attributes Number of Occurrences Unlimited Parent elements xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements Child elements None Elements
  • 15. <?xml version = "1.0" encoding = "UTF-8"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "/"> <html> <body> <h2>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
  • 16. XSLT <sort> Sr.No Name & Description 1 select Sorting key of the node. 2 lang Language alphabet used to determine sort order. 3 data-type Data type of the text. 4 order Sorting order. Default is "ascending". 5 case-order <xsl:sort> tag specifies a sort criteria on the nodes. Declaration Following is the syntax declaration of <xsl:sort> element. <xsl:sort select = string-expression lang = { nmtoken } data-type = { "text" | "number" | QName } order = { "ascending" | "descending" } case-order = { "upper-first" | "lower-first" } > </xsl:sort> Attributes
  • 17. Number of occurrences Unlimited Parent elements xsl:apply-templates, xsl:for-each Child elements None Elements
  • 18. students.xsl <?xml version = "1.0" encoding = "UTF-8"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "/"> <html> <body> <h2>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <xsl:sort select = "firstname"/> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
  • 19. XSLT <if> Sr.No Name & Description 1 test The condition in the xml data to test. Number of Occurrences Unlimited Parent elements xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements Child elements xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements <xsl:if> tag specifies a conditional test against the content of nodes. Declaration Following is the syntax declaration of <xsl:if> element. <xsl:if test = boolean-expression > </xsl:if> Attributes Elements
  • 20. <?xml version = "1.0" encoding = "UTF-8"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "/"> <html> <body> <h2>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <xsl:if test = "marks > 90"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
  • 21. XSLT processors Two techniques for performing XSLT processing • client-side processing • server-side processing.
  • 22. Client-side XSLT processing • Client-side XSLT processing commonly occurs in a Web browser. • The Web browser includes an XSLT processor and retrieves the XML document and XSL style sheet • The client-side technique offloads the XSLT processing to the client machine. This minimizes the workload on the Web server. • However, the Web browser must provide XSLT support. • E.g: Netscape Communicator 6 , Microsoft Internet Explorer 6 support the XSLT 1.0 specification
  • 23. • For client-side processing, the XML document requires a special processing instruction to reference the XSL style sheet. • The processing instruction is <?xml- stylesheet> – it has two attributes: type and href. • The type attribute specifies the content type of the document to be retrieved (in this case, text/xsl). • The href attribute is a URL reference to the style sheet. The href attribute supports absolute and relative URL references.
  • 24. <?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class> Students.xml
  • 25. <?xml version = "1.0" encoding = "UTF-8"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "/"> <html> <body> <h2>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Students.xsl
  • 26. Output at the web browser
  • 27. • Server-side XSLT processing occurs on the Web server or application server. • A serverside process such as an Active Server Page (ASP), JavaServer Page (JSP), or Java servlet will retrieve the XML document and XSL style sheet and pass them to an XSLT processor. • The output of the XSLT processor is sent to the client Web browser for presentation. • The output is generally a markup language, such as HTML, that is understood by the client browser. server-side XSLT processing
  • 28. • An advantage of the server-side technique is browser independence. This technique supports the older browser versions and makes the application more robust and versatile. • Also, by utilizing the server-side technique, the application can support a diverse collection of clients. • The application can detect the user-agent, such as a WAP-enabled mobile phone, and send back a document containing a Wireless Markup Language (WML) tag. • The WAP-enabled phone can render the content using the built-in WML mini-browser.
  • 29. • A number of server-side technologies are available, including Common Gateway Interface (CGI), ColdFusion, Hypertext Processor (PHP), and so on. • Microsoft’s Active Server Pages (ASP) and Sun Microsystems’ JavaServer Pages (JSP). ASP: Server-Side XSLT Processing Required components: – Microsoft IIS Web Server 5.0. This version of IIS is included with Microsoft Windows 2000 Professional. We can also use IIS 4.0 or Personal Web Server (PWS); But, we have to install the Windows NT Option Pack 4. – Microsoft XML Parser 3.0 If we have IE 6 installed on our server machine, then Microsoft XML Parser 3.0 is included. The MS XML Parser 3.0 is also available as a separate download from http://msdn.microsoft.com. • we have two options for publishing the source code on the IIS server: – Copy the students.xml and students.xsl files in to c:Inetpubwwwroot. – Set up a virtual directory that points to the xml file location
  • 30. <%@ Language=VBScript %> <% set xml = Server.CreateObject(“Microsoft.XMLDOM”) xml.load(Server.MapPath(“students.xml”)) set xsl = Server.CreateObject(“Microsoft.XMLDOM”) xsl.load(Server.MapPath(“students.xsl”)) Response.Write(xml.transformNode(xsl)) %> Students.asp A Web browser rendering HTML
  • 31. JSP: Server-Side XSLT Processing • Sun Microsystems provides a server-side technology that is very similar to ASP. The server-side scripting is accomplished in Java. Required components: – Sun Microsystems’ Software Development Kit (SDK) 1.3 (or higher). The SDK is available at Sun’s Web site, http://java.sun.com/j2se. Follow the installation instructions provided with the SDK. – Apache Tomcat Server 4. Apache Tomcat 4 is the official reference implementation for JSP 1.2 and Java Servlets 2.3. – If the application server already supports JSP 1.1 or higher, there is no requirement to install Tomcat. Apache Tomcat 4 is available from the Apache Web site, http://jakarta.apache.org/tomcat. Follow the – installation instructions provided with the Tomcat server.
  • 32. • Once Tomcat 4 is installed, add a new Web application that points to the source code directory. This is done by editing the file <tomcat_install_dir>confserver.xml • Move to the section where the <Context> elements are listed and then add the following entry: <Context path=”/myapp” docBase=”c://documents/mypgm/serverpgm” debug=”0” reloadable=”true” />
  • 33. • Restart the Tomcat server to pick up the new configuration. By default, the Tomcat server is listening on port 8080. • we can access files for the myapp Web application using the URL http://localhost:8080/myapp/students.jsp. • A JSP custom tag is a special tag that is created by a developer. • When the JSP server encounters the custom tag, it executes the handler code associated with the tag. • JSP custom tags are conceptually similar to ASP server objects. • However, the custom action is represented in the JSP page as a custom tag instead of scripting code. • The Apache <jakarta:apply> tag provides the XSLT processing.
  • 34. <%@ taglib uri=”http://jakarta.apache.org/taglibs/xsl-1.0” prefix=”jakarta” %> <jakarta:apply xml=”students.xml” xsl=”students.xsl” /> c://documents/mypgm/serverpgm/students.jsp
  • 35. • The first line in this example informs the JSP server to use the tag library that is identified by the URI http://jakarta.apache.org/taglibs/xsl-1.0. This URI is defined in the Web application’s deployment description. – The URI is actually mapped to the file jakarta-xsl.tld, located in the directory c://documents/mypgm/serverpgm/WEBINF. – The file jakarta-xsl.tld is the Tag Library Descriptor (TLD). The TLD file provides a description of the custom tags available in the class library. It also provides a mapping between the custom tag name and the tag handler class. – The tag handler class is located in the directory c://documents/mypgm/serverpgmWEB-INFlib. • The next line of code is the actual <jakarta:apply> tag. This tag has two attributes— – one defines the XML input source and the other defines the XSL style sheet. • The results of the XSLT process are returned to the Web browser. To test this example, make sure the Tomcat server is running. In a Web browser, access the JSP with the URL http://localhost:8080/myapp/students.jsp.
  • 36. XSL for Business-to-Business (B2B) Communication • XSLT can also be used in for B2B communication—the process of exchanging data between two different companies. • Developers can leverage XML to describe the data in a vendor-independent fashion. In the ideal case, both companies will agree upon a standard vocabulary for describing the data using a DTD or schema. • The vocabulary is composed of the XML element names used in the XML document. • However, in certain cases one of the companies might like to use a different vocabulary. This is where XSL enters the picture.
  • 37. Scenario • The computer training company maintains a database for the students that have attended its courses. The training company has developed an XML application that produces the list of students for a given class. • The management team at software development company would like to retrieve this list from the training company’s XML application. • However, once the data is retrieved, software development company would like to store the data in a different XML format using its own XML element names.
  • 38. • The XML application at the training company is accessible using the HTTP protocol. • The first step is to request the XML document from the training company. • In step 2, the XML document is retrieved. • In step 3, the document is transformed using the supplied XSLT style sheet. • Finally, the desired output document is produced in step 4. Training company Software development company
  • 39. <?xml version=”1.0”?> <trainingclass> <title>J2EE Essentials</title> <start_date>24 Sep 2001</start_date> <end_date>28 Sep 2001</end_date> <location>Philadelphia, PA</location> <student> <first_name>Riley</first_name> <last_name>Scott</last_name> <email>riley@acmesoft.web</email> </student> <student> <first_name>Torrance</first_name> <last_name>Lee</last_name> <email>torrance.lee@acmesoft.web</email> </student> </trainingclass> Training company’s XML
  • 40. <?xml version=”1.0”?> <employeelist> <course_title>J2EE Essentials</course_title> <course_date start=”24 Sep 2001” end=”28 Sep 2001” /> <location>Philadelphia, PA</location> <employee> <name> <first>Riley</first> <last>Scott</last> </name> <email>riley.scott@acmesoft.web</email> </employee> <employee> <name> <first>Torrance</first> <last>Lee</last> </name> <email>torrance.lee@acmesoft.web</email> </employee> </employeelist> Software development company’s xml
  • 41. • Therefore, a mechanism is needed to convert an XML document to another XML format. • XSLT offers a solution to this problem. An XSL style sheet can be developed to convert the <trainingclass> document to the <employeelist> document. • This approach will not require any changes by the training company. The training company can continue to publish XML documents for its training classes. • The development team can develop an XSL style sheet that contains the transformation rules. • Once the style sheet is developed, the XML document and style sheet can be passed to the XSLT processor, which will generate the desired XML document for <employeelist>.
  • 42. • The training company describes the date for the class using the elements <start_date> and <end_date>, as shown here: <start_date>24 Sep 2001</start_date> <end_date>28 Sep 2001</end_date> • S/W development company stores the date as a single element with two attributes for the start and end: <course_date start=”24 Sep 2001” end=”28 Sep 2001” /> • In this case, <xsl:attribute> can be used to create attributes for <course_date>: <course_date> <xsl:attribute name=”start”> <xsl:value-of select=”start_date”/> </xsl:attribute> <xsl:attribute name=”end”> <xsl:value-of select=”end_date”/> </xsl:attribute> </course_date> The <xsl:attribute> element creates attributes for the parent element. In this example, the parent element is course_date. This transformation will result in the following code: <course_date start=”24 Sep 2001” end=”28 Sep 2001” />
  • 43. <?xml version=”1.0”?> <xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” version=”1.0”> <xsl:template match=”/trainingclass”> <employeelist> <course_title><xsl:value-of select=”title” /></course_title> <!-- create attributes for the start and end course dates --> <course_date> <xsl:attribute name=”start”> <xsl:value-of select=”start_date”/> </xsl:attribute> <xsl:attribute name=”end”> <xsl:value-of select=”end_date”/> </xsl:attribute> </course_date> <location><xsl:value-of select=”location” /></location> train2employee.xsl
  • 44. <!-- Perform a loop for each student in the training class --> <xsl:for-each select=”student” <employee> <name> <first><xsl:value-of select=”first_name”/></first> <last><xsl:value-of select=”last_name”/></last> </name> <email><xsl:value-of select=”email”/></email> </employee> </xsl:for-each> </employeelist> </xsl:template> </xsl:stylesheet>
  • 45. import org.apache.xalan.xslt.*; /** * Usage: java XslTester <input XML> <input XSL> <output file> */ public class XslTester { public static void main(String[] args) { try { // Verify the correct arguments are passed in if (args.length != 3) { System.out.println(“Usage: java XslTester <input XML> <input XSL> <output file>”); System.exit(1); } System.out.println(“Processing: “ + args[0] + “ and “ + args[1]); // Step 1: Get a reference to the XSLT Processor XSLTProcessor myEngine = XSLTProcessorFactory.getProcessor(); // Step 2: Get the XML input document XSLTInputSource xmlSource = new XSLTInputSource(args[0]); xslTester.java
  • 46. // Step 3: Get the XSL style sheet XSLTInputSource xslStylesheet = new XSLTInputSource(args[1]); // Step 4: Setup the output target XSLTResultTarget xmlOutput = new XSLTResultTarget(args[2]); // Step 5: Now process it! myEngine.process(xmlSource, xslStylesheet, xmlOutput); System.out.println(“Created => “ + args[2]); System.out.println(“Done!”); } catch (Exception exc) { exc.printStackTrace(); } } }
  • 48. XSL Formatting Objects • XSL-FO was designed to assist with the printing and displaying of XML data. • The main emphasis is on the document layout and structure. This includes the dimensions of the output document, including page headers, footers, and margins. • XSL-FO also allows the developer to define the formatting rules for the content, such as font, style, color, and positioning. • XSL-FO is a sophisticated version of Cascading Style Sheets (CSS). In fact, XSL-FO borrows a lot of the terminology and elements from CSS. • XSL-FO documents are well-formed XML documents. An XSL-FO formatting engine processes XSL-FO documents. • Two techniques for creating XSL-FO documents: 1. simply develop the XSL-FO file with the included data. 2. dynamically create the XSL-FO file using an XSLT translation. 7/29/2019 48Dr.S.Roselin Mary HOD/CSE
  • 49. XSL-FO Formatting Engines 7/29/2019 49Dr.S.Roselin Mary HOD/CSE
  • 50. Basic Document Structure XSL-FO elements use the following namespace: http://www.w3.org/1999/XSL/Format <?xml version=”1.0” encoding=”utf-8”?> <fo:root xmlns:fo=”http://www.w3.org/1999/XSL/Format”> <!-- layout master set --> <!-- page masters: size and layout --> <!-- page sequences and content --> </fo:root> • The element <fo:root> is the root element for the XSL-FO document. An XSL- FO document can contain the following components: – • Page master  describes the page size and layout – • Page master set  refers to the collection of page masters – • Page sequences  defines a series of printed pages. The page sequence contains the actual content for the document 7/29/2019 50Dr.S.Roselin Mary HOD/CSE
  • 51. • The <fo:simple-page-master> element defines the layout of a page. <fo:simple-page-master master-name=”simple” page-height=”11in” page-width=”8.5in” margin-top=”1in” margin-bottom=”1in” margin-left=”1.25in” margin-right=”1.25in” > </fo:simple-page-master> 7/29/2019 51Dr.S.Roselin Mary HOD/CSE
  • 53. • To set the page height to 210 millimeters, use the following syntax: page-height=”210mm” • The <fo:simple-page-master> element can also be used to describe an A4 letter (height 210 mm and width 297 mm): <fo:simple-page-master master-name=”A4-example” page-height=”210mm” page-width=”297mm” margin-top=”0.5in” margin-bottom=”0.5in” margin-left=”0.5in” margin-right=”0.5in” > </fo:simple-page-master> 7/29/2019 53Dr.S.Roselin Mary HOD/CSE
  • 54. • Each page is divided into five regions. Regions serve as containers for the document content. • The region-before and region-after areas are commonly used for page headers and footers. • The region-body area is the center of the page and contains the main content. • The region-start and region-end sections are commonly used for left and right sidebars, respectively. • In the definition of a page master, specify the size of the regions using the following elements: • <fo:region-before> • <fo:region-after> • <fo:region-body> • <fo:region-start> • <fo:region-end> 7/29/2019 54Dr.S.Roselin Mary HOD/CSE
  • 56. <fo:simple-page-master master-name=”simple” page-height=”11in” page-width=”8.5in” > <fo:region-body margin-top=”0.5in”/> <fo:region-before extent=”0.5in”/> <fo:region-after extent=”0.5in”/> </fo:simple-page-master> • The extent attribute has a different meaning, depending on the region. • For <fo:region-end> and <fo:region-start>, the extent attribute specifies the width. • For <fo:region-before> and <fo:region-after>, it specifies the height. 7/29/2019 56Dr.S.Roselin Mary HOD/CSE
  • 57. Page Master Set: <fo:page-master-set> • A document can be composed of multiple pages, each with its own dimensions. • The page master set refers to the collection of page masters. <fo:layout-master-set> <fo:simple-page-master master-name=”simple” page-height=”11in” page-width=”8.5in” margin-top=”1in” margin-bottom=”1in” margin-left=”1.25in” margin-right=”1.25in”> <fo:region-body margin-top=”0.5in”/> <fo:region-before extent=”3cm”/> <fo:region-after extent=”1.5cm”/> </fo:simple-page-master> </fo:layout-master-set> 7/29/2019 57Dr.S.Roselin Mary HOD/CSE
  • 58. <?xml version=”1.0” encoding=”utf-8”?> <fo:root xmlns:fo=”http://www.w3.org/1999/XSL/Format”> <!-- layout master set --> <fo:layout-master-set> <!-- page masters: size and layout --> <fo:simple-page-master master-name=”simple” page-height=”11in” page-width=”8.5in” margin-top=”1in” margin-bottom=”1in” margin-left=”1.25in” margin-right=”1.25in”> <fo:region-body margin-top=”0.5in”/> <fo:region-before extent=”3cm”/> <fo:region-after extent=”1.5cm”/> </fo:simple-page-master> </fo:layout-master-set> <!-- page sequences and content --> </fo:root> Simplepagemaster.fo 7/29/2019 58Dr.S.Roselin Mary HOD/CSE
  • 59. Page Sequences: <fo:page-sequence> • A page sequence defines a series of printed pages. • Each page sequence refers to a page master for its dimensions. • The page sequence contains the actual content for the document. • The <fo:page-sequence> element contains – <fo:static-content> – <fo:flow> 7/29/2019 59Dr.S.Roselin Mary HOD/CSE
  • 60. 1. The <fo:static-content> element is used for page headers and footers. E.g: we can define a header for the company name and page number, and this information will appear on every page. 2. The <fo:flow> element contains a collection of text blocks. – The <fo:flow> element is similar to a collection of paragraphs. – A body of text is defined using the <fo:block> element. • The <fo:block> element is a child element of <fo:flow>. • The <fo:block> element contains free-flowing text that will wrap to the next line in a document if it overflows. • In this example 7/29/2019 60Dr.S.Roselin Mary HOD/CSE
  • 61. <fo:page-sequence master-name=”simple”> <fo:flow flow-name=”xsl-region-body”> <!-- this defines a level 1 heading with orange background --> <fo:block font-size=”18pt” font-family=”sans-serif” line-height=”24pt” space-after.optimum=”15pt” background-color=”orange” color=”white” text-align=”center” padding-top=”3pt”> Ez Books Online </fo:block> <!-- Paragraph that contains info about the company --> <fo:block font-size=”12pt” font-family=”sans-serif” line-height=”15pt” space-after.optimum=”14pt” text-align=”justify”> Welcome to Ez Books Online, the world’s smallest online book store. Our company’s mission is to sell books on Java, Thrillers and Romance. We have something for everyone...so we think. Feel free to browse our catalog and if you find a book of interest then send us an e-mail. Thanks for visiting! </fo:block> </fo:flow> </fo:page-sequence> 7/29/2019 61Dr.S.Roselin Mary HOD/CSE
  • 62. • The <fo:flow> element has to specify a region for its content. E.g: the content is placed in the main body region. • The first <fo:block> element defines a heading with an orange background. • The content of each <fo:block> can be customized using font and line attributes. • The second <fo:block> element contains information about the company. • The text for <fo:block> is free flowing. The text will automatically wrap. • Ample space is provided at the end of the paragraph using the space-after.optimum attribute. 7/29/2019 62Dr.S.Roselin Mary HOD/CSE
  • 63. <?xml version=”1.0” encoding=”utf-8”?> <fo:root xmlns:fo=”http://www.w3.org/1999/XSL/Format”> <!-- layout master set --> <fo:layout-master-set> <!-- page masters: size and layout --> <fo:simple-page-master master-name=”simple” page-height=”11in” page-width=”8.5in” margin-top=”1in” margin-bottom=”1in” margin-left=”1.25in” margin-right=”1.25in”> <fo:region-body margin-top=”0.5in”/> <fo:region-before extent=”3cm”/> <fo:region-after extent=”1.5cm”/> </fo:simple-page-master> </fo:layout-master-set> <!-- page sequences and content --> <fo:page-sequence master-name=”simple”> <fo:flow flow-name=”xsl-region-body”> Simple.fo 7/29/2019 63Dr.S.Roselin Mary HOD/CSE
  • 64. <!-- this defines a level 1 heading with orange background --> <fo:block font-size=”18pt” font-family=”sans-serif” line-height=”24pt” space-after.optimum=”15pt” background-color=”orange” color=”white” text-align=”center” padding-top=”3pt”> Ez Books Online </fo:block> <!-- Paragraph that contains info about the company --> <fo:block font-size=”12pt” font-family=”sans-serif” line-height=”15pt” space-after.optimum=”14pt” text-align=”justify”> Welcome to Ez Books Online, the world’s smallest online book store. Our company’s mission is to sell books on Java, Thrillers and Romance. We have something for everyone...so we think. Feel free to browse our catalog and if you find a book of interest then send us an e-mail. Thanks for visiting! </fo:block> </fo:flow> </fo:page-sequence> </fo:root> 7/29/2019 64Dr.S.Roselin Mary HOD/CSE
  • 65. Generating a PDF Document • Convert the XSL-FO document simple.fo to a PDF file. • we are using the open-source Apache-FOP formatting engine. • Apache-FOP requires the Java Development Kit from Sun Microsystems. • The Adobe Acrobat Reader is required to view the PDF documents. • The Acrobat Reader is freely available at http://www.adobe.com. Steps to generate a PDF document from simple.fo: 1. Open an MS-DOS window. 2. Move to the directory where simple.fo is stored 3. Set up the Java classpath by typing setpaths. 4. Execute Apache-FOP by typing fop simple.fo simple.pdf. 5. The Apache-FOP formatter now reads the input file simple.fo and generates the output file simple.pdf. 6. View the simple.pdf file in Adobe Acrobat Reader. 7/29/2019 65Dr.S.Roselin Mary HOD/CSE
  • 67. Page Headers and Footers • The <fo:static-content> element defines content that should appear on every page. • The <fo:static-content> element is commonly used to set up page headers and footers. • The <fo:static-content> element is a component of <fo:page-sequence>. • In the following example, we’ll define a page header that contains the company name and current page number. We’ll also define a footer that lists the company’s Web site. This example is also composed of multiple pages to illustrate the fact that the header and footer are repeated on each page. 7/29/2019 67Dr.S.Roselin Mary HOD/CSE
  • 68. The header is defined using the following code fragment: <!-- header --> <fo:static-content flow-name =”xsl-region-before”> <fo:block text-align=”end” font-size=”10pt” font-family=”serif” line-height=”14pt” > Ez Books Catalog - page <fo:page-number/> </fo:block> </fo:static-content> • The content for the header is placed in xsl-region-before, which is the top of the page in this example. • The <fo:block> element uses the text-align attribute to place the text at the end of the region. This example uses the English language, so the text is right justified. • The current page number is determined using the <fo:page-number> element Page Header 7/29/2019 68Dr.S.Roselin Mary HOD/CSE <!-- header --> <fo:static-content flow-name =”xsl-region-before”> <fo:block text-align=”end” font-size=”10pt” font-family=”serif” line-height=”14pt” > Ez Books Catalog - page <fo:page-number/> </fo:block> </fo:static-content>
  • 69. The footer is defined using the following code fragment: <!-- footer --> <fo:static-content flow-name=”xsl-region-after”> <fo:block text-align=”center” font-size=”10pt” font-family=”serif” line-height=”14pt” > Visit our website http://www.ezbooks.web </fo:block> </fo:static-content> • The footer content is placed at the bottom of the page in xsl-region- after. • A message containing the company’s Web site is listed in the footer. Page Footer 7/29/2019 69Dr.S.Roselin Mary HOD/CSE <!-- footer --> <fo:static-content flow-name=”xsl-region-after”> <fo:block text-align=”center” font-size=”10pt” font-family=”serif” line-height=”14pt” > Visit our website http://www.ezbooks.web </fo:block> </fo:static-content>
  • 70. • New pages are generated using <fo:block break-before=”page”>. • The static content, header, and footer will also appear on the new page. • The following code fragment generates a page break before the content is rendered. <!-- insert page break for second page --> <fo:block break-before=”page”> A page break is inserted before this block. Notice we have the headers and footers in place. This was accomplished with the fo-static-content elements. We can continue on...business as usual. </fo:block> Page Break 7/29/2019 70Dr.S.Roselin Mary HOD/CSE <!-- insert page break for second page --> <fo:block break-before=”page”> A page break is inserted before this block. Notice we have the headers and footers in place. This was accomplished with the fo-static-content elements. We can continue on...business as usual. </fo:block>
  • 74. Graphics • XSL-FO also allows for the insertion of external graphic images. • The graphic formats supported are dependent on the XSL-FO formatting engine. • The Apache-FOP formatting engine supports the popular graphics formats: GIF, JPEG, and BMP. Code to insert the image smiley.jpg: <fo:block text-align=”center”> <fo:external-graphic src=”smiley.jpg” width=”200px” height=”200px”/> </fo:block> 7/29/2019 74Dr.S.Roselin Mary HOD/CSE
  • 76. Write code fragments for the following page 7/29/2019 76Dr.S.Roselin Mary HOD/CSE
  • 77. <fo:table> <!-- define column widths --> <fo:table-column column-width=”120pt”/> <fo:table-column column-width=”200pt”/> <fo:table-column column-width=”80pt”/> <fo:table-header> <fo:table-row> <fo:table-cell> <fo:block font-weight=”bold”>Author</fo:block> </fo:table-cell> <fo:table-cell> <fo:block font-weight=”bold”>Title</fo:block> </fo:table-cell> <fo:table-cell> <fo:block font-weight=”bold”>Price (USD)</fo:block> </fo:table-cell> </fo:table-row> </fo:table-header> <!-- insert table body and rows here --> </fo:table> Coding to create and define the column width & table headers 7/29/2019 77Dr.S.Roselin Mary HOD/CSE
  • 78. <fo:table-body> <fo:table-row> <fo:table-cell> <fo:block>Michael Daconta</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>XML Development with Java 2</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>37.99</fo:block> </fo:table-cell> </fo:table-row> <fo:table-row> <fo:table-cell> <fo:block>E. Lynn Harris</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>Any Way The Wind Blows</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>19.95</fo:block> </fo:table-cell> </fo:table-row> Coding to include the data in the table cells for each row 7/29/2019 78Dr.S.Roselin Mary HOD/CSE
  • 80. table.fo <?xml version=”1.0” encoding=”utf-8”?> <fo:root xmlns:fo=”http://www.w3.org/1999/XSL/Format”> <fo:layout-master-set> <!-- layout information  <fo:simple-page-master master-name=”simple” page-height=”11in” page-width=”8.5in” margin-top=”1in” margin-bottom=”1in” margin-left=”1.25in” margin-right=”1.25in”> <fo:region-body margin-top=”0.5in”/> <fo:region-before extent=”3cm”/> <fo:region-after extent=”1.5cm”/> </fo:simple-page-master> </fo:layout-master-set> 7/29/2019 80Dr.S.Roselin Mary HOD/CSE
  • 81. <fo:page-sequence master-name=”simple”> <fo:flow flow-name=”xsl-region-body”> <!-- this defines a level 1 heading with orange background --> <fo:block font-size=”18pt” font-family=”sans-serif” line-height=”24pt” space-after.optimum=”15pt” background-color=”orange” color=”white” text-align=”center” padding-top=”3pt”> Ez Books Online </fo:block> 7/29/2019 81Dr.S.Roselin Mary HOD/CSE
  • 82. <fo:table> <!-- define column widths --> <fo:table-column column-width=”120pt”/> <fo:table-column column-width=”200pt”/> <fo:table-column column-width=”80pt”/> <fo:table-header> <fo:table-row> <fo:table-cell> <fo:block font-weight=”bold”>Author</fo:block> </fo:table-cell> <fo:table-cell> <fo:block font-weight=”bold”>Title</fo:block> </fo:table-cell> <fo:table-cell> <fo:block font-weight=”bold”>Price (USD)</fo:block> </fo:table-cell> </fo:table-row> </fo:table-header> <!-- insert table body and rows here --> </fo:table>7/29/2019 82Dr.S.Roselin Mary HOD/CSE
  • 83. <fo:table-body> <fo:table-row> <fo:table-cell> <fo:block>Michael Daconta</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>XML Development with Java 2</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>37.99</fo:block> </fo:table-cell> </fo:table-row> <fo:table-row> <fo:table-cell> <fo:block>E. Lynn Harris</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>Any Way The Wind Blows</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>19.95</fo:block> </fo:table-cell> </fo:table-row> 7/29/2019 83Dr.S.Roselin Mary HOD/CSE
  • 85. Generating XSL-FO Tables Using XSLT • the size of the document if we wanted to list 500 books, the document would be extremely large and verbose. • So, we’ll use XSLT to automatically generate the XSL-FO document. • The file, booklist.xml, contains a list of the books. • We can develop an XSL style sheet that will automatically construct the XSL-FO document. 7/29/2019 85Dr.S.Roselin Mary HOD/CSE
  • 87. • After reviewing the XSL-FO document for the book table, you can see that the dynamic portion is the construction of each table row. • We can use the element <xsl:for-each> to loop over each book and build the table row. This is accomplished with the following code: <!-- Perform loop for each book in the book list --> <xsl:for-each select=”booklist/book” > <fo:table-row> <fo:table-cell>[sr] <fo:block><xsl:value-of select=”author” /> </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> <xsl:value-of select=”title” /> </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> <xsl:value-of select=”price” /> </fo:block> </fo:table-cell> </fo:table-row> </xsl:for-each> 7/29/2019 87Dr.S.Roselin Mary HOD/CSE
  • 88. Generating a PDF Document • The first step involves XSLT processing the booklist.xml document with booklist_table.xsl. • The second step involves converting the output of the XSLT conversion to a PDF file using XSL-FO. • The Apache-FOP product can perform both of these steps internally. All we have to do is provide the XML document and XSL style sheet. • Follow these steps to generate the PDF document: – 1. Open an MS-DOS window. – 2. Move to the directory <install_dir>ch9_xslxsl_fodynamictable. – 3. Set up the Java classpath by typing setpaths. – 4. Execute Apache-FOP by typing the following: – fop -xml booklist.xml -xsl booklist_table.xsl dyntable.pdf – 5. View the dyntable.pdf file in Adobe Acrobat Reader. 7/29/2019 88Dr.S.Roselin Mary HOD/CSE