SlideShare a Scribd company logo
1 of 108
SOA
Dr.Smitha.P.S
Associate Professor
Velammal Engineering College
IT8074-SOA
IT8074 SERVICE ORIENTED ARCHITECTURE
Objectives
∙ To learn fundamentals of XML
∙ To provide an overview of Service Oriented
Architecture and Web services and their
importance
∙ To learn web services standards and technologies
∙ To learn service oriented analysis and design for
developing SOA based applications
COURSE OUTCOMES
•Understand XML technologies
•Understand service orientation, benefits of SOA
•Understand web services and WS standards
•Use web services extensions to develop solutions
•Understand and apply service modeling, service
oriented analysis and design for application development
UNIT I
XML document structure – Well-formed and
valid documents – DTD – XML Schema –
Parsing XML using DOM, SAX – XPath - XML
Transformation and XSL – Xquery
1.0 XML document Structure
• XML documents form a tree structure that
starts at "the root" and branches to "the
leaves".
XML Tree Structure
• XML documents are formed as element trees.
• An XML tree starts at a root element and branches from the root to
child elements.
• All elements can have sub elements (child elements):
• <root>
<child>
<subchild>.....</subchild>
</child>
</root>
• The terms parent, child, and sibling are used to describe the
relationships between elements.
• Parent have children. Children have parents. Siblings are children
on the same level (brothers and sisters).
• All elements can have text content (Harry Potter) and attributes
(category="cooking").
SYNTAX
• XML uses a much self-describing syntax.
• A prolog defines the XML version and the character encoding:
• <?xml version="1.0" encoding="UTF-8"?>
• The next line is the root element of the document:
• <bookstore>
• The next line starts a <book> element:
• <book category="cooking">
• The <book> elements have 4 child elements: <title>,< author>, <year>, <price>.
• <title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
• The next line ends the book element:
• </book>
• </bookstore>
2.0 DTD(Document Type Definition)
A DTD defines the structure and the legal
elements and attributes of an XML document.
XML document with an internal DTD
• <?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
DTD
• The DTD above is interpreted like this:
• !DOCTYPE note defines that the root element of this
document is note
• !ELEMENT note defines that the note element must
contain four elements: "to,from,heading,body"
• !ELEMENT to defines the to element to be of type
"#PCDATA"
• !ELEMENT from defines the from element to be of type
"#PCDATA"
• !ELEMENT heading defines the heading element to be of
type "#PCDATA"
• !ELEMENT body defines the body element to be of type
"#PCDATA"
External DTD
An External DTD Declaration
• If the DTD is declared in an external file, the <!DOCTYPE>
definition must contain a reference to the DTD file:
• XML document with a reference to an external DTD
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
External DTD
note.dtd
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
DTD - XML Building Blocks
The Building Blocks of XML Documents
Seen from a DTD point of view, all XML
documents are made up by the following
building blocks:
• Elements
• Attributes
• Entities
• PCDATA
• CDATA
DTD-XML BUILDING BLOCKS
ELEMENTS
<body>some text</body>
ATTRIBUTES
<img src="computer.gif" />
ENTITY
Entity References Character
&lt; <
&gt; >
&amp; &
&quot; "
&apos; '
DTD-XML BUILDING BLOCKS
PCDATA
• PCDATA means parsed character data.
• Think of character data as the text found between the start tag and the end
tag of an XML element.
• PCDATA is text that WILL be parsed by a parser. The text will be
examined by the parser for entities and markup.
• Tags inside the text will be treated as markup and entities will be expanded.
• However, parsed character data should not contain any &, <, or >
characters; these need to be represented by the &amp; &lt; and &gt;
entities, respectively.
CDATA
• CDATA means character data.
• CDATA is text that will NOT be parsed by a parser. Tags inside the text
will NOT be treated as markup and entities will not be expanded.
DTD - Elements
Declaring Elements
• In a DTD, XML elements are declared with the following syntax:
• <!ELEMENT element-name category>
or
<!ELEMENT element-name (element-content)>
Empty Elements
• Empty elements are declared with the category keyword EMPTY:
<!ELEMENT element-name EMPTY>
Example:
<!ELEMENT br EMPTY>
XML example:
<br />
DTD - Elements
Elements with Parsed Character Data
• Elements with only parsed character data are declared with #PCDATA
inside parentheses:
• <!ELEMENT element-name (#PCDATA)>
Example:
<!ELEMENT from (#PCDATA)>
Elements with any Contents
• Elements declared with the category keyword ANY, can contain any
combination of parsable data:
• <!ELEMENT element-name ANY>
Example:
<!ELEMENT note ANY>
DTD ELEMENTS-? sign
Declaring zero or one occurrences of the same
element example:
The ? sign in the example above declares that
the child element message can occur zero or
one times inside the "note” element
<!ELEMENT element name(child name?)>
Example
<!ELEMENT note(message?)>
DTD Elements
Elements with Children (sequences)
• Elements with one or more children are declared with the
name of the children elements inside parentheses:
• <!ELEMENT element-name (child1)>
or
<!ELEMENT element-name (child1,child2,...)>
Example:
<!ELEMENT note (to,from,heading,body)>
• When children are declared in a sequence separated by
commas, the children must appear in the same sequence in
the document
DTD Elements
Declaring Minimum One Occurrence of an Element
• <!ELEMENT element-name (child-name+)>
Example:
<!ELEMENT note (message+)>
• The + sign in the example above declares that the child element
"message" must occur one or more times inside the "note" element.
Declaring Zero or More Occurrences of an Element
• <!ELEMENT element-name (child-name*)>
Example:
<!ELEMENT note (message*)>
• The * sign in the example above declares that the child element
"message" can occur zero or more times inside the "note" element.
DTD Elements
Declaring either/or Content
• <!ELEMENT note (to,from,header,(message|body))>
• The example above declares that the "note" element must
contain a "to" element, a "from" element, a "header"
element, and either a "message" or a "body" element.
Declaring Mixed Content
• <!ELEMENT note (#PCDATA|to|from|header|message)*>
• The example above declares that the "note" element can
contain zero or more occurrences of parsed character data,
"to", "from", "header", or "message" elements.
DTD - Attributes
Declaring Attributes
• An attribute declaration has the following syntax:
• <!ATTLIST element-name attribute-name attribute-
type attribute-value>
DTD example:
<!ATTLIST payment type CDATA "check">
XML example:
<payment type="check" />
DTD Attributes
The attribute-type can be one of the following:
Type Description
CDATA The value is character data
(en1|en2|..) The value must be one from an enumerated
list
ID The value is a unique id
IDREF The value is the id of another element
IDREFS The value is a list of other ids
NMTOKEN The value is a valid XML name
NMTOKENS The value is a list of valid XML names
ENTITY The value is an entity
ENTITIES The value is a list of entities
NOTATION The value is a name of a notation
DTD Attributes
The attribute-value can be one of the following:
Value Explanation
value The default value of the
attribute
#REQUIRED The attribute is required
#IMPLIED The attribute is optional
#FIXED value The attribute value is fixed
DTD Attributes
A Default Attribute Value
• DTD:
<!ELEMENT square EMPTY>
<!ATTLIST square width CDATA "0">
Valid XML:
<square width="100" />
• In the example above, the "square" element is defined to
be an empty element with a "width" attribute of type
CDATA. If no width is specified, it has a default value of 0.
DTD Attributes
#REQUIRED
Syntax
<!ATTLIST element-name attribute-name attribute-type #REQUIRED>
Example
DTD:
<!ATTLIST person number CDATA #REQUIRED>
Valid XML:
<person number="5677" />
Invalid XML:
<person />
• Use the #REQUIRED keyword if you don't have an option for a default value, but
still want to force the attribute to be present.
DTD Attributes
#IMPLIED
Syntax
<!ATTLIST element-name attribute-name attribute-type #IMPLIED>
Example
DTD:
<!ATTLIST contact fax CDATA #IMPLIED>
Valid XML:
<contact fax="555-667788" />
Valid XML:
<contact />
Use the #IMPLIED keyword if you don't want to force the author to include an
attribute, and you don't have an option for a default value.
DTD Attributes
#FIXED
Syntax
• <!ATTLIST element-name attribute-name attribute-type #FIXED "value">
• Example
• DTD:
<!ATTLIST sender company CDATA #FIXED "Microsoft">
Valid XML:
<sender company="Microsoft" />
Invalid XML:
<sender company="W3Schools" />
• Use the #FIXED keyword when you want an attribute to have a fixed value without allowing the author to
change it. If an author includes another value, the XML parser will return an error.
Enumerated Attribute Values
Syntax
• <!ATTLIST element-name attribute-name (en1|en2|..) default-value>
• Example
• DTD:
<!ATTLIST payment type (check|cash) "cash">
XML example:
<payment type="check" />
or
<payment type="cash" />
• Use enumerated attribute values when you want the attribute value to be one of a fixed set of legal values.
DTD - Entities
• Entities are used to define shortcuts to special characters.
• Entities can be declared internal or external.
An Internal Entity Declaration
Syntax
<!ENTITY entity-name "entity-value">
Example
DTD Example:
<!ENTITY writer "Donald Duck.">
<!ENTITY copyright "Copyright W3Schools.">
XML example:
<author>&writer;&copyright;</author>
• Note: An entity has three parts: an ampersand (&), an entity name, and a semicolon
(;).
DTD - Entities
An External Entity Declaration
Syntax
<!ENTITY entity-name SYSTEM "URI/URL">
Example
DTD Example:
<!ENTITY writer SYSTEM
"https://www.w3schools.com/entities.dtd">
<!ENTITY copyright SYSTEM
"https://www.w3schools.com/entities.dtd">
XML example:
<author>&writer;&copyright;</author>
DTD-Examples
Newspaper Article DTD
<!DOCTYPE NEWSPAPER [
<!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLINE (#PCDATA)>
<!ELEMENT LEAD (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)>
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
<!ENTITY NEWSPAPER "Vervet Logic Times">
<!ENTITY PUBLISHER "Vervet Logic Press">
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">
]>
DTD Examples
TV Schedule DTD
<!DOCTYPE TVSCHEDULE [
<!ELEMENT TVSCHEDULE (CHANNEL+)>
<!ELEMENT CHANNEL (BANNER,DAY+)>
<!ELEMENT BANNER (#PCDATA)>
<!ELEMENT DAY (DATE,(HOLIDAY|PROGRAMSLOT+)+)>
<!ELEMENT HOLIDAY (#PCDATA)>
<!ELEMENT DATE (#PCDATA)>
<!ELEMENT PROGRAMSLOT (TIME,TITLE,DESCRIPTION?)>
<!ELEMENT TIME (#PCDATA)>
<!ELEMENT TITLE (#PCDATA)>
<!ELEMENT DESCRIPTION (#PCDATA)>
<!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED>
<!ATTLIST CHANNEL CHAN CDATA #REQUIRED>
<!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED>
<!ATTLIST TITLE RATING CDATA #IMPLIED>
<!ATTLIST TITLE LANGUAGE CDATA #IMPLIED>
]>
3.0 Well formed and Valid XML
Documents
Well formed XML Document
• The XML specification defines a set of rules that XML documents must follow
in order to be well-formed.
• If an XML document is not well-formed according to the XML specification,
browsers, for example, should not make any attempt at correcting the errors
as they did for HTML documents.
• The following text demonstrates a complete, well-formed XML document:
<greeting>
Hello, World!
</greeting>
II. Valid xml document
If an XML document is well-formed and has an associated Document Type
Declaration (DTD), then it is said to be a valid XML document.
Valid and well-formed XML document
with DTD
Let's take an example of well-formed and valid XML document. It follows all the rules of DTD.
employee.xml
<?xml version="1.0"?>
<!DOCTYPE employee SYSTEM "employee.dtd">
<employee>
<firstname>vimal</firstname>
<lastname>jaiswal</lastname>
<email>vimal@javatpoint.com</email>
</employee>
• In the above example, the DOCTYPE declaration refers to an external DTD file. The content of
the file is shown in below paragraph.
employee.dtd
<!ELEMENT employee (firstname,lastname,email)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT email (#PCDATA)>
•
WELL FORMED XML Document
Well-formed XML Document
• An XML document is said to be well-formed if it adheres to the following rules −
• Non DTD XML files must use the predefined character entities for amp(&), apos(single
quote), gt(>), lt(<), quot(double quote).
• It must follow the ordering of the tag. i.e., the inner tag must be closed before closing the outer tag.
• Each of its opening tags must have a closing tag or it must be a self ending tag.(<title>....</title> or
<title/>).
• It must have only one attribute in a start tag, which needs to be quoted.
• amp(&), apos(single quote), gt(>), lt(<), quot(double quote) entities other than these must be declared.
Example
Following is an example of a well-formed XML document −
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
<!DOCTYPE address [ <!ELEMENT address (name,company,phone)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)> ]>
XML File
<address>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</address>
4.0 XML SCHEMA
• An XML Schema describes the structure of an XML document.
• The XML Schema language is also referred to as XML Schema Definition (XSD).
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The note element is a complex type because it contains other elements. The other
elements (to, from, heading, body) are simple types because they do not contain
other elements.
XML NAMESPACE
Solving the Name Conflict Using a Prefix
• Name conflicts in XML can easily be avoided using a name prefix.
• This XML carries information about an HTML table, and a piece of
furniture:
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
• In the example above, there will be no conflict because the two
<table> elements have different name
XML NAMESPACE
XML Namespaces provide a method to avoid element name conflicts.
Name Conflicts
• In XML, element names are defined by the developer. This often results in a conflict
when trying to mix XML documents from different XML applications.
• This XML carries HTML table information:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
This XML carries information about a table (a piece of furniture):
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
• If these XML fragments were added together, there would be a name conflict. Both
contain a <table> element, but the elements have different content and meaning.
• A user or an XML application will not know how to handle these differences.
XML NAMESPACE
• XML Namespaces - The xmlns Attribute
• When using prefixes in XML, a namespace for
the prefix must be defined.
• The namespace can be defined by an xmlns
attribute in the start tag of an element.
• The namespace declaration has the following
syntax. xmlns:prefix="URI".
XML NAMESPACE
<root
xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="http://www.w3schools.com/furniture">
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
• Note: The namespace URI is not used by the parser to look up information.
• The purpose of using an URI is to give the namespace a unique name.
• However, companies often use the namespace as a pointer to a web page
containing namespace information.
XSD - The <schema> Element
The <schema> Element
• The <schema> element is the root element of
every XML Schema:
• <?xml version="1.0"?>
<xs:schema>
...
...
</xs:schema>
XSD - The <schema>
Declaration Element
• The <schema> element may contain some
attributes. A schema declaration often looks
something like this:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/
XMLSchema"
targetNamespace="https://www.xxx.com"
xmlns="https://xxx.com"
elementFormDefault="qualified">
...
...
</xs:schema>
XSD - The <schema> Element
xmlns:xs="http://www.w3.org/2001/XMLSchem
a"
• indicates that the elements and data types
used in the schema come from the
"http://www.w3.org/2001/XMLSchema"
namespace. It also specifies that the elements
and data types that come from the
"http://www.w3.org/2001/XMLSchema"
namespace should be prefixed with xs:
XSD - The <schema> Element
This fragment:
targetNamespace="https://www.xxx.com"
• indicates that the elements defined by this
schema (note, to, from, heading, body.) come
from the "https://www.xxx.com" namespace.
XSD - The <schema> Element
This fragment:
xmlns="https://www.xxx.com"
• indicates that the default namespace is
"https://www.xxx.com".
This fragment:
elementFormDefault="qualified"
• indicates that any elements used by the XML
instance document which were declared in
this schema must be namespace qualified.
XSD Simple Elements
A simple element is an XML element that can
contain only text. It cannot contain any other elements or
attributes.
Defining a Simple Element
The syntax for defining a simple element is:
<xs:element name="xxx" type="yyy"/>
• where xxx is the name of the element and yyy is the data
type of the element.
• XML Schema has a lot of built-in data types. The most
common types are:
• xs:string
• xs:decimal
• xs:integer
• xs:boolean
• xs:date
• xs:time
XSD Simple Elements
Example
Here are some XML elements:
<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>
And here are the corresponding simple element
definitions:
<xs:element name="lastname" type="xs:string"/>
<xs:element name="age" type="xs:integer"/>
<xs:element name="dateborn" type="xs:date"/>
Default and Fixed Values for Simple
Elements
• A default value is automatically assigned to the
element when no other value is specified.
• In the following example the default value is "red":
<xs:element name="color" type="xs:string" default=
"red"/>
• A fixed value is also automatically assigned to the
element, and you cannot specify another value.
• In the following example the fixed value is "red":
<xs:element name="color" type="xs:string" fixed=
"red"/>
XSD Attributes
What is an Attribute?
Simple elements cannot have attributes. If an element has attributes, it is
considered to be of a complex type. But the attribute itself is always
declared as a simple type.
How to Define an Attribute?
The syntax for defining an attribute is:
<xs:attribute name="xxx" type="yyy"/>
• where xxx is the name of the attribute and yyy specifies the data type of
the attribute.
• XML Schema has a lot of built-in data types. The most common types are:
• xs:string
• xs:decimal
• xs:integer
• xs:boolean
• xs:date
• xs:time
XSD Attributes
Example
• Here is an XML element with an attribute:
<lastname lang="EN">Smith</lastname>
• And here is the corresponding attribute
definition:
<xs:attribute name="lang" type="xs:string"/>
Default and Fixed Values for Attributes
• Attributes may have a default value or a fixed value specified.
• A default value is automatically assigned to the attribute when
no other value is specified.
• In the following example the default value is "EN":
• <xs:attribute name="lang" type="xs:string" default="EN"/>
• A fixed value is also automatically assigned to the attribute,
and you cannot specify another value.
• In the following example the fixed value is "EN":
• <xs:attribute name="lang" type="xs:string" fixed="EN"/>
Optional and Required Attributes
• Attributes are optional by default. To specify that the attribute
is required, use the "use" attribute:
• <xs:attribute name="lang" type="xs:string" use="required"/>
XSD Restrictions/Facets
Restrictions are used to define acceptable values for XML
elements or attributes. Restrictions on XML elements
are called facets.
Restrictions on Values
• The following example defines an element called "age"
with a restriction. The value of age cannot be lower
than 0 or greater than 120:
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XSD Restrictions/Facets
Restrictions on a Set of Values
• To limit the content of an XML element to a set of acceptable
values, we would use the enumeration constraint.
• The example below defines an element called "car" with a
restriction. The only acceptable values are: Audi, Golf, BMW:
<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XSD Restrictions/Facets
Restrictions on a Series of Values
• To limit the content of an XML element to define a series of
numbers or letters that can be used, we would use the
pattern constraint.
• The example below defines an element called "letter" with
a restriction. The only acceptable value is ONE of the
LOWERCASE letters from a to z:
• <xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XSD Restrictions/Facets
Other Restrictions on a Series of Values
• The example below defines an element called "letter"
with a restriction. The acceptable value is zero or more
occurrences of lowercase letters from a to z:
• <xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-z])*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XSD Restrictions/Facets
The next example defines an element called "initials" with a restriction.
The only acceptable value is THREE of the UPPERCASE letters from a to z:
<xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z][A-Z][A-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
The next example also defines an element called "initials" with a
restriction. The only acceptable value is THREE of the LOWERCASE OR
UPPERCASE letters from a to z:
<xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XSD Restrictions/Facets
The next example defines an element called "gender" with a restriction. The
only acceptable value is male OR female:
<xs:element name="gender">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="male|female"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
The next example defines an element called "password" with a restriction.
There must be exactly eight characters in a row and those characters must
be lowercase or uppercase letters from a to z, or a number from 0 to 9:
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]{8}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XSD Restrictions/Facets
Restrictions on Whitespace Characters
• To specify how whitespace characters should be handled, we would use the whiteSpace
constraint.
• This example defines an element called "address" with a restriction. The whiteSpace
constraint is set to "preserve", which means that the XML processor WILL NOT remove any
white space characters:
• <xs:element name="address">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
• This example also defines an element called "address" with a restriction. The whiteSpace
constraint is set to "replace", which means that the XML processor WILL REPLACE all white
space characters (line feeds, tabs, spaces, and carriage returns) with spaces:
• <xs:element name="address">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="replace"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XSD Restrictions/Facets
• This example also defines an element called "address" with
a restriction. The whiteSpace constraint is set to "collapse",
which means that the XML processor WILL REMOVE all
white space characters (line feeds, tabs, spaces, carriage
returns are replaced with spaces, leading and trailing
spaces are removed, and multiple spaces are reduced to a
single space):
• <xs:element name="address">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XSD Restrictions/Facets
Restrictions on Length
• To limit the length of a value in an element, we would use the length,
maxLength, and minLength constraints.
• This example defines an element called "password" with a restriction. The
value must be exactly eight characters:
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
• This example defines another element called "password" with a restriction.
The value must be minimum five characters and maximum eight characters:
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions for Datatypes
Constraint Description
enumeration Defines a list of acceptable values
fractionDigits Specifies the maximum number of decimal places allowed.
Must be equal to or greater than zero
length Specifies the exact number of characters or list items
allowed. Must be equal to or greater than zero
maxExclusive Specifies the upper bounds for numeric values (the value
must be less than this value)
maxInclusive Specifies the upper bounds for numeric values (the value
must be less than or equal to this value)
maxLength Specifies the maximum number of characters or list items
allowed. Must be equal to or greater than zero
minExclusive Specifies the lower bounds for numeric values (the value
must be greater than this value)
Restrictions for Datatypes
minInclusive Specifies the lower bounds for numeric
values (the value must be greater than or
equal to this value)
minLength Specifies the minimum number of
characters or list items allowed. Must be
equal to or greater than zero
pattern Defines the exact sequence of characters
that are acceptable
totalDigits Specifies the exact number of digits
allowed. Must be greater than zero
whiteSpace Specifies how white space (line feeds,
tabs, spaces, and carriage returns) is
handled
XSD Complex Elements
A complex element contains other elements and/or attributes.
• We can define a complex element in an XML Schema two
different ways:
1. The "employee" element can be declared directly by naming
the element, like this:
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
If you use the method described above, only the "employee"
element can use the specified complex type. Note that the child
elements, "firstname" and "lastname", are surrounded by the
<sequence> indicator. This means that the child elements must
appear in the same order as they are declared.
XSD Complex Elements
2. The "employee" element can have a type attribute that refers to the name of
the complex type to use:
<xs:element name="employee" type="personinfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
If you use the method described above, several elements can refer to the same
complex type, like this:
<xs:element name="employee" type="personinfo"/>
<xs:element name="student" type="personinfo"/>
<xs:element name="member" type="personinfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
XSD Indicators
There are seven indicators:
Order indicators:
• All
• Choice
• Sequence
Occurrence indicators:
• maxOccurs
• minOccurs
Group indicators:
• Group name
• attributeGroup name
Order Indicators
Order indicators are used to define the order of the
elements.
• All Indicator
• The <all> indicator specifies that the child elements can
appear in any order, and that each child element must
occur only once:
<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
Choice Indicator
• The <choice> indicator specifies that either one
child element or another can occur:
• <xs:element name="person">
<xs:complexType>
<xs:choice>
<xs:element name="employee" type="employee"/>
<xs:element name="member" type="member"/>
</xs:choice>
</xs:complexType>
</xs:element>
Sequence Indicator
• The <sequence> indicator specifies that the child
elements must appear in a specific order:
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string
"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Occurrence Indicators
Occurrence indicators are used to define how
often an element can occur.
maxOccurs Indicator
The <maxOccurs> indicator specifies the
maximum number of times an element can
occur
minOccurs Indicator
The <minOccurs> indicator specifies the
minimum number of times an element can
occur:
Occurrence Indicators
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string"
maxOccurs="10" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
• The example above indicates that the "child_name"
element can occur a minimum of zero times and a
maximum of ten times in the "person" element.
• Tip: To allow an element to appear an unlimited number
of times, use the maxOccurs="unbounded" statement:
Group Indicators
Group indicators are used to define related sets of elements.
<xs:group name="persongroup">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="birthday" type="xs:date"/>
</xs:sequence>
</xs:group>
<xs:element name="person" type="personinfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:group ref="persongroup"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
Attribute Groups
• Attribute groups are defined with the attributeGroup declaration,
like this:
• <xs:attributeGroup name="groupname">
...
</xs:attributeGroup>
Example
<xs:attributeGroup name="personattrgroup">
<xs:attribute name="firstname" type="xs:string"/>
<xs:attribute name="lastname" type="xs:string"/>
<xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>
<xs:element name="person">
<xs:complexType>
<xs:attributeGroup ref="personattrgroup"/>
</xs:complexType>
</xs:element>
XML SCHEMA EXAMPLE
An XML Document
Let's have a look at this XML document called "shiporder.xml":
<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
• The XML document above consists of a root element, "shiporder", that contains a required attribute called "orderid".
The "shiporder" element contains three different child elements: "orderperson", "shipto" and "item". The "item"
element appears twice, and it contains a "title", an optional "note" element, a "quantity", and a "price" element.
• The line above: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tells the XML parser that this document
should be validated against a schema. The line: xsi:noNamespaceSchemaLocation="shiporder.xsd" specifies WHERE
the schema resides (here it is in the same folder as "shiporder.xml").
XML SCHEMA
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
5.0 TRANSFORMATIONS AND XSL
XSL TECHNOLOGIES
• XSL(XML style sheet language) has two independent
languages:
– The XSL Transformation Language(XSLT)
– The XSL Formatting object language(XSL-FO)
• XSLT is used to convert an XML document to another
format. XSL-FO provides a way of describing the
presentation of an XML document.
• Correct Style Sheet Declaration
• The root element that declares the document to be an
XSL style sheet is <xsl:stylesheet> or <xsl:transform>.
XSLT
The <xsl:template> Element
• The <xsl:template> element is used to build templates.
• The match attribute is used to associate a template
with an XML element. The match attribute can also be
used to define a template for the entire XML
document. The value of the match attribute is an XPath
expression (i.e. match="/" defines the whole
document).
XSLT <xsl:value-of> Element
• The <xsl:value-of> element can be used to extract the
value of an XML element and add it to the output
stream of the transformation.
XSLT
The <xsl:for-each> Element
• The XSL <xsl:for-each> element can be used to select every
XML element of a specified node-set:
• Filtering the Output
• We can also filter the output from the XML file by adding a
criterion to the select attribute in the <xsl:for-each>
element.
<xsl:for-each select="catalog/cd[artist='Bob Dylan']">
• Legal filter operators are:
• = (equal)
• != (not equal)
• &lt; less than
• &gt; greater than
XSLT <xsl:sort> Element
• The <xsl:sort> element is used to sort the output.
XSLT
XSLT <xsl:if> Element
• The <xsl:if> element is used to put a conditional test
against the content of the XML file.
The <xsl:if> Element
• To put a conditional if test against the content of the
XML file, add an <xsl:if> element to the XSL document.
• Syntax
• <xsl:if test="expression">
...some output if the expression is true...
</xsl:if>
XSLT <xsl:choose> Element
• The <xsl:choose> element is used in conjunction with
<xsl:when> and <xsl:otherwise> to express multiple
conditional tests.
XSL Examples
cdcatalog.xml
<catalog>
<cd><title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year></cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
</catalog>
Create an XSL Style Sheet
Then you create an XSL Style Sheet ("cdcatalog.xsl") with a transformation template:
<?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>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Link the XSL Style Sheet to the XML Document
• Add the XSL style sheet reference to your XML document ("cdcatalog.xml"):
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
Output
My CD Collection
Title Artist
Empire Burlesque Bob Dylan
Hide your heart Bonnie Tyler
Greatest Hits Dolly Parton
Create an XSL Style Sheet
Example for XSLT <xsl:sort> Element
<?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>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:sort select="artist"/>
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output
My CD Collection
Title Artist
Empire Burlesque Bob Dylan
Hide your heart Bonnie Tyler
Greatest Hits Dolly Parton
XSLT <xsl:if> Element
<?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>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
<th>Price</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:if test="price &gt; 10">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output
My CD Collection
Title Artist
Price
Empire Burlesque Bob Dylan 10.90
XSLT <xsl:choose> Element
<?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>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price &gt; 10">
<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output
My CD Collection
Title Artist
Empire Burlesque Bob Dylan
Hide your heart Bonnie Tyler
Greatest Hits Dolly Parton
XSL FORMATTING
• The World Wide Web Consortium's specification for Extensible
Stylesheet Language (XSL) comes in two parts:
• XSLT, a language for transforming XML documents, and
• XSL Formatting Objects (XSL FO), an XML vocabulary for specifying
formatting semantics.
• XSL Formatting Objects is itself an XML-based markup language
that lets you specify in great detail the pagination, layout, and
styling information that will be applied to your content.
• The XSL FO markup is quite complex. It is also verbose; virtually the
only practical way to produce an XSL FO file is to use XSLT to
produce a source document.
• Finally, once you have this XSL FO file, you need some way to
render it to an output medium. There are few tools available to do
this final step. For these reasons, XML FO has not caught on as
quickly as XSLT.
Initialization
• Since the XSL FO file will be an XML document, it
must begin with the standard XML processing
instruction and the FO root element.
• <?xml version="1.0" encoding="utf-8"?>
• <fo:root>
• The structure of the remainder of the document
is:
• The layout master set, which consists of
– Descriptions of the kinds of pages that can occur in
the document.
– Sequences in which those page formats can occur.
• The pages and their content.
Page Layouts
Document will have three kinds of pages
shown in the diagram below. To
accommodate the stapling area, the cover
page and right-hand pages will have more
margin space at the left. The content pages
will also have a region for a header and
footer.
Page Layout
The units below are all in centimeters, but you
may use any of the CSS units, such as px
(pixel), pt (point), em, in, mm, etc. Each of
these specifications is called a simple-page-
master and must be given a master-name so
you can refer to it later.
Page Layout
<fo:layout-master-set>
<fo:simple-page-master master-name="cover"
page-height="12cm"
page-width="12cm"
margin-top="0.5cm"
margin-bottom="0.5cm"
margin-left="1cm"
margin-right="0.5cm">
</fo:simple-page-master>
Page Layout
<fo:simple-page-master master-name="leftPage"
page-height="12cm"
page-width="12cm"
margin-left="0.5cm"
margin-right="1cm"
margin-top="0.5cm"
margin-bottom="0.5cm">
</fo:simple-page-master>
Page Layout
<fo:simple-page-master master-name="rightPage"
page-height="12cm"
page-width="12cm"
margin-left="1cm"
margin-right="0.5cm"
margin-top="0.5cm"
margin-bottom="0.5cm">
</fo:simple-page-master>
<!-- more info will go here -->
</fo:layout-master-set>
The margins are areas which will not contain any printed
output.
The content area
This is the page content area (officially called
the page-reference-area), which can be
divided into five regions as shown below.
Content Area-Cover Page
• The cover page doesn't need a header or footer, so we
need only specify information for the region-body by
adding the information shown in bold below.
<fo:simple-page-master master-name="cover"
page-height="12cm"
page-width="12cm"
margin-top="0.5cm"
margin-bottom="0.5cm"
margin-left="1cm"
margin-right="0.5cm">
<fo:region-body
margin-top="3cm" />
</fo:simple-page-master>
Content Area-Left Page
The left and right pages will have a header and footer, so we
must specify the extent of the region-before and region-
after.
<fo:simple-page-master master-name="leftPage"
page-height="12cm"
page-width="12cm"
margin-left="0.5cm"
margin-right="1cm"
margin-top="0.5cm"
margin-bottom="0.5cm">
<fo:region-before extent="1cm"/>
<fo:region-after extent="1cm"/>
<fo:region-body
margin-top="1.1cm"
margin-bottom="1.1cm" />
</fo:simple-page-master>
Content Area-Right Page
<fo:simple-page-master master-name="rightPage"
page-height="12cm"
page-width="12cm"
margin-left="1cm"
margin-right="0.5cm"
margin-top="0.5cm"
margin-bottom="0.5cm">
<fo:region-before extent="1cm"/>
<fo:region-after extent="1cm"/>
<fo:region-body
margin-top="1.1cm"
margin-bottom="1.1cm" />
</fo:simple-page-master>
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> and <fo:flow>
elements
• The <fo:static-content> element is used for page headers and footers.For example
we can define a header for the company name and page number and this
information will appear on every page.
• 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> elements. 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.
Example
Ez book online
Welcome to Ez books online in the worlds smallest online book store
Code fragment
<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”
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=”24pt”
Text-align=”justify”>
Welcome to Ez books online in the worlds smallest online book store
</fo:block>
</fo:flow>
</fo:page sequence>
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>
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. The <fo:block> element uses the text-align attribute to
place the text at the end of the region. The above example uses the
English language, so the text is right justified. The current page number
is determined using the <fo:page-number> element.
Page headers and footers
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.
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.
• The following code fragment inserts the image
smiley.jpg
• <fo:block text-align=”center”>
• <fo:external-graphic src=”smiley.jpg”width=”200px”
height=”200px”/>
• </fo:block>
XSL-FO Tables
• The XSL-FO table model is not very different from the HTML table model.
• There are nine XSL-FO objects used to create tables:
• fo:table-and-caption
• fo:table
• fo:table-caption
• fo:table-column
• fo:table-header
• fo:table-footer
• fo:table-body
• fo:table-row
• fo:table-cell
• XSL-FO uses the <fo:table-and-caption> element to define a table. It
contains a <fo:table> and an optional <fo:caption> element.
• The <fo:table> element contains optional <fo:table-column> elements, an
optional <fo:table-header> element, a <fo:table-body> element, and an
optional <fo:table-footer> element. Each of these elements has one or
more <fo:table-row> elements, with one or more <fo:table-cell>
elements:
XSL FO TABLES
<fo:table-and-caption>
<fo:table>
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-header>
<fo:table-row>
<fo:table-cell>
<fo:block font-weight="bold">Car</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight="bold">Price</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>Volvo</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>$50000</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>SAAB</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>$48000</fo:block>
</fo:table-cell>
</fo:table-row></fo:table-
body> </fo:table></fo:table-and-caption>
OUTPUT
Car Price
Volvo $50000
SAAB $48000
It8074 soa-unit i

More Related Content

What's hot (20)

Dtd
DtdDtd
Dtd
 
DTD
DTDDTD
DTD
 
Xml
XmlXml
Xml
 
XML's validation - XML Schema
XML's validation - XML SchemaXML's validation - XML Schema
XML's validation - XML Schema
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Document Type Definitions
Document Type DefinitionsDocument Type Definitions
Document Type Definitions
 
XML's validation - DTD
XML's validation - DTDXML's validation - DTD
XML's validation - DTD
 
Xml schema
Xml schemaXml schema
Xml schema
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
XML DTD and Schema
XML DTD and SchemaXML DTD and Schema
XML DTD and Schema
 
Dtd
DtdDtd
Dtd
 
2 dtd - validating xml documents
2   dtd - validating xml documents2   dtd - validating xml documents
2 dtd - validating xml documents
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
Dtd
DtdDtd
Dtd
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml dtd
Xml dtdXml dtd
Xml dtd
 
4 xml namespaces and xml schema
4   xml namespaces and xml schema4   xml namespaces and xml schema
4 xml namespaces and xml schema
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
XML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITIONXML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITION
 
Document type definition
Document type definitionDocument type definition
Document type definition
 

Similar to It8074 soa-unit i (20)

it8074-soa-uniti-.pdf
it8074-soa-uniti-.pdfit8074-soa-uniti-.pdf
it8074-soa-uniti-.pdf
 
2-DTD.ppt
2-DTD.ppt2-DTD.ppt
2-DTD.ppt
 
Xml2
Xml2Xml2
Xml2
 
Xml part2
Xml part2Xml part2
Xml part2
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
 
Dtd
DtdDtd
Dtd
 
Xml 20111006 hurd
Xml 20111006 hurdXml 20111006 hurd
Xml 20111006 hurd
 
Web Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdfWeb Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdf
 
Test for an issue
Test for an issueTest for an issue
Test for an issue
 
Chen's first test slides
Chen's first test slidesChen's first test slides
Chen's first test slides
 
Chen test paper20abcdeftfdfd
Chen test paper20abcdeftfdfdChen test paper20abcdeftfdfd
Chen test paper20abcdeftfdfd
 
Document Type Definition
Document Type DefinitionDocument Type Definition
Document Type Definition
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
XXE
XXEXXE
XXE
 
Xxe
XxeXxe
Xxe
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Session 2
Session 2Session 2
Session 2
 
XML for beginners
XML for beginnersXML for beginners
XML for beginners
 
Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
 

More from smitha273566

Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...smitha273566
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheetssmitha273566
 

More from smitha273566 (7)

Web services
Web servicesWeb services
Web services
 
Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...
 
Unit iv xml dom
Unit iv xml domUnit iv xml dom
Unit iv xml dom
 
Html (1)
Html (1)Html (1)
Html (1)
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Soa unit iv
Soa unit ivSoa unit iv
Soa unit iv
 
Unit iii soa
Unit iii soaUnit iii soa
Unit iii soa
 

Recently uploaded

Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 

Recently uploaded (20)

Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 

It8074 soa-unit i

  • 2. IT8074-SOA IT8074 SERVICE ORIENTED ARCHITECTURE Objectives ∙ To learn fundamentals of XML ∙ To provide an overview of Service Oriented Architecture and Web services and their importance ∙ To learn web services standards and technologies ∙ To learn service oriented analysis and design for developing SOA based applications
  • 3. COURSE OUTCOMES •Understand XML technologies •Understand service orientation, benefits of SOA •Understand web services and WS standards •Use web services extensions to develop solutions •Understand and apply service modeling, service oriented analysis and design for application development
  • 4. UNIT I XML document structure – Well-formed and valid documents – DTD – XML Schema – Parsing XML using DOM, SAX – XPath - XML Transformation and XSL – Xquery
  • 5. 1.0 XML document Structure • XML documents form a tree structure that starts at "the root" and branches to "the leaves".
  • 6. XML Tree Structure • XML documents are formed as element trees. • An XML tree starts at a root element and branches from the root to child elements. • All elements can have sub elements (child elements): • <root> <child> <subchild>.....</subchild> </child> </root> • The terms parent, child, and sibling are used to describe the relationships between elements. • Parent have children. Children have parents. Siblings are children on the same level (brothers and sisters). • All elements can have text content (Harry Potter) and attributes (category="cooking").
  • 7. SYNTAX • XML uses a much self-describing syntax. • A prolog defines the XML version and the character encoding: • <?xml version="1.0" encoding="UTF-8"?> • The next line is the root element of the document: • <bookstore> • The next line starts a <book> element: • <book category="cooking"> • The <book> elements have 4 child elements: <title>,< author>, <year>, <price>. • <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> • The next line ends the book element: • </book> • </bookstore>
  • 8. 2.0 DTD(Document Type Definition) A DTD defines the structure and the legal elements and attributes of an XML document. XML document with an internal DTD • <?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note>
  • 9. DTD • The DTD above is interpreted like this: • !DOCTYPE note defines that the root element of this document is note • !ELEMENT note defines that the note element must contain four elements: "to,from,heading,body" • !ELEMENT to defines the to element to be of type "#PCDATA" • !ELEMENT from defines the from element to be of type "#PCDATA" • !ELEMENT heading defines the heading element to be of type "#PCDATA" • !ELEMENT body defines the body element to be of type "#PCDATA"
  • 10. External DTD An External DTD Declaration • If the DTD is declared in an external file, the <!DOCTYPE> definition must contain a reference to the DTD file: • XML document with a reference to an external DTD <?xml version="1.0"?> <!DOCTYPE note SYSTEM "note.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 11. External DTD note.dtd <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
  • 12. DTD - XML Building Blocks The Building Blocks of XML Documents Seen from a DTD point of view, all XML documents are made up by the following building blocks: • Elements • Attributes • Entities • PCDATA • CDATA
  • 13. DTD-XML BUILDING BLOCKS ELEMENTS <body>some text</body> ATTRIBUTES <img src="computer.gif" /> ENTITY Entity References Character &lt; < &gt; > &amp; & &quot; " &apos; '
  • 14. DTD-XML BUILDING BLOCKS PCDATA • PCDATA means parsed character data. • Think of character data as the text found between the start tag and the end tag of an XML element. • PCDATA is text that WILL be parsed by a parser. The text will be examined by the parser for entities and markup. • Tags inside the text will be treated as markup and entities will be expanded. • However, parsed character data should not contain any &, <, or > characters; these need to be represented by the &amp; &lt; and &gt; entities, respectively. CDATA • CDATA means character data. • CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded.
  • 15. DTD - Elements Declaring Elements • In a DTD, XML elements are declared with the following syntax: • <!ELEMENT element-name category> or <!ELEMENT element-name (element-content)> Empty Elements • Empty elements are declared with the category keyword EMPTY: <!ELEMENT element-name EMPTY> Example: <!ELEMENT br EMPTY> XML example: <br />
  • 16. DTD - Elements Elements with Parsed Character Data • Elements with only parsed character data are declared with #PCDATA inside parentheses: • <!ELEMENT element-name (#PCDATA)> Example: <!ELEMENT from (#PCDATA)> Elements with any Contents • Elements declared with the category keyword ANY, can contain any combination of parsable data: • <!ELEMENT element-name ANY> Example: <!ELEMENT note ANY>
  • 17. DTD ELEMENTS-? sign Declaring zero or one occurrences of the same element example: The ? sign in the example above declares that the child element message can occur zero or one times inside the "note” element <!ELEMENT element name(child name?)> Example <!ELEMENT note(message?)>
  • 18. DTD Elements Elements with Children (sequences) • Elements with one or more children are declared with the name of the children elements inside parentheses: • <!ELEMENT element-name (child1)> or <!ELEMENT element-name (child1,child2,...)> Example: <!ELEMENT note (to,from,heading,body)> • When children are declared in a sequence separated by commas, the children must appear in the same sequence in the document
  • 19. DTD Elements Declaring Minimum One Occurrence of an Element • <!ELEMENT element-name (child-name+)> Example: <!ELEMENT note (message+)> • The + sign in the example above declares that the child element "message" must occur one or more times inside the "note" element. Declaring Zero or More Occurrences of an Element • <!ELEMENT element-name (child-name*)> Example: <!ELEMENT note (message*)> • The * sign in the example above declares that the child element "message" can occur zero or more times inside the "note" element.
  • 20. DTD Elements Declaring either/or Content • <!ELEMENT note (to,from,header,(message|body))> • The example above declares that the "note" element must contain a "to" element, a "from" element, a "header" element, and either a "message" or a "body" element. Declaring Mixed Content • <!ELEMENT note (#PCDATA|to|from|header|message)*> • The example above declares that the "note" element can contain zero or more occurrences of parsed character data, "to", "from", "header", or "message" elements.
  • 21. DTD - Attributes Declaring Attributes • An attribute declaration has the following syntax: • <!ATTLIST element-name attribute-name attribute- type attribute-value> DTD example: <!ATTLIST payment type CDATA "check"> XML example: <payment type="check" />
  • 22. DTD Attributes The attribute-type can be one of the following: Type Description CDATA The value is character data (en1|en2|..) The value must be one from an enumerated list ID The value is a unique id IDREF The value is the id of another element IDREFS The value is a list of other ids NMTOKEN The value is a valid XML name NMTOKENS The value is a list of valid XML names ENTITY The value is an entity ENTITIES The value is a list of entities NOTATION The value is a name of a notation
  • 23. DTD Attributes The attribute-value can be one of the following: Value Explanation value The default value of the attribute #REQUIRED The attribute is required #IMPLIED The attribute is optional #FIXED value The attribute value is fixed
  • 24. DTD Attributes A Default Attribute Value • DTD: <!ELEMENT square EMPTY> <!ATTLIST square width CDATA "0"> Valid XML: <square width="100" /> • In the example above, the "square" element is defined to be an empty element with a "width" attribute of type CDATA. If no width is specified, it has a default value of 0.
  • 25. DTD Attributes #REQUIRED Syntax <!ATTLIST element-name attribute-name attribute-type #REQUIRED> Example DTD: <!ATTLIST person number CDATA #REQUIRED> Valid XML: <person number="5677" /> Invalid XML: <person /> • Use the #REQUIRED keyword if you don't have an option for a default value, but still want to force the attribute to be present.
  • 26. DTD Attributes #IMPLIED Syntax <!ATTLIST element-name attribute-name attribute-type #IMPLIED> Example DTD: <!ATTLIST contact fax CDATA #IMPLIED> Valid XML: <contact fax="555-667788" /> Valid XML: <contact /> Use the #IMPLIED keyword if you don't want to force the author to include an attribute, and you don't have an option for a default value.
  • 27. DTD Attributes #FIXED Syntax • <!ATTLIST element-name attribute-name attribute-type #FIXED "value"> • Example • DTD: <!ATTLIST sender company CDATA #FIXED "Microsoft"> Valid XML: <sender company="Microsoft" /> Invalid XML: <sender company="W3Schools" /> • Use the #FIXED keyword when you want an attribute to have a fixed value without allowing the author to change it. If an author includes another value, the XML parser will return an error. Enumerated Attribute Values Syntax • <!ATTLIST element-name attribute-name (en1|en2|..) default-value> • Example • DTD: <!ATTLIST payment type (check|cash) "cash"> XML example: <payment type="check" /> or <payment type="cash" /> • Use enumerated attribute values when you want the attribute value to be one of a fixed set of legal values.
  • 28. DTD - Entities • Entities are used to define shortcuts to special characters. • Entities can be declared internal or external. An Internal Entity Declaration Syntax <!ENTITY entity-name "entity-value"> Example DTD Example: <!ENTITY writer "Donald Duck."> <!ENTITY copyright "Copyright W3Schools."> XML example: <author>&writer;&copyright;</author> • Note: An entity has three parts: an ampersand (&), an entity name, and a semicolon (;).
  • 29. DTD - Entities An External Entity Declaration Syntax <!ENTITY entity-name SYSTEM "URI/URL"> Example DTD Example: <!ENTITY writer SYSTEM "https://www.w3schools.com/entities.dtd"> <!ENTITY copyright SYSTEM "https://www.w3schools.com/entities.dtd"> XML example: <author>&writer;&copyright;</author>
  • 30. DTD-Examples Newspaper Article DTD <!DOCTYPE NEWSPAPER [ <!ELEMENT NEWSPAPER (ARTICLE+)> <!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)> <!ELEMENT HEADLINE (#PCDATA)> <!ELEMENT BYLINE (#PCDATA)> <!ELEMENT LEAD (#PCDATA)> <!ELEMENT BODY (#PCDATA)> <!ELEMENT NOTES (#PCDATA)> <!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED> <!ATTLIST ARTICLE EDITOR CDATA #IMPLIED> <!ATTLIST ARTICLE DATE CDATA #IMPLIED> <!ATTLIST ARTICLE EDITION CDATA #IMPLIED> <!ENTITY NEWSPAPER "Vervet Logic Times"> <!ENTITY PUBLISHER "Vervet Logic Press"> <!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press"> ]>
  • 31. DTD Examples TV Schedule DTD <!DOCTYPE TVSCHEDULE [ <!ELEMENT TVSCHEDULE (CHANNEL+)> <!ELEMENT CHANNEL (BANNER,DAY+)> <!ELEMENT BANNER (#PCDATA)> <!ELEMENT DAY (DATE,(HOLIDAY|PROGRAMSLOT+)+)> <!ELEMENT HOLIDAY (#PCDATA)> <!ELEMENT DATE (#PCDATA)> <!ELEMENT PROGRAMSLOT (TIME,TITLE,DESCRIPTION?)> <!ELEMENT TIME (#PCDATA)> <!ELEMENT TITLE (#PCDATA)> <!ELEMENT DESCRIPTION (#PCDATA)> <!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED> <!ATTLIST CHANNEL CHAN CDATA #REQUIRED> <!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED> <!ATTLIST TITLE RATING CDATA #IMPLIED> <!ATTLIST TITLE LANGUAGE CDATA #IMPLIED> ]>
  • 32. 3.0 Well formed and Valid XML Documents Well formed XML Document • The XML specification defines a set of rules that XML documents must follow in order to be well-formed. • If an XML document is not well-formed according to the XML specification, browsers, for example, should not make any attempt at correcting the errors as they did for HTML documents. • The following text demonstrates a complete, well-formed XML document: <greeting> Hello, World! </greeting> II. Valid xml document If an XML document is well-formed and has an associated Document Type Declaration (DTD), then it is said to be a valid XML document.
  • 33. Valid and well-formed XML document with DTD Let's take an example of well-formed and valid XML document. It follows all the rules of DTD. employee.xml <?xml version="1.0"?> <!DOCTYPE employee SYSTEM "employee.dtd"> <employee> <firstname>vimal</firstname> <lastname>jaiswal</lastname> <email>vimal@javatpoint.com</email> </employee> • In the above example, the DOCTYPE declaration refers to an external DTD file. The content of the file is shown in below paragraph. employee.dtd <!ELEMENT employee (firstname,lastname,email)> <!ELEMENT firstname (#PCDATA)> <!ELEMENT lastname (#PCDATA)> <!ELEMENT email (#PCDATA)> •
  • 34. WELL FORMED XML Document Well-formed XML Document • An XML document is said to be well-formed if it adheres to the following rules − • Non DTD XML files must use the predefined character entities for amp(&), apos(single quote), gt(>), lt(<), quot(double quote). • It must follow the ordering of the tag. i.e., the inner tag must be closed before closing the outer tag. • Each of its opening tags must have a closing tag or it must be a self ending tag.(<title>....</title> or <title/>). • It must have only one attribute in a start tag, which needs to be quoted. • amp(&), apos(single quote), gt(>), lt(<), quot(double quote) entities other than these must be declared. Example Following is an example of a well-formed XML document − <?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?> <!DOCTYPE address [ <!ELEMENT address (name,company,phone)> <!ELEMENT name (#PCDATA)> <!ELEMENT company (#PCDATA)> <!ELEMENT phone (#PCDATA)> ]> XML File <address> <name>Tanmay Patil</name> <company>TutorialsPoint</company> <phone>(011) 123-4567</phone> </address>
  • 35. 4.0 XML SCHEMA • An XML Schema describes the structure of an XML document. • The XML Schema language is also referred to as XML Schema Definition (XSD). <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> The note element is a complex type because it contains other elements. The other elements (to, from, heading, body) are simple types because they do not contain other elements.
  • 36. XML NAMESPACE Solving the Name Conflict Using a Prefix • Name conflicts in XML can easily be avoided using a name prefix. • This XML carries information about an HTML table, and a piece of furniture: <h:table> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> • In the example above, there will be no conflict because the two <table> elements have different name
  • 37. XML NAMESPACE XML Namespaces provide a method to avoid element name conflicts. Name Conflicts • In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications. • This XML carries HTML table information: <table> <tr> <td>Apples</td> <td>Bananas</td> </tr> </table> This XML carries information about a table (a piece of furniture): <table> <name>African Coffee Table</name> <width>80</width> <length>120</length> </table> • If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning. • A user or an XML application will not know how to handle these differences.
  • 38. XML NAMESPACE • XML Namespaces - The xmlns Attribute • When using prefixes in XML, a namespace for the prefix must be defined. • The namespace can be defined by an xmlns attribute in the start tag of an element. • The namespace declaration has the following syntax. xmlns:prefix="URI".
  • 39. XML NAMESPACE <root xmlns:h="http://www.w3.org/TR/html4/" xmlns:f="http://www.w3schools.com/furniture"> <h:table> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> • Note: The namespace URI is not used by the parser to look up information. • The purpose of using an URI is to give the namespace a unique name. • However, companies often use the namespace as a pointer to a web page containing namespace information.
  • 40. XSD - The <schema> Element The <schema> Element • The <schema> element is the root element of every XML Schema: • <?xml version="1.0"?> <xs:schema> ... ... </xs:schema>
  • 41. XSD - The <schema> Declaration Element • The <schema> element may contain some attributes. A schema declaration often looks something like this: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/ XMLSchema" targetNamespace="https://www.xxx.com" xmlns="https://xxx.com" elementFormDefault="qualified"> ... ... </xs:schema>
  • 42. XSD - The <schema> Element xmlns:xs="http://www.w3.org/2001/XMLSchem a" • indicates that the elements and data types used in the schema come from the "http://www.w3.org/2001/XMLSchema" namespace. It also specifies that the elements and data types that come from the "http://www.w3.org/2001/XMLSchema" namespace should be prefixed with xs:
  • 43. XSD - The <schema> Element This fragment: targetNamespace="https://www.xxx.com" • indicates that the elements defined by this schema (note, to, from, heading, body.) come from the "https://www.xxx.com" namespace.
  • 44. XSD - The <schema> Element This fragment: xmlns="https://www.xxx.com" • indicates that the default namespace is "https://www.xxx.com". This fragment: elementFormDefault="qualified" • indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.
  • 45. XSD Simple Elements A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes. Defining a Simple Element The syntax for defining a simple element is: <xs:element name="xxx" type="yyy"/> • where xxx is the name of the element and yyy is the data type of the element. • XML Schema has a lot of built-in data types. The most common types are: • xs:string • xs:decimal • xs:integer • xs:boolean • xs:date • xs:time
  • 46. XSD Simple Elements Example Here are some XML elements: <lastname>Refsnes</lastname> <age>36</age> <dateborn>1970-03-27</dateborn> And here are the corresponding simple element definitions: <xs:element name="lastname" type="xs:string"/> <xs:element name="age" type="xs:integer"/> <xs:element name="dateborn" type="xs:date"/>
  • 47. Default and Fixed Values for Simple Elements • A default value is automatically assigned to the element when no other value is specified. • In the following example the default value is "red": <xs:element name="color" type="xs:string" default= "red"/> • A fixed value is also automatically assigned to the element, and you cannot specify another value. • In the following example the fixed value is "red": <xs:element name="color" type="xs:string" fixed= "red"/>
  • 48. XSD Attributes What is an Attribute? Simple elements cannot have attributes. If an element has attributes, it is considered to be of a complex type. But the attribute itself is always declared as a simple type. How to Define an Attribute? The syntax for defining an attribute is: <xs:attribute name="xxx" type="yyy"/> • where xxx is the name of the attribute and yyy specifies the data type of the attribute. • XML Schema has a lot of built-in data types. The most common types are: • xs:string • xs:decimal • xs:integer • xs:boolean • xs:date • xs:time
  • 49. XSD Attributes Example • Here is an XML element with an attribute: <lastname lang="EN">Smith</lastname> • And here is the corresponding attribute definition: <xs:attribute name="lang" type="xs:string"/>
  • 50. Default and Fixed Values for Attributes • Attributes may have a default value or a fixed value specified. • A default value is automatically assigned to the attribute when no other value is specified. • In the following example the default value is "EN": • <xs:attribute name="lang" type="xs:string" default="EN"/> • A fixed value is also automatically assigned to the attribute, and you cannot specify another value. • In the following example the fixed value is "EN": • <xs:attribute name="lang" type="xs:string" fixed="EN"/> Optional and Required Attributes • Attributes are optional by default. To specify that the attribute is required, use the "use" attribute: • <xs:attribute name="lang" type="xs:string" use="required"/>
  • 51. XSD Restrictions/Facets Restrictions are used to define acceptable values for XML elements or attributes. Restrictions on XML elements are called facets. Restrictions on Values • The following example defines an element called "age" with a restriction. The value of age cannot be lower than 0 or greater than 120: <xs:element name="age"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> <xs:maxInclusive value="120"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 52. XSD Restrictions/Facets Restrictions on a Set of Values • To limit the content of an XML element to a set of acceptable values, we would use the enumeration constraint. • The example below defines an element called "car" with a restriction. The only acceptable values are: Audi, Golf, BMW: <xs:element name="car"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Audi"/> <xs:enumeration value="Golf"/> <xs:enumeration value="BMW"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 53. XSD Restrictions/Facets Restrictions on a Series of Values • To limit the content of an XML element to define a series of numbers or letters that can be used, we would use the pattern constraint. • The example below defines an element called "letter" with a restriction. The only acceptable value is ONE of the LOWERCASE letters from a to z: • <xs:element name="letter"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[a-z]"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 54. XSD Restrictions/Facets Other Restrictions on a Series of Values • The example below defines an element called "letter" with a restriction. The acceptable value is zero or more occurrences of lowercase letters from a to z: • <xs:element name="letter"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="([a-z])*"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 55. XSD Restrictions/Facets The next example defines an element called "initials" with a restriction. The only acceptable value is THREE of the UPPERCASE letters from a to z: <xs:element name="initials"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[A-Z][A-Z][A-Z]"/> </xs:restriction> </xs:simpleType> </xs:element> The next example also defines an element called "initials" with a restriction. The only acceptable value is THREE of the LOWERCASE OR UPPERCASE letters from a to z: <xs:element name="initials"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 56. XSD Restrictions/Facets The next example defines an element called "gender" with a restriction. The only acceptable value is male OR female: <xs:element name="gender"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="male|female"/> </xs:restriction> </xs:simpleType> </xs:element> The next example defines an element called "password" with a restriction. There must be exactly eight characters in a row and those characters must be lowercase or uppercase letters from a to z, or a number from 0 to 9: <xs:element name="password"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[a-zA-Z0-9]{8}"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 57. XSD Restrictions/Facets Restrictions on Whitespace Characters • To specify how whitespace characters should be handled, we would use the whiteSpace constraint. • This example defines an element called "address" with a restriction. The whiteSpace constraint is set to "preserve", which means that the XML processor WILL NOT remove any white space characters: • <xs:element name="address"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:whiteSpace value="preserve"/> </xs:restriction> </xs:simpleType> </xs:element> • This example also defines an element called "address" with a restriction. The whiteSpace constraint is set to "replace", which means that the XML processor WILL REPLACE all white space characters (line feeds, tabs, spaces, and carriage returns) with spaces: • <xs:element name="address"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:whiteSpace value="replace"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 58. XSD Restrictions/Facets • This example also defines an element called "address" with a restriction. The whiteSpace constraint is set to "collapse", which means that the XML processor WILL REMOVE all white space characters (line feeds, tabs, spaces, carriage returns are replaced with spaces, leading and trailing spaces are removed, and multiple spaces are reduced to a single space): • <xs:element name="address"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:whiteSpace value="collapse"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 59. XSD Restrictions/Facets Restrictions on Length • To limit the length of a value in an element, we would use the length, maxLength, and minLength constraints. • This example defines an element called "password" with a restriction. The value must be exactly eight characters: <xs:element name="password"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:length value="8"/> </xs:restriction> </xs:simpleType> </xs:element> • This example defines another element called "password" with a restriction. The value must be minimum five characters and maximum eight characters: <xs:element name="password"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="5"/> <xs:maxLength value="8"/> </xs:restriction> </xs:simpleType> </xs:element>
  • 60. Restrictions for Datatypes Constraint Description enumeration Defines a list of acceptable values fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value) maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value) maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value)
  • 61. Restrictions for Datatypes minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value) minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero pattern Defines the exact sequence of characters that are acceptable totalDigits Specifies the exact number of digits allowed. Must be greater than zero whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled
  • 62. XSD Complex Elements A complex element contains other elements and/or attributes. • We can define a complex element in an XML Schema two different ways: 1. The "employee" element can be declared directly by naming the element, like this: <xs:element name="employee"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> If you use the method described above, only the "employee" element can use the specified complex type. Note that the child elements, "firstname" and "lastname", are surrounded by the <sequence> indicator. This means that the child elements must appear in the same order as they are declared.
  • 63. XSD Complex Elements 2. The "employee" element can have a type attribute that refers to the name of the complex type to use: <xs:element name="employee" type="personinfo"/> <xs:complexType name="personinfo"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> If you use the method described above, several elements can refer to the same complex type, like this: <xs:element name="employee" type="personinfo"/> <xs:element name="student" type="personinfo"/> <xs:element name="member" type="personinfo"/> <xs:complexType name="personinfo"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType>
  • 64. XSD Indicators There are seven indicators: Order indicators: • All • Choice • Sequence Occurrence indicators: • maxOccurs • minOccurs Group indicators: • Group name • attributeGroup name
  • 65. Order Indicators Order indicators are used to define the order of the elements. • All Indicator • The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once: <xs:element name="person"> <xs:complexType> <xs:all> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:all> </xs:complexType> </xs:element>
  • 66. Choice Indicator • The <choice> indicator specifies that either one child element or another can occur: • <xs:element name="person"> <xs:complexType> <xs:choice> <xs:element name="employee" type="employee"/> <xs:element name="member" type="member"/> </xs:choice> </xs:complexType> </xs:element>
  • 67. Sequence Indicator • The <sequence> indicator specifies that the child elements must appear in a specific order: <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string "/> </xs:sequence> </xs:complexType> </xs:element>
  • 68. Occurrence Indicators Occurrence indicators are used to define how often an element can occur. maxOccurs Indicator The <maxOccurs> indicator specifies the maximum number of times an element can occur minOccurs Indicator The <minOccurs> indicator specifies the minimum number of times an element can occur:
  • 69. Occurrence Indicators <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="full_name" type="xs:string"/> <xs:element name="child_name" type="xs:string" maxOccurs="10" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> • The example above indicates that the "child_name" element can occur a minimum of zero times and a maximum of ten times in the "person" element. • Tip: To allow an element to appear an unlimited number of times, use the maxOccurs="unbounded" statement:
  • 70. Group Indicators Group indicators are used to define related sets of elements. <xs:group name="persongroup"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:element name="birthday" type="xs:date"/> </xs:sequence> </xs:group> <xs:element name="person" type="personinfo"/> <xs:complexType name="personinfo"> <xs:sequence> <xs:group ref="persongroup"/> <xs:element name="country" type="xs:string"/> </xs:sequence> </xs:complexType>
  • 71. Attribute Groups • Attribute groups are defined with the attributeGroup declaration, like this: • <xs:attributeGroup name="groupname"> ... </xs:attributeGroup> Example <xs:attributeGroup name="personattrgroup"> <xs:attribute name="firstname" type="xs:string"/> <xs:attribute name="lastname" type="xs:string"/> <xs:attribute name="birthday" type="xs:date"/> </xs:attributeGroup> <xs:element name="person"> <xs:complexType> <xs:attributeGroup ref="personattrgroup"/> </xs:complexType> </xs:element>
  • 72. XML SCHEMA EXAMPLE An XML Document Let's have a look at this XML document called "shiporder.xml": <?xml version="1.0" encoding="UTF-8"?> <shiporder orderid="889923" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="shiporder.xsd"> <orderperson>John Smith</orderperson> <shipto> <name>Ola Nordmann</name> <address>Langgt 23</address> <city>4000 Stavanger</city> <country>Norway</country> </shipto> <item> <title>Empire Burlesque</title> <note>Special Edition</note> <quantity>1</quantity> <price>10.90</price> </item> <item> <title>Hide your heart</title> <quantity>1</quantity> <price>9.90</price> </item> </shiporder> • The XML document above consists of a root element, "shiporder", that contains a required attribute called "orderid". The "shiporder" element contains three different child elements: "orderperson", "shipto" and "item". The "item" element appears twice, and it contains a "title", an optional "note" element, a "quantity", and a "price" element. • The line above: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tells the XML parser that this document should be validated against a schema. The line: xsi:noNamespaceSchemaLocation="shiporder.xsd" specifies WHERE the schema resides (here it is in the same folder as "shiporder.xml").
  • 73. XML SCHEMA <?xml version="1.0" encoding="UTF-8" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="shiporder"> <xs:complexType> <xs:sequence> <xs:element name="orderperson" type="xs:string"/> <xs:element name="shipto"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="address" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="country" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="item" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string"/> <xs:element name="note" type="xs:string" minOccurs="0"/> <xs:element name="quantity" type="xs:positiveInteger"/> <xs:element name="price" type="xs:decimal"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="orderid" type="xs:string" use="required"/> </xs:complexType> </xs:element>
  • 74. 5.0 TRANSFORMATIONS AND XSL XSL TECHNOLOGIES • XSL(XML style sheet language) has two independent languages: – The XSL Transformation Language(XSLT) – The XSL Formatting object language(XSL-FO) • XSLT is used to convert an XML document to another format. XSL-FO provides a way of describing the presentation of an XML document. • Correct Style Sheet Declaration • The root element that declares the document to be an XSL style sheet is <xsl:stylesheet> or <xsl:transform>.
  • 75. XSLT The <xsl:template> Element • The <xsl:template> element is used to build templates. • The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document). XSLT <xsl:value-of> Element • The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation.
  • 76. XSLT The <xsl:for-each> Element • The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set: • Filtering the Output • We can also filter the output from the XML file by adding a criterion to the select attribute in the <xsl:for-each> element. <xsl:for-each select="catalog/cd[artist='Bob Dylan']"> • Legal filter operators are: • = (equal) • != (not equal) • &lt; less than • &gt; greater than XSLT <xsl:sort> Element • The <xsl:sort> element is used to sort the output.
  • 77. XSLT XSLT <xsl:if> Element • The <xsl:if> element is used to put a conditional test against the content of the XML file. The <xsl:if> Element • To put a conditional if test against the content of the XML file, add an <xsl:if> element to the XSL document. • Syntax • <xsl:if test="expression"> ...some output if the expression is true... </xsl:if> XSLT <xsl:choose> Element • The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express multiple conditional tests.
  • 78. XSL Examples cdcatalog.xml <catalog> <cd><title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year></cd> <cd> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <country>UK</country> <company>CBS Records</company> <price>9.90</price> <year>1988</year> </cd> <cd> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <country>USA</country> <company>RCA</company> <price>9.90</price> <year>1982</year> </cd> </catalog>
  • 79. Create an XSL Style Sheet Then you create an XSL Style Sheet ("cdcatalog.xsl") with a transformation template: <?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>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Link the XSL Style Sheet to the XML Document • Add the XSL style sheet reference to your XML document ("cdcatalog.xml"): <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd>
  • 80. Output My CD Collection Title Artist Empire Burlesque Bob Dylan Hide your heart Bonnie Tyler Greatest Hits Dolly Parton
  • 81. Create an XSL Style Sheet Example for XSLT <xsl:sort> Element <?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>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
  • 82. Output My CD Collection Title Artist Empire Burlesque Bob Dylan Hide your heart Bonnie Tyler Greatest Hits Dolly Parton
  • 83. XSLT <xsl:if> Element <?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>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> <th>Price</th> </tr> <xsl:for-each select="catalog/cd"> <xsl:if test="price &gt; 10"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> <td><xsl:value-of select="price"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
  • 84. Output My CD Collection Title Artist Price Empire Burlesque Bob Dylan 10.90
  • 85. XSLT <xsl:choose> Element <?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>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <xsl:choose> <xsl:when test="price &gt; 10"> <td bgcolor="#ff00ff"> <xsl:value-of select="artist"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="artist"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
  • 86. Output My CD Collection Title Artist Empire Burlesque Bob Dylan Hide your heart Bonnie Tyler Greatest Hits Dolly Parton
  • 87. XSL FORMATTING • The World Wide Web Consortium's specification for Extensible Stylesheet Language (XSL) comes in two parts: • XSLT, a language for transforming XML documents, and • XSL Formatting Objects (XSL FO), an XML vocabulary for specifying formatting semantics. • XSL Formatting Objects is itself an XML-based markup language that lets you specify in great detail the pagination, layout, and styling information that will be applied to your content. • The XSL FO markup is quite complex. It is also verbose; virtually the only practical way to produce an XSL FO file is to use XSLT to produce a source document. • Finally, once you have this XSL FO file, you need some way to render it to an output medium. There are few tools available to do this final step. For these reasons, XML FO has not caught on as quickly as XSLT.
  • 88. Initialization • Since the XSL FO file will be an XML document, it must begin with the standard XML processing instruction and the FO root element. • <?xml version="1.0" encoding="utf-8"?> • <fo:root> • The structure of the remainder of the document is: • The layout master set, which consists of – Descriptions of the kinds of pages that can occur in the document. – Sequences in which those page formats can occur. • The pages and their content.
  • 89. Page Layouts Document will have three kinds of pages shown in the diagram below. To accommodate the stapling area, the cover page and right-hand pages will have more margin space at the left. The content pages will also have a region for a header and footer.
  • 90. Page Layout The units below are all in centimeters, but you may use any of the CSS units, such as px (pixel), pt (point), em, in, mm, etc. Each of these specifications is called a simple-page- master and must be given a master-name so you can refer to it later.
  • 94. The content area This is the page content area (officially called the page-reference-area), which can be divided into five regions as shown below.
  • 95. Content Area-Cover Page • The cover page doesn't need a header or footer, so we need only specify information for the region-body by adding the information shown in bold below. <fo:simple-page-master master-name="cover" page-height="12cm" page-width="12cm" margin-top="0.5cm" margin-bottom="0.5cm" margin-left="1cm" margin-right="0.5cm"> <fo:region-body margin-top="3cm" /> </fo:simple-page-master>
  • 96. Content Area-Left Page The left and right pages will have a header and footer, so we must specify the extent of the region-before and region- after. <fo:simple-page-master master-name="leftPage" page-height="12cm" page-width="12cm" margin-left="0.5cm" margin-right="1cm" margin-top="0.5cm" margin-bottom="0.5cm"> <fo:region-before extent="1cm"/> <fo:region-after extent="1cm"/> <fo:region-body margin-top="1.1cm" margin-bottom="1.1cm" /> </fo:simple-page-master>
  • 97. Content Area-Right Page <fo:simple-page-master master-name="rightPage" page-height="12cm" page-width="12cm" margin-left="1cm" margin-right="0.5cm" margin-top="0.5cm" margin-bottom="0.5cm"> <fo:region-before extent="1cm"/> <fo:region-after extent="1cm"/> <fo:region-body margin-top="1.1cm" margin-bottom="1.1cm" /> </fo:simple-page-master>
  • 98. 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> and <fo:flow> elements • The <fo:static-content> element is used for page headers and footers.For example we can define a header for the company name and page number and this information will appear on every page. • 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> elements. 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.
  • 99. Example Ez book online Welcome to Ez books online in the worlds smallest online book store
  • 100. Code fragment <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” 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=”24pt” Text-align=”justify”> Welcome to Ez books online in the worlds smallest online book store </fo:block> </fo:flow> </fo:page sequence>
  • 101. 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> 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. The <fo:block> element uses the text-align attribute to place the text at the end of the region. The above example uses the English language, so the text is right justified. The current page number is determined using the <fo:page-number> element.
  • 102. Page headers and footers 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.
  • 103. 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. • The following code fragment inserts the image smiley.jpg • <fo:block text-align=”center”> • <fo:external-graphic src=”smiley.jpg”width=”200px” height=”200px”/> • </fo:block>
  • 104. XSL-FO Tables • The XSL-FO table model is not very different from the HTML table model. • There are nine XSL-FO objects used to create tables: • fo:table-and-caption • fo:table • fo:table-caption • fo:table-column • fo:table-header • fo:table-footer • fo:table-body • fo:table-row • fo:table-cell • XSL-FO uses the <fo:table-and-caption> element to define a table. It contains a <fo:table> and an optional <fo:caption> element. • The <fo:table> element contains optional <fo:table-column> elements, an optional <fo:table-header> element, a <fo:table-body> element, and an optional <fo:table-footer> element. Each of these elements has one or more <fo:table-row> elements, with one or more <fo:table-cell> elements:
  • 105. XSL FO TABLES <fo:table-and-caption> <fo:table> <fo:table-column column-width="25mm"/> <fo:table-column column-width="25mm"/> <fo:table-header> <fo:table-row> <fo:table-cell> <fo:block font-weight="bold">Car</fo:block> </fo:table-cell> <fo:table-cell> <fo:block font-weight="bold">Price</fo:block> </fo:table-cell> </fo:table-row> </fo:table-header> <fo:table-body> <fo:table-row> <fo:table-cell> <fo:block>Volvo</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>$50000</fo:block> </fo:table-cell>