Professional Documents
Culture Documents
1
XSLT (XML Stylesheet Language Transformation)
This module will discuss another XML-related technology; XSLT. Just like
XPath, it can also extend the function of XML. XSLT is mainly used for
transforming XML documents. This module covers the basics of XSLT and
how it transforms an XML document.
Upon completion of this module, the students should be able to:
1. Define what is XSLT
2. Discuss the purpose of XSLT
3. Identify the syntax of XSLT
What is XSLT?
XSLT Defined
XSLT stands for eXtended Stylesheet Transformation. XSLT is a language
used to transform XML documents into other XML documents, XHTML file, or
any other XML document formats.
Below is an Example of an XML Document
<tr bgcolor="cyan">
<th style="text-align:left">Movie Title</th>
<th style="text-align:left">Director</th>
</tr>
<xsl:for-each select="cinema/movie">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="director"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Course Module
Purpose of XSLT
XSLT uses XPath to navigate through XML documents and to define parts of
the source document that should match one or more predefined templates.
XSLT will transform the matching part of the source document into the result
document when a match is found.
XSLT has its own processor. An XSLT stylesheet is applied on XML documents
to produce a new format.
XSLT Syntax
Declaration
In declaring XSLT documents, we can use the
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Or
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Glossary
XSLT: This stands for eXtended Stylesheet Transformation. XSLT is a
language used to transform XML documents into other XML documents
Course Module
[
declaration
]>
<!DOCTYPE letter [
]>
This means that the root tag of our XML document should be the element/tag
<letter>.
The next line:
means that inside the tag/element <letter> the XML document is required
to have the elements/tag <from>, <to>, and, <message>. If one of these
elements is missing, then your XML will produce an error. You can also notice
the + next to the to element/tag. This means that there could be one or
more <to> element inside <letter>.
The lines:
Refer to the body of the DTD. In these lines, the elements/tags <from>, <to>,
and, <message> have the type #PCDATA. #PCDATA means parse-able text
data.
Course Module
In order to be considered a valid XML document, the XML file should abide by
the rules set by the DTD. You can check if it is a valid XML document by using
an XML Validator.
Glossary
XML DTD: is a set of rules used to describe XML language accurately.
Course Module
WebApp: XML-based Web Application
1
XML Schema
XML Schema
In the previous lesson, we discussed all about a type of Document Definition
called XML DTD. There is a more powerful alternative to this; XML Schema.
Just like XML DTD, it can be used to create valid XML documents. This lesson
focuses on XML Schema; its elements, purpose, and applications.
XML Schema
XML Schema Defined
XML Schema defines and validates the structure of an XML document. It is an
alternative to DTD. XML Schema uses XML to define its rules. By using XML
Schema, we can create valid XML documents. XML Schema is also known as
XML Schema Definition (XSD).
XML Schema element uses Namespaces. It is similar to a database schema
that describes the data in a database.
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="note">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="to" type="xs:string"/>
<xsd:element name="from" type="xs:string"/>
<xsd:element name="heading" type="xs:string"/>
<xsd:element name="body" type="xs:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Figure 1: An XML document with XML Schema 1
Purpose of XML Schema
The purpose of XML Schema is to define the rules an XML document should
follow to be considered a valid XML Document.
Course Module
It is important that we learn XML Schema because of these two reasons:
a. It is more powerful than DTD and uses XML syntax
b. Many of the XML standards today are defined by XML Schemas.
</xsd:schema>
Figure 2: An XML document with XML Schema 2
Below is a detailed explanation of the XML Schema above.
a. XML Schema declaration
An XML Schema declaration uses the namespace
"http://www.w3.org/2001/XMLSchema"
And usually uses the prefix ”xsd”. A complete XML Schema looks like:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Figure 2: XML Schema Declaration
b. XML Schema elements
Elements are the building blocks of XML document. XML Schema elements
can have mixed, empty, or element content. They can have the minimum and
max number of times they can occur.
WebApp: XML-based Web Application
3
XML Schema
<xsd:element name="age">
<xsd:simpleType>
<xsd:restriction base="xs:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Function Description
Course Module
xsd:string Sequence of characters
<xsd:element name="age">
<xsd:simpleType>
<xsd:restriction base="xs:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="100"/>
</xsd:restriction>
WebApp: XML-based Web Application
5
XML Schema
</xsd:simpleType>
</xsd:element>
In the example above, the <xsd:restriction> was used together with the
<xsd:minInclusive> and < xsd:maxInclusive> elements.
<xsd:element name="gender">
<xsd:simpleType>
<xsd:restriction base="xs:string">
<xsd:enumeration value="”Male”"/>
<xsd:enumeration value="Female"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xs:element name="PersonalInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="address" type="xs:string" />
<xs:element name="contactnumber" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="emptyelement">
<xs:complexType>
</xs:complexType>
</xs:element>
<xs:element name="PersonalInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="address" type="xs:string" />
<xs:element name="contactnumber" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
Declaring attributes
Attributes in XML Schema are always Simple Type.
Examples of attribute declaration
a. The example below shows an attribute named attrib and type of
xsd:integer.
<xsd:attribute name="attrib" type=”xsd:integer” />
Glossary
XML Schema Element Complex type: This is a container for other element
definitions
WebApp: XML-based Web Application
7
XML Schema
XML Schema Element Simple type: This is used only in the context of the
text.
XML Schema: This defines and validates the structure of an XML document.
Course Module
WebApp: XML-based Web Application
1
XML Database and XML RSS
XML Database
XML Database Defined
XML Database is software capable of storing large amounts of data and
information in the XML format.
Some examples of XML Database
a. BaseX f. Sedna
b. Berkeley DB g. IBM DB2
XML Edition (pureXML)
c. eXist h. Microsoft SQL
d. MarkLogic Server
Server i. Oracle Database
e. Qizx j. PostgreSQL
The data stored in the database can be queried using XQuery, serialized, and
exported into desired format.
XQuery is a query and functional programming language that queries and
transforms collections of structured and unstructured data, usually in the
form of XML, text and with vendor-specific extensions for other data formats.
Course Module
a. XML- Enabled Database
XML enabled database is the extension provided for the conversion of XML
document. This is relational database, where data are stored in tables
consisting of rows and columns. The tables contain set of records, which in
turn consist of fields.
XML enabled database is best suited where the majority of data are non-XML.
b. Native XML Database
Native XML database is based on the container rather than table format. It
can store large amount of XML document and data. Native XML database is
queried by the XPath-expressions.
Example of XML database
Below is an example of XML database.
<?xml version="1.0"?>
<album>
<song1>
<title>Your Song</title>
<genre>Rock</genre>
<composer>Danny Tan</composer>
</song1>
<song2>
<title>My Heart</title>
<genre>Pop</genre>
<composer>Mel White</composer>
</song2>
</album>
Figure 1: XML Database Example
In figure 1, table album is created that holds the records song1 and song2,
which in turn consists of three entities – title, genre and composer.
XML RSS
XML RSS stands for Really Simple Syndication/Rich Site Summary. It is
possible to distribute up-to-date web content from one web site to thousands
of other web sites around the world.
XML RSS Features
The following are features of RSS XML
• RSS allows you to syndicate your site content
• RSS defines an easy way to share and view headlines and content
• RSS files can be automatically updated
• RSS allows personalized views for different sites
• RSS is written in XML
WebApp: XML-based Web Application
3
XML Database and XML RSS
<channel>
<title>Online Tutorials</title>
<link>https://www.tutorial.com</link>
<description>Online Education</description>
<item>
<title>Java Programming</title>
<link>https://www.tutorials.com/java </link>
<description>Java Programming Tutorial</description>
</item>
<item>
<title>HTML Tutorial</title>
<link>https://www.tutorial.com/html</link>
<description>HTML Tutorial</description>
</item>
</channel>
</rss>
Figure 2: XML RSS Example
Course Module
With RSS you can choose to view the news you want, the news that interest
you and are relevant to your work.
b. Remove unwanted information
With RSS you can separate wanted information from unwanted information
c. Increase your site traffic
With RSS you can create your own news channel, and publish it to the
Internet
Glossary
Native XML database: This is based on the container rather than table
format. It can store large amount of XML document and data. Native XML
database is queried by the XPath-expressions.
XML Enabled database: This is the extension provided for the conversion of
XML document.
Course Module