Upload
aparnajanwalkar
View
213
Download
0
Embed Size (px)
Citation preview
8/13/2019 XML_Session05
1/33
8/13/2019 XML_Session05
2/33
Slide 2 of 33Ver. 1.0
Extensible Markup Language
Session 5
A CSS is a text file containing one or more rules or
definitions for the style characteristics of a particular
element.
It controls how tags are formatted in XML and HTML
documents.The CSS file can be included in XML documents with the
same data structure.
Introducing Cascading Style Sheet
8/13/2019 XML_Session05
3/33
Slide 3 of 33Ver. 1.0
Extensible Markup Language
Session 5
The syntax for coding a CSS is:elementname {
property1: value;
property2: value;
}
Creating CSS
elementnamespecifies the
name of the element.
8/13/2019 XML_Session05
4/33
Slide 4 of 33Ver. 1.0
Extensible Markup Language
Session 5
The syntax for coding a CSS is:elementname {
property1: value;
property2: value;
}
Creating CSS (Contd.)
property1and property2
specify the property names,
such as font-family, font-size,
and color
8/13/2019 XML_Session05
5/33
Slide 5 of 33Ver. 1.0
Extensible Markup Language
Session 5
The syntax for coding a CSS is:elementname {
property1: value;
property2: value;
}
Creating CSS (Contd.)
valuespecifies the property
values for a property name.
For example, to display the film title in red, you can
type the following code in a CSS file:FILM {COLOR: RED}
8/13/2019 XML_Session05
6/33
Slide 6 of 33Ver. 1.0
Extensible Markup Language
Session 5
A CSS can be applied to an XML
document using the following
syntax:
Applying CSS
Instructs the browser that the
XML document uses a
stylesheet.
8/13/2019 XML_Session05
7/33Slide 7 of 33Ver. 1.0
Extensible Markup Language
Session 5
A CSS can be applied to an XML
document using the following
syntax:
Applying CSS (Contd.)
Specifies the type of
formatting that is being used.
8/13/2019 XML_Session05
8/33Slide 8 of 33Ver. 1.0
Extensible Markup Language
Session 5
A CSS can be applied to an XML
document using the following
syntax:
Applying CSS (Contd.)
Specifies the name of the
CSS file used to format the
XML document.
8/13/2019 XML_Session05
9/33Slide 9 of 33Ver. 1.0
Extensible Markup Language
Session 5
Problem Statement:
Jim, the XML developer at CyberShoppe, has been asked to
display the product details for Cybershoppe in a browser in the
following format:
The price per unit, description, and quantity on hand for each
product should be displayed in teal, with a font size of 10 pts.
The product name should be displayed in red, with a font size of
20 pts. It should be displayed in bold.
All details should be displayed in the Arial font.
Demo: Creating a CSS
8/13/2019 XML_Session05
10/33Slide 10 of 33Ver. 1.0
Extensible Markup Language
Session 5
CSS does not support the reorder, sort, and display of
elements based on a condition.
For such advanced formatting, XML supports Extensible
Style Sheet Language (XSL).
XSL has two parts:XSL Transformations (XSLT)
XML Path (XPath)
XSL:
Contains instructions on how an XML document should be
transformed into an HTML or an XHTML document.Uses XPath expressions to extract specific data from an XML
document.
The XSLT processor transforms the XML document into an
HTML or XHTML or into another XML document.
Introducing XSL
8/13/2019 XML_Session05
11/33Slide 11 of 33Ver. 1.0
Extensible Markup Language
Session 5
The XSLT processor applies the transformation information
to the source document and builds the result tree as shown
in the following figure.
Analyzing the Working of the XSLT Processor
MSXML Parser
XSLT tree
XSLT
processor
Source tree
Result tree
XSLT style sheet
XML document
8/13/2019 XML_Session05
12/33Slide 12 of 33Ver. 1.0
Extensible Markup Language
Session 5
XSLT provides the following elements to select and format
data:
stylesheet
value-of
for-each
sort
text
Formatting Data Using XSLT
8/13/2019 XML_Session05
13/33Slide 13 of 33Ver. 1.0
Extensible Markup Language
Session 5
XSLT provides the following elements to select and format
data:
stylesheet
value-of
for-each
sort
text
Formatting Data Using XSLT (Contd.)
Instructs the browser that the document is a style
sheet file.
Is the root element for all XSLT style sheets.
Is written as:
8/13/2019 XML_Session05
14/33Slide 14 of 33Ver. 1.0
Extensible Markup Language
Session 5
XSLT provides the following elements to select and format
data:
stylesheet
value-of
for-each
sort
text
Displays the value of the specified element or
attribute.
Follows the syntax:
Formatting Data Using XSLT (Contd.)
8/13/2019 XML_Session05
15/33Slide 15 of 33Ver. 1.0
Extensible Markup Language
Session 5
XSLT provides the following elements to select and format
data:
stylesheet
value-of
for-each
sort
text
Instructs the XSLT processor to process the
information for each instance of the specified pattern.
Follows the syntax:
[action to be performed]
Formatting Data Using XSLT (Contd.)
8/13/2019 XML_Session05
16/33Slide 16 of 33Ver. 1.0
Extensible Markup Language
Session 5
XSLT provides the following elements to select and format
data:
stylesheet
value-of
for-each
sort
text
Sorts data based on the values assigned to elements and
attributes.
Follows the syntax:
8/13/2019 XML_Session05
17/33Slide 17 of 33Ver. 1.0
Extensible Markup Language
Session 5
XSLT provides the following elements to select and format
data:
stylesheet
value-of
for-each
sort
textGenerates constant text in the output and displays
labels.
Follows the syntax: Text to be displayed as
label
Formatting Data Using XSLT (Contd.)
8/13/2019 XML_Session05
18/33Slide 18 of 33Ver. 1.0
Extensible Markup Language
Session 5
XSL Formatting Objects (XSL-FO):
Is an XML-based language that formats XML documents into
pages, paragraphs, and lists.
Provides various objects and properties that define the
formatting of XML objects.
Provides a basic document structure that contains the
formatting objects and properties.
Formatting Data Using XSL Formatting Objects
8/13/2019 XML_Session05
19/33Slide 19 of 33Ver. 1.0
Extensible Markup Language
Session 5
The following code snippet depicts the structure of an XML
document:
Is
Formatting Data Using XSL Formatting Objects (Contd.)
8/13/2019 XML_Session05
20/33Slide 20 of 33Ver. 1.0
Extensible Markup Language
Session 5
The XSL-FO objects provides a logical layout to an XML
document.
The content of an XML document can be split into pages.
These pages are divided into following four areas:
Regions: Are the topmost areas in the page.Block areas: Are the block level elements.
Line areas: Contain the text within the block areas.
Inline areas: Are part of line areas.
Formatting Data Using XSL Formatting Objects (Contd.)
8/13/2019 XML_Session05
21/33Slide 21 of 33Ver. 1.0
Extensible Markup Language
Session 5
The XSL-FO properties specifies the type of formatting that
can be specified on the XSL-FO objects.
Consider the following code-snippet:
Formatting Data Using XSL Formatting Objects (Contd.)
This element defines a template
with the name right.
This specifies that the left margin
of the template is set to 5 inches.
This specifies that the right margin
of the template is set to 2 inches.
8/13/2019 XML_Session05
22/33Slide 22 of 33Ver. 1.0
Extensible Markup Language
Session 5
A template rule:
Describes how an XML element and its contents are converted
into a specific format for displaying in the browser.
Consists of two parts:
A pattern that identifies an XML element in an XML document.
An action or processing code that details the transformation and
rendering of the resulting element.
XSLT uses two main elements for creating template rules:
template
apply-templates
Creating XSLT Template Rules
8/13/2019 XML_Session05
23/33
Slide 23 of 33Ver. 1.0
Extensible Markup Language
Session 5
A template rule:
Describes how an XML element and its contents are converted
into a specific format for displaying in the browser.
Consists of two parts:
A pattern that identifies an XML element in an XML document.
An action or processing code that details the transformation and
rendering of the resulting element.
XSLT uses two main elements for creating template rules:
template
apply-templates
Creating XSLT Template Rules (Contd.)
Defines a template for the desired
output.
Follows the syntax:
[action to be taken]
8/13/2019 XML_Session05
24/33
Slide 24 of 33Ver. 1.0
Extensible Markup Language
Session 5
A template rule:
Describes how an XML element and its contents are converted
into a specific format for displaying in the browser.
Consists of two parts:
A pattern that identifies an XML element in an XML document.
An action or processing code that details the transformation and
rendering of the resulting element.
XSLT uses two main elements for creating template rules:
template
apply-templates Instructs the XSLT processor to find an
appropriate template and perform the specifiedtasks on selected elements.
Follows the syntax:
Creating XSLT Template Rules (Contd.)
8/13/2019 XML_Session05
25/33
Slide 25 of 33Ver. 1.0
Extensible Markup Language
Session 5
Problem Statement:
CyberShoppe needs to display product details, such as
product ID, name, and price per unit. The following figure
depicts a sample output.
The details about the products should be displayed in red.
Demo: Creating an XSLT Style Sheet to Format Data
8/13/2019 XML_Session05
26/33
Slide 26 of 33Ver. 1.0
Extensible Markup Language
Session 5
The various departments of a university store data in
different formats. The IT department of the university
decides to use XML as the data interchange format to
transmit the data between the departments. Which of the
following would be the best approach to accomplish the task
using XML?
a. Devise a common information model and enforce its use by all
the departments that need to exchange data.
b. Implement a conversion application that can handle the data
received from other departments.
Practice Questions
8/13/2019 XML_Session05
27/33
Slide 27 of 33Ver. 1.0
Extensible Markup Language
Session 5
c. Use an XSLT style sheet to convert the incoming or outgoing
XML document into the format used within the departments.
d. Modify the XML schema to use the same content model in all
departments.
Answer:
c. Use an XSLT style sheet to convert the incoming or outgoing
XML document into the format used within the departments.
Practice Questions (Contd.)
8/13/2019 XML_Session05
28/33
Slide 28 of 33Ver. 1.0
Extensible Markup Language
Session 5
Which of the following code snippets can be used in an XMLdocument named Test.xml to associate it with a style
sheet named Test.css?
a.
b.
c.
d.
Practice Questions
Answer:
a.
8/13/2019 XML_Session05
29/33
Slide 29 of 33Ver. 1.0
Extensible Markup Language
Session 5
Consider the following statements:
Statement A: CSS can be used to reorder, add, delete, or
perform other operations on elements.
Statement B: CSS uses less memory when compared to
XSLT.Which of the following is correct about the preceding
statements?
a. Statement A is True, and Statement B is False.
b. Statement A is False, and Statement B is True.
c. Both, Statement A and Statement B, are True.d. Both, Statement A and Statement B, are False.
Answer:
b. Statement A is False, and Statement B is True.
Practice Questions
8/13/2019 XML_Session05
30/33
Slide 30 of 33Ver. 1.0
Extensible Markup Language
Session 5
Which element must contain one or more when elements?
a. xsl:if
b. xsl:for-each
c. xsl:sort
d. xsl:choose
Answer:
d. xsl:choose
Practice Questions
8/13/2019 XML_Session05
31/33
8/13/2019 XML_Session05
32/33
Slide 32 of 33Ver. 1.0
Extensible Markup Language
Session 5
In this session, you learned that:
Rendering is the process of formatting and presenting the data
in an XML document in different formats.
A style sheet is a document that contains the formatting rules
for one or several XML documents. The two types of style
sheets that can be used with XML documents are:CSS
XSL
CSS is used to define the style or appearance of an XML
document.
XSL is made up of XSLT and XPath.XSLT is used to display selective elements or attributes, sort
data on one or more elements, and process the data based on
conditions.
Summary
8/13/2019 XML_Session05
33/33
Extensible Markup Language
The XSLT processor applies the transformation information
contained in the XSLT style sheet and builds a resultant tree
structure, which is then rendered to various targets.
XSLT elements, such as template, apply-templates,
sort, for-each, and value-ofare used to extract and
format data.XSL-FO provides formatting objects to break XML documents
into pages, paragraphs, and lists. The associated properties of
the formatting objects allow you to format the XML documents.
A template rule describes how an XML element and its
contents are converted into a format that can be displayed in
the browser.
Summary (Contd.)