You are on page 1of 40

Expriment No.

Aim: To Study of all HTML tags.

Problem Statement: WAP to design resume using basic HTML Tags.


WAP to design student information form using HTML form tag.
WAP using frame tag.
Requirement: Notepad, Internet Explorer

Theory:

HTML is an abbreviation of "HyperText Mark-up Language" - which is


already more than you need to know at this stage. However, for the sake of good order,
let us explain in greater detail.

• Hyper is the opposite of linear. In the good old days - when a mouse was
something the cat chased - computer programs ran linearly: when the program had
executed one action it went to the next line and after that, the next line and so on.
But HTML is different - you can go wherever you want and whenever you want.
For example, it is not necessary to visit MSN.com before you visit HTML.net.
• Text is self-explanatory.
• Mark-up is what you do with the text. You are marking up the text the same way
you do in a text editing program with headings, bullets and bold text and so on.
• Language is what HTML is. It uses many English words.

HTML Tags

HTML markup tags are usually called HTML tags

• HTML tags are keywords surrounded by angle brackets like <html>


• HTML tags normally come in pairs like <b> and </b>
• The first tag in a pair is the start tag, the second tag is the end tag
• Start and end tags are also called opening tags and closing tags.

Tag Description
<!--...--> Defines a comment
<!DOCTYPE> Defines the document type
<a> Defines an anchor
<abbr> Defines an abbreviation
<acronym> Defines an acronym
<address> Defines contact information for the author/owner of a document
<applet> Deprecated. Defines an embedded applet
<area /> Defines an area inside an image-map
<b> Defines bold text
<base /> Defines a default address or a default target for all links on a page
<basefont /> Deprecated. Defines a default font, color, or size for the text in a page
<bdo> Defines the text direction
<big> Defines big text
<blockquote> Defines a long quotation
<body> Defines the document's body
<br /> Defines a single line break
<button> Defines a push button
<caption> Defines a table caption
<center> Deprecated. Defines centered text
<cite> Defines a citation
<code> Defines computer code text
<col /> Defines attribute values for one or more columns in a table
<colgroup> Defines a group of columns in a table for formatting
<dd> Defines a description of a term in a definition list
<del> Defines deleted text
<dir> Deprecated. Defines a directory list
<div> Defines a section in a document
<dfn> Defines a definition term
<dl> Defines a definition list
<dt> Defines a term (an item) in a definition list
<em> Defines emphasized text
<fieldset> Defines a border around elements in a form
<font> Deprecated. Defines font, color, and size for text
<form> Defines an HTML form for user input
<frame /> Defines a window (a frame) in a frameset
<frameset> Defines a set of frames
<h1> to <h6> Defines HTML headings
<head> Defines information about the document
<hr /> Defines a horizontal line
<html> Defines an HTML document
<i> Defines italic text
<iframe> Defines an inline frame
<img /> Defines an image
<input /> Defines an input control
<ins> Defines inserted text
<isindex> Deprecated. Defines a searchable index related to a document
<kbd> Defines keyboard text
<label> Defines a label for an input element
<legend> Defines a caption for a fieldset element
<li> Defines a list item
<link /> Defines the relationship between a document and an external resource
<map> Defines an image-map
<menu> Deprecated. Defines a menu list
<meta /> Defines metadata about an HTML document
<noframes> Defines an alternate content for users that do not support frames
<noscript> Defines an alternate content for users that do not support client-side scripts
<object> Defines an embedded object
<ol> Defines an ordered list
<optgroup> Defines a group of related options in a select list
<option> Defines an option in a select list
<p> Defines a paragraph
<param /> Defines a parameter for an object
<pre> Defines preformatted text
<q> Defines a short quotation
<s> Deprecated. Defines strikethrough text
<samp> Defines sample computer code
<script> Defines a client-side script
<select> Defines a select list (drop-down list)
<small> Defines small text
<span> Defines a section in a document
<strike> Deprecated. Defines strikethrough text
<strong> Defines strong text
<style> Defines style information for a document
<sub> Defines subscripted text
<sup> Defines superscripted text
<table> Defines a table
<tbody> Groups the body content in a table
<td> Defines a cell in a table
<textarea> Defines a multi-line text input control
<tfoot> Groups the footer content in a table
<th> Defines a header cell in a table
<thead> Groups the header content in a table
<title> Defines the title of a document
<tr> Defines a row in a table
<tt> Defines teletype text
<u> Deprecated. Defines underlined text
<ul> Defines an unordered list
<var> Defines a variable part of a text
<xmp> Deprecated. Defines preformatted tex

Output:

Conclusion: Thus we studied all basic html tags.


Expriment No.2

Aim: To Study of java scripts.

Problem Statement: WAP to design resume using basic HTML Tags.


WAP to design student information form using HTML form tag.
WAP using frame tag.
Requirement: Notepad, Internet Explorer

Theory:
What is JavaScript?

• JavaScript was designed to add interactivity to HTML pages


• JavaScript is a scripting language
• A scripting language is a lightweight programming language
• JavaScript is usually embedded directly into HTML pages
• JavaScript is an interpreted language (means that scripts execute without
preliminary compilation)
• Everyone can use JavaScript without purchasing a license

JavaScript Statements

A JavaScript statement is a command to a browser. The purpose of the command is to tell


the browser what to do.

This JavaScript statement tells the browser to write "Hello Dolly" to the web page:

document.write("Hello Dolly");

It is normal to add a semicolon at the end of each executable


statement. Most people think this is a good programming practice, and
most often you will see this in JavaScript examples on the web.

JavaScript Variables

As with algebra, JavaScript variables are used to hold values or expressions.

A variable can have a short name, like x, or a more descriptive name, like carname.

Rules for JavaScript variable names:

• Variable names are case sensitive (y and Y are two different variables)
• Variable names must begin with a letter or the underscore character

Operators:
JavaScript Arithmetic Operators

Arithmetic operators are used to perform arithmetic between variables and/or values.

Given that y=5, the table below explains the arithmetic operators:

Operator Description Example Result


+ Addition x=y+2 x=7
- Subtraction x=y-2 x=3
* Multiplication x=y*2 x=10
/ Division x=y/2 x=2.5
% Modulus (division remainder) x=y%2 x=1
++ Increment x=++y x=6
-- Decrement x=--y x=4

JavaScript Assignment Operators

Assignment operators are used to assign values to JavaScript variables.

Given that x=10 and y=5, the table below explains the assignment operators:

Operator Example Same As Result


= x=y x=5
+= x+=y x=x+y x=15
-= x-=y x=x-y x=5
*= x*=y x=x*y x=50
/= x/=y x=x/y x=2
%= x%=y x=x%y x=0
Comparison Operators

Comparison operators are used in logical statements to determine equality or difference


between variables or values.

Given that x=5, the table below explains the comparison operators:

Operator Description Example


== is equal to x==8 is false
=== is exactly equal to (value and type) x===5 is true
x==="5" is false
!= is not equal x!=8 is true
> is greater than x>8 is false
< is less than x<8 is true
>= is greater than or equal to x>=8 is false
<= is less than or equal to x<=8 is true

Logical Operators

Logical operators are used to determine the logic between variables or values.

Given that x=6 and y=3, the table below explains the logical operators:

Operator Description Example


&& and (x < 10 && y > 1) is true
|| or (x==5 || y==5) is false
! not !(x==y) is true

Conditional Operator

JavaScript also contains a conditional operator that assigns a value to a variable based on
some condition.

Syntax
variablename=(condition)?value1:value2
Conditional Statements

Very often when you write code, you want to perform different actions for different
decisions. You can use conditional statements in your code to do this.

In JavaScript we have the following conditional statements:

• if statement - use this statement to execute some code only if a specified


condition is true
• if...else statement - use this statement to execute some code if the condition is
true and another code if the condition is false
• if...else if....else statement - use this statement to select one of many blocks of
code to be executed
• switch statement - use this statement to select one of many blocks of code to be
executed

JavaScript Loops

Often when you write code, you want the same block of code to run over and over again
in a row. Instead of adding several almost equal lines in a script we can use loops to
perform a task like this.

In JavaScript, there are two different kind of loops:

• for - loops through a block of code a specified number of times


• while - loops through a block of code while a specified condition is true

The Array Object

The Array object is used to store multiple values in a single variable.

Syntax for creating an Array object:

var myCars=new Array("Saab","Volvo","BMW")

To access and to set values inside an array, you must use the index numbers as follows:

• myCars[0] is the first element


• myCars[1] is the second element
• myCars[2] is the third element

Array Object Properties

FF: Firefox, IE: Internet Explorer


Property Description FF IE
constructor Returns a reference to the array function that created the object 1 4
index 1 4
input 1 4
length Sets or returns the number of elements in an array 1 4
prototype Allows you to add properties and methods to the object 1 4

Array Object Methods

Method Description FF IE
concat() Joins two or more arrays and returns the result 1 4
join() Puts all the elements of an array into a string. The elements are 1 4
separated by a specified delimiter
pop() Removes and returns the last element of an array 1 5.5
push() Adds one or more elements to the end of an array and returns the 1 5.5
new length
reverse() Reverses the order of the elements in an array 1 4
shift() Removes and returns the first element of an array 1 5.5
slice() Returns selected elements from an existing array 1 4
sort() Sorts the elements of an array 1 4
splice() Removes and adds new elements to an array 1 5.5
toSource() Represents the source code of an object 1 -
toString() Converts an array to a string and returns the result 1 4
unshift() Adds one or more elements to the beginning of an array and 1 6
returns the new length
valueOf() Returns the primitive value of an Array object 1 4

Conclusion: Thus we studied all basic html tags.


Expriment No.3

Aim: To Study of servlet.

Problem Statement: 1.WAP to display “hello, Welcome to servlet” in servlet.


2. WAP to display data of the student from database (mysql) in
servlet.
3. WAP to get the html document in servelet.

Requirement: Notepad, Internet Explorer, Appache server, mysql

Theory:

HTML Forms, Components, and Servlets

This document is to give you a brief overview of HTML forms, components, and
servlets. The big picture is that you create a form on a web page. When a user completes
the form, the data that the user entered is sent to a servlet for processing. A servlet is a
java class (or object) whose doPost or doGet method is invoked (as prescribed by the
form). The servlet reads the submitted data, and outputs text or a new web page as a
result. In this document, I show how servlets can output either pure text or a web page as
a result.

What is a Servlet?

Servlets are modules of Java code that run in a server application (hence the name
"Servlets", similar to "Applets" on the client side) to answer client requests. Servlets are
not tied to a specific client-server protocol but they are most commonly used with HTTP
and the word "Servlet" is often used in the meaning of "HTTP Servlet".

Servlets make use of the Java standard extension classes in the packages javax.servlet
(the basic Servlet framework) and javax.servlet.http (extensions of the Servlet framework
for Servlets that answer HTTP requests). Since Servlets are written in the highly portable
Java language and follow a standard framework, they provide a means to create
sophisticated server extensions in a server and operating system independent way.

Typical uses for HTTP Servlets include:

• Processing and/or storing data submitted by an HTML form.


• Providing dynamic content, e.g. returning the results of a database query to the
client.
• Managing state information on top of the stateless HTTP, e.g. for an online
shopping cart system which manages shopping carts for many concurrent
customers and maps every request to the right customer.

Servlets vs CGI

The traditional way of adding functionality to a Web Server is the Common Gateway
Interface (CGI), a language-independent interface that allows a server to start an external
process which gets information about a request through environment variables, the
command line and its standard input stream and writes response data to its standard
output stream. Each request is answered in a separate process by a separate instance of
the CGI program, or CGI script (as it is often called because CGI programs are usually
written in interpreted languages like Perl).

Servlets have several advantages over CGI:

• A Servlet does not run in a separate process. This removes the overhead of
creating a new process for each request.
• A Servlet stays in memory between requests. A CGI program (and probably also
an extensive runtime system or interpreter) needs to be loaded and started for each
CGI request.
• There is only a single instance which answers all requests concurrently. This
saves memory and allows a Servlet to easily manage persistent data.
• A Servlet can be run by a Servlet Engine in a restrictive Sandbox (just like an
Applet runs in a Web Browser's Sandbox) which allows secure use of untrusted
and potentially harmful Servlets.

1.3 The Basic Servlet Architecture

A Servlet, in its most general form, is an instance of a class which implements the
javax.servlet.Servlet interface. Most Servlets, however, extend one of the standard
implementations of that interface, namely javax.servlet.GenericServlet and
javax.servlet.http.HttpServlet. In this tutorial we'll be discussing only HTTP Servlets
which extend the javax.servlet.http.HttpServlet class.

In order to initialize a Servlet, a server application loads the Servlet class (and probably
other classes which are referenced by the Servlet) and creates an instance by calling the
no-args constructor. Then it calls the Servlet's init(ServletConfig config) method. The
Servlet should performe one-time setup procedures in this method and store the
ServletConfig object so that it can be retrieved later by calling the Servlet's
getServletConfig() method. This is handled by GenericServlet. Servlets which extend
GenericServlet (or its subclass HttpServlet) should call super.init(config) at the beginning
of the init method to make use of this feature. The ServletConfig object contains Servlet
parameters and a reference to the Servlet's ServletContext. The init method is guaranteed
to be called only once during the Servlet's lifecycle. It does not need to be thread-safe
because the service method will not be called until the call to init returns.

When the Servlet is initialized, its service(ServletRequest req, ServletResponse res)


method is called for every request to the Servlet. The method is called concurrently (i.e.
multiple threads may call this method at the same time) so it should be implemented in a
thread-safe manner. Techniques for ensuring that the service method is not called
concurrently, for the cases where this is not possible, are described in section 4.1.

When the Servlet needs to be unloaded (e.g. because a new version should be loaded or
the server is shutting down) the destroy() method is called. There may still be threads that
execute the service method when destroy is called, so destroy has to be thread-safe. All
resources which were allocated in init should be released in destroy. This method is
guaranteed to be called only once during the Servlet's lifecycle.

Servlet Methods:

A Generic servlet contains the following five methods:

init()

public void init(ServletConfig config) throws ServletException


The init() method is called only once by the servlet container throughout the life of a
servlet. By this init() method the servlet get to know that it has been placed into
service.
The servlet cannot be put into the service if

• The init() method does not return within a fix time set by the web server.
• It throws a ServletException

Parameters - The init() method takes a ServletConfig object that contains the
initialization parameters and servlet's configuration and throws a ServletException if
an exception has occurred.

service()

public void service(ServletRequest req, ServletResponse res) throws


ServletException, IOException
Once the servlet starts getting the requests, the service() method is called by the servlet
container to respond. The servlet services the client's request with the help of two
objects. These two objects javax.servlet.ServletRequest and
javax.servlet.ServletResponse are passed by the servlet container.

The status code of the response always should be set for a servlet that throws or sends
an error.

Parameters - The service() method takes the ServletRequest object that contains the
client's request and the object ServletResponse contains the servlet's response. The
service() method throws ServletException and IOExceptions exception.

getServletConfig()

public ServletConfig getServletConfig()


This method contains parameters for initialization and startup of the servlet and returns
a ServletConfig object. This object is then passed to the init method. When this
interface is implemented then it stores the ServletConfig object in order to return it. It
is done by the generic class which implements this inetrface.
Returns - the ServletConfig object
getServletInfo()

public String getServletInfo()


The information about the servlet is returned by this method like version, author etc.
This method returns a string which should be in the form of plain text and not any kind
of markup.
Returns - a string that contains the information about the servlet
destroy()

public void destroy()


This method is called when we need to close the servlet. That is before removing a
servlet instance from service, the servlet container calls the destroy() method. Once the
servlet container calls the destroy() method, no service methods will be then called .
That is after the exit of all the threads running in the servlet, the destroy() method is
called. Hence, the servlet gets a chance to clean up all the resources like memory,
threads etc which are being held.
A typical Servlet lifecycle

1.4 HTTP

Before we can start writing the first Servlet, we need to know some basics of HTTP
("HyperText Transfer Protocol"), the protocol which is used by a WWW client (e.g. a
browser) to send a request to a Web Server.

HTTP is a request-response oriented protocol. An HTTP request consists of a request


method, a URI, header fields and a body (which can be empty). An HTTP response
contains a result code and again header fields and a body.

The service method of HttpServlet dispatches a request to different Java methods for
different HTTP request methods. It recognizes the standard HTTP/1.1 methods and
should not be overridden in subclasses unless you need to implement additional methods.
The recognized methods are GET, HEAD, PUT, POST, DELETE, OPTIONS and
TRACE. Other methods are answered with a Bad Request HTTP error. An HTTP method
XXX is dispatched to a Java method doXxx, e.g. GET -> doGet. All these methods expect
the parameters "(HttpServletRequest req, HttpServletResponse res)". The methods
doOptions and doTrace have suitable default implementations and are usually not
overridden. The HEAD method (which is supposed to return the same header lines that a
GET method would return, but doesn't include a body) is performed by calling doGet and
ignoring any output that is written by this method. That leaves us with the methods
doGet, doPut, doPost and doDelete whose default implementations in HttpServlet return
a Bad Request HTTP error. A subclass of HttpServlet overrides one or more of these
methods to provide a meaningful implementation.

The request data is passed to all methods through the first argument of type
HttpServletRequest (which is a subclass of the more general ServletRequest class). The
response can be created with methods of the second argument of type
HttpServletResponse (a subclass of ServletResponse).

When you request a URL in a Web Browser, the GET method is used for the request. A
GET request does not have a body (i.e. the body is empty). The response should contain a
body with the response data and header fields which describe the body (especially
Content-Type and Content-Encoding). When you send an HTML form, either GET or
POST can be used. With a GET request the parameters are encoded in the URL, with a
POST request they are transmited in the body. HTML editors and upload tools use PUT
requests to upload resources to a Web Server and DELETE requests to delete resources.

Conclusion: Thus we studied in detail servlet.


Expriment No.4

Aim: To Study of DHTML:CSS

Problem Statement: 1.WAP on inline stylesheet .


2. WAP on external stylesheet
3. WAP to style element.

Requirement: Notepad, Internet Explorer

Theory:
DHTML is NOT a language. It is a TERM describing the art of making
dynamic and interactive web pages. DHTML combines HTML, JavaScript, DOM, and
CSS is the W3C standard style and layout model for HTML.CSS allows web developers
to control the style and layout of web pages.HTML 4 allows dynamic changes to
CSS.DHTML is about using JavaScript and DOM to change the style and positioning of
HTML elements.

CSS Tutorial:
Using In-line Style This page is a CSS tutorial about how to use in-line stylesheets rules.
In-line CSS Style rules take precedence over internal CSS Style Sheets rules. The internal
CSS style sheet (template) takes precedence over any external CSS style sheets rules. The
lowest on the totem pole is the external style sheet (template), also called the external
CSS style sheets rules. The highest in the hierarchy is the in-line STYLE property which
can be added to a tag, such as <P STYLE="text-align:center;">.

In this paragraph the text will take on the properties of the internal CSS style,
CLASS="micro". If no internal Cascading Style Sheets rules have been established the
external CSS style will be used, if you created a text file for the external Cascading Style
Sheets rules. If no CSS is used, your Web page will be rendered by the default settings of
the user's browser.

If you find yourself using in-line styles a lot, you will want to consider making a new
class to handle any style that you are using repeatedly. Place it into an internal or external
style sheet rather than in-line style. In-line style was only meant for very occasional use.
Oh, and I get lazy and use it more than I should at times, so I will consiously try to clean
up my own faults, too. This is how it is done:
Let's say for some reason that your internal style sheet (persistent style) has specified all
of your H3 headings as blue and you need on to be a more subtle orange color. In the
BODY of the HTML document when you want this change to occur, you would code

<H3 STYLE = "color:#FF9473;">


just as if everything within the quotes is an actual declaration from a regular style sheet.
The quotes are required. Use semi-colons again if using more than one declaration.
Preceed the in-line style with STYLE = after the opening HTML "tag" and the entire in-
line style is coded before closing the first "tag".

Another example of in-line occurs when you want to change only the left and right
margins of one paragraph.

<P STYLE="margin-left:25; margin-right:25;">[text]</P>

For any element in HTML that has a STYLE attribute, you may use in-line style rather
than the internal style sheets rule.. Any inline style rule supercedes and over-rides the
internal style sheets rule. The internal style sheets rules however still supercede and over-
ride the external style sheets rules. This is the reason they are called Cascading Style
Sheets... their heirarchy flows from the external (least important), to the internal, and one
down to the in-line style sheets rule (most important in that in over-rides all the other
rules for the element).
Experiment No.5

Aim: To Study of XML.

Problem Statement: 1.WAP to create simple xml.


2. WAP to create simple xml with html.

Requirement: Notepad, Internet Explorer

Theory:

What is XML?

"XML is a cross-platform, software and hardware independent


tool for transmitting information"

XML is a W3C Recommendations. It stands for Extensible Markup


Language . It is a markup language much like HTML used to describe
data. In XML, tags are not predefined. A user defines his own tags
and XML document structure like Document Type Definition (DTD) ,
XML Schema to describe the data. Hence it is self-descriptive
too.There is Nothing Special About XML It is just plain text with
the addition of some XML tags enclosed in angle brackets. In a simple
text editor, the XML document is easily visible .

Why Is XML So Important?

There are number of reasons that contributes to the XML's increasing


acceptance , few of them are:
Plain Text

In XML it is easy to create and edit files with anything from a standard
text editor to a visual development environment. XML also provides
scalability for anything from small configuration files to a company-
wide data repository.

Data Identification

The markup tags in XML documents identifiy the information and break
up the data into parts for example.. a search program can look for
messages sent to particular people from the rest of the message.
Different parts of the information are identified and further they can
be used in different ways by different applications.

Stylability

When display matters, the stylesheet standard, XSL (an advance


feature of XML), lets you dictate over the convectional designs ( like
using HTML) to portray the data. XML being style-free, uses different
stylesheets to produce output in postscript, TEX, PDF, or some new
format that hasn't even been invented yet. A user can use a simple
XML document to display data in diverse formats like

• a plain text file


• an XHTML file
• a WML (Wireless Markup Language) document suitable for display on a PDA
• an Adobe PDF document suitable for hard copy
• a VML (Voice Markup Language) dialog for a voicemail information system
• an SVG (Scalable Vector Graphic) document that draws pictures of thermometers and
water containers

Universally Processed

Apart from being valid , restrictions are imposed on a xml file to abide
by a DTD or a Schema to make it well-formed .Otherwise, the XML
parser won't be able to read the data. XML is a vendor-neutral
standard, so a user can choose among several XML parsers to process
XML data.

Hierarchical Approach

XML documents get benefitted from their hierarchical structure.


Hierarchical document structures are, faster to access. They are also
easier to rearrange, because each piece is delimited. This makes xml
files easy to modify and maintain.

Inline Reusabiliy

XML documents can be composed of separate entities. XML entities


can be included "in line" in a XML document. And this included sections
look like a normal part of the document .A user can single-source a
section so that an edit to it is reflected everywhere the section is used,
and yet a document composed looks like a one-piece document.

How Can You Use XML?

Few Applications of XML

Although there are countless applications that use XML, here are a
few examples of the applications that are making use of this
technology.

Refined search results - With XML-specific tags, search engines can


give users more refined search results. A search engine seeks the term
in the tags, rather than the entire document, giving the user more
precise results.

EDI Transactions - XML has made electronic data interchange (EDI)


transactions accessible to a broader set of users. XML allows data to
be exchanged, regardless of the computing systems or accounting
applications being used.

Cell Phones - XML data is sent to some cell phones, which is then
formatted by the specification of the cell phone software designer to
display text, images and even play sounds!

File Converters - Many applications have been written to convert existing documents
into the XML standard. An example is a PDF to XML converter.

VoiceXML - Converts XML documents into an audio format so that a


user can listen to an XML document.

Comparing XML with HTML

The Main Differences Between XML and HTML


XML is designed to carry data.
XML describes and focuses on the data while HTML only displays and focuses on
how data looks. HTML is all about displaying information but XML is all about
describing information. In current scenario XML is the most common tool for data
manipulation and data transmission.
XML is used to store data in files and for sharing data between diverse applications.
Unlike HTML document where data and display logic are available in the same file,
XML hold only data. Different presentation logics could be applied to display the xml
data in the required format. XML is the best way to exchange information.
XML is Free and Extensible
XML tags are not predefined. User must "invent" his tags.
The tags used to mark up HTML documents and the structure of HTML documents are
predefined. The author of HTML documents can only use tags that are defined in the
HTML standard (like <p>, <h1>, etc.).
XML allows the user to define his own tags and document structure.
XML Tags are Case Sensitive
Unlike HTML, XML tags are case sensitive. In HTML the following will work:
<Message>This is incorrect</message>
In XML opening and closing tags must therefore be written with the same case:
<message>This is correct</message

XML Elements Must be Properly Nested


Improper nesting of tags makes no sense to XML.
In HTML some elements can be improperly nested within each other like this:
<b><i>This text is bold and italic</b></i>

In XML all elements must be properly nested within each other like this:
<b><i>This text is bold and italic</i></b>

XML is a Complement to HTML


XML is not a replacement for HTML.
It is important to understand that XML is not a replacement for HTML. In Web
development it is most likely that XML will be used to describe the data, while HTML
will be used to format and display the same data.

XML Syntax Rules


The syntax rules for XML are very simple and strict. These are easy to learn and
use. Because of this, creating software that can read and manipulate XML is very easy.
Xml enables an user to create his own tags.

Note - XML documents use a self-describing and simple syntax

Let's develop a simple XML document :

<?xml version="1.0" encoding="ISO-8859-1"?>


<E-mail>
<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u tonight</Body>
</E-mail>

The XML declaration: Always the first line in the xml document:

The XML declaration should always be included. It defines the XML


version and the character encoding used in the document. In this case
the document conforms to the 1.0 specification of XML and uses the
ISO-8859-1 (Latin-1/West European) character set.

<?xml version="1.0" encoding="ISO-8859-1"?>

Root Element: The next line defines the first element of the
document . It is called as the root element

<E-mail>

Child Elements: The next 4 lines describe the four child elements of
the root (To, From, Subject and Body).

<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u
tonight</Body>

And finally the last line defines the end of the root element .

</E-mail>
you may feel from this example that the XML document contains a E-
mail To Rohan From Amit. Don't you agree that XML is quite self-
descriptive?

Now let's discuss its syntax-rules which are very simple to learn.

All XML elements must have a closing tag

In XML all the elements must have a closing tag like this:

<To>Rohan</To>
<From>Amit</From>

XML tags are case sensitive

XML tags are case sensitive. The tag <To> is different from the tag
<to>.Hence the opening and closing tags must be written with the
same case:

<To>Rohan</To>
<to>Rohan</to>

XML Elements Must be Properly Nested

Improper nesting of tags makes no sense to XML. In XML all


elements must be properly nested within each other like this in a
logical order:

<b><i>Hi , how are you.....</i></b>

XML Documents Must Have a Root Element

All XML documents must contain a single tag pair to define a root
element. All other elements must be written within this root element.
All elements can have sub elements called as child elements. Sub
elements must be correctly nested within their parent element:

<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Always Quote the XML Attribute Values

In XML the attribute value must always be quoted. XML elements can
have attributes in name/value pairs just like in HTML. Just look the two
XML documents below.

The error in the first document is that the date and version attributes are not quoted .
<?xml version=1.0 encoding="ISO-8859-1"?>
<E-mail date=12/11/2002/>

The second document is correct:

<?xml version="1.0" encoding="ISO-8859-1"?>


<E-mail date="12/11/2002"/>

With XML, White Space is Preserved

With XML, the white space in a document is preserved .

So a sentence like this : Hello How are you, will be


displayed like this:

Hello How are you,

Comments in XML

The syntax for writing comments in XML is similar to that of HTML.

<!-- This is a comment -->

XML Elements are extensible. They have relationships. They have simple naming
rules.

XML Element

XML Elements are Extensible

XML documents can be extended to carry more information.


Look at the following XML example:

<?xml version="1.0" encoding="ISO-8859-1"?>


<E-mail>
<To>Rohan</To>
<From>Amit</From>
<Body>Be ready for a cruise...i will catch u tonight</Body>
</E-mail>

Let's suppose that we create an application to fetch data from the


above XML document and produce this output:

E-mail

To: Rohan
From: Amit

Be ready for a cruise...i will catch u


tonight

Now, the author wants to add a new feature (let it be a subject line).
He can easily achieve it by adding one more tag ie..<Subject>in the
xml document. So the new modified xml document will look like this :

<?xml version="1.0" encoding="ISO-8859-1"?>


<E-mail>
<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u tonight</Body>
</E-mail>

Now the new generated output will look like this

E-mail

To: Rohan
From: Amit

Subject : Surprise....

Be ready for a cruise...i will catch u


tonight
XML Elements have Relationships

Elements in a xml document are related as parents and


children.

Imagine that this xml document is a description of a e-mail:

<?xml version="1.0" encoding="ISO-8859-1"?>


<E-mail>
<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u
tonight</Body>
</E-mail>

Here, E-mail is the root element while To, From, Subject and Body are
the child elements of the E-mail. Here, E-mail is the parent element
of To, From, Subject and Body. To, From, Subject and Body are
siblings (or sister elements) because they have the same parentage.
Hence , all the XML Elements have Relationships.

XML Element Naming : Know-hows

XML elements must follow these naming conventions:

Names must not start with a number or punctuation character but it can contain letters,
numbers, and other characters without spaces. Names must not start with the letters xml
(or XML, or Xml, etc)

XML Attributes
XML elements can have attributes in the start tag, just like HTML. Attributes are used to
provide additional information about elements. Attributes often provide information that
is not a part of the data. In the example below, the file type is irrelevant to the data, but
important to the software that wants to manipulate the element:

<file type="gif">roseindia.gif</file>

Use the quote styles: "red" or 'red'


Attribute values must always be enclosed in quotes. Use either single or double quotes
eg..
<color="red">

or like this:

<color='red'>

Note: If the attribute value itself contains double quotes it is necessary to use single
quotes, like in this example:

<name='Rose "India" Net'>

Note: If the attribute value itself contains single quotes it is necessary to use double
quotes, like in this example:

<name="Rose 'India' Net">

Use of Elements vs. Attributes


If you start using attributes as containers for XML data, you might end up with the
documents that are both difficult to maintain and manipulate. So the user should use
elements to describe the data. Use attributes only to provide data that is not relevant to
the reader. Only metadata (data about data) should be stored as attributes, and that data
itself should be stored as elements.

This is not the way to use attributes eg..

<?xml version="1.0" encoding="ISO-8859-1"?>


<E-mail To="Rohan" From="Amit" Subject="Surprise...."
<Body>Be ready for a cruise...i will catch u tonight</Body>
</E-mail>

Try to avoid using attributes in few of the situations.


Lot of problems occur with using attributes values. They are not easily expandable and
cannot contain multiple values .They are not easy to test against a Document Type
Definition and are also unable to describe their structure. Becomes more irritating
,because of its difficultly to get manipulated by program code.

Here is an example, demonstrating how elements can be used instead of attributes. The
following three XML documents contain exactly the same information. A date attribute is
used in the first, a date element is used in the second, and an expanded date element is
used in the third:

<?xml version="1.0" encoding="ISO-8859-1"?>


<E-mail date="15/05/07">
<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u tonight</Body>
</E-mail>

First xml document contains date as a attribute which can not be further extended. But
date used a element in second document makes it more flexible.

<?xml version="1.0" encoding="ISO-8859-1"?>


<E-mail >
<date="15/05/07">
<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u tonight</Body>
</E-mail>

Second xml document can be further extended as..

<?xml version="1.0" encoding="ISO-8859-1"?>


<E-mail >
<date>
<day>12</day>
<month>11</month>
<year>99</year>
</date>
<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u tonight</Body>
</E-mail>

Conclusion: thus we studied XML.

Experiment No.6

Aim: To Study of XSL.

Requirement: Notepad, Internet Explorer


Theory:
Introduction

This specification defines the syntax and semantics of the XSLT language. A
transformation in the XSLT language is expressed as a well-formed XML document
[XML] conforming to the Namespaces in XML Recommendation [XML Names], which
may include both elements that are defined by XSLT and elements that are not defined by
XSLT. XSLT-defined elements are distinguished by belonging to a specific XML
namespace (see [2.1 XSLT Namespace]), which is referred to in this specification as the
XSLT namespace. Thus this specification is a definition of the syntax and semantics of
the XSLT namespace.

A transformation expressed in XSLT describes rules for transforming a source tree into a
result tree. The transformation is achieved by associating patterns with templates. A
pattern is matched against elements in the source tree. A template is instantiated to create
part of the result tree. The result tree is separate from the source tree. The structure of the
result tree can be completely different from the structure of the source tree. In
constructing the result tree, elements from the source tree can be filtered and reordered,
and arbitrary structure can be added.

A transformation expressed in XSLT is called a stylesheet. This is because, in the case


when XSLT is transforming into the XSL formatting vocabulary, the transformation
functions as a stylesheet.

This document does not specify how an XSLT stylesheet is associated with an XML
document. It is recommended that XSL processors support the mechanism described in
[XML Stylesheet]. When this or any other mechanism yields a sequence of more than
one XSLT stylesheet to be applied simultaneously to a XML document, then the effect
should be the same as applying a single stylesheet that imports each member of the
sequence in order (see [2.6.2 Stylesheet Import]).

A stylesheet contains a set of template rules. A template rule has two parts: a pattern
which is matched against nodes in the source tree and a template which can be
instantiated to form part of the result tree. This allows a stylesheet to be applicable to a
wide class of documents that have similar source tree structures.

A template is instantiated for a particular source element to create part of the result tree.
A template can contain elements that specify literal result element structure. A template
can also contain elements from the XSLT namespace that are instructions for creating
result tree fragments. When a template is instantiated, each instruction is executed and
replaced by the result tree fragment that it creates. Instructions can select and process
descendant source elements. Processing a descendant element creates a result tree
fragment by finding the applicable template rule and instantiating its template. Note that
elements are only processed when they have been selected by the execution of an
instruction. The result tree is constructed by finding the template rule for the root node
and instantiating its template.

In the process of finding the applicable template rule, more than one template rule may
have a pattern that matches a given element. However, only one template rule will be
applied. Single template by itself has considerable power: it can create structures of
arbitrary complexity; it can pull string values out of arbitrary locations in the source tree;
it can generate structures that are repeated according to the occurrence of elements in the
source tree. For simple transformations where the structure of the result tree is
independent of the structure of the source tree, a stylesheet can often consist of only a
single template, which functions as a template for the complete result tree.
Transformations on XML documents that represent data are often of this kind. XSLT
allows a simplified syntax for such stylesheets.

When a template is instantiated, it is always instantiated with respect to a current node


and a current node list. The current node is always a member of the current node list.
Many operations in XSLT are relative to the current node. Only a few instructions change
the current node list or the current node (see [5 Template Rules] and [8 Repetition]);
during the instantiation of one of these instructions, the current node list changes to a new
list of nodes and each member of this new list becomes the current node in turn; after the
instantiation of the instruction is complete, the current node and current node list revert to
what they were before the instruction was instantiated.

XSLT makes use of the expression language defined by [XPath] for selecting elements
for processing, for conditional processing and for generating text.

XSLT provides two "hooks" for extending the language, one hook for extending the set
of instruction elements used in templates and one hook for extending the set of functions
used in XPath expressions. These hooks are both based on XML namespaces. This
version of XSLT does not define a mechanism for implementing the hooks..

The element syntax summary notation used to describe the syntax of XSLT-defined
elements is described .The MIME media types text/xml and application/xml [RFC2376]
should be used for XSLT stylesheets. It is possible that a media type will be registered
specifically for XSLT stylesheets; if and when it is, that media type may also be used.

2 Stylesheet Structure

XSLT Namespace

The XSLT namespace has the URI http://www.w3.org/1999/XSL/Transform.

NOTE:The 1999 in the URI indicates the year in which the URI was allocated by the
W3C. It does not indicate the version of XSLT being used, which is specified by
attributes (see Stylesheet Element] and [Literal Result Element as Stylesheet]).
XSLT processors must use the XML namespaces mechanism [XML Names] to recognize
elements and attributes from this namespace. Elements from the XSLT namespace are
recognized only in the stylesheet not in the source document. The complete list of XSLT-
defined elements is specified in [B Element Syntax Summary]. Vendors must not
extend the XSLT namespace with additional elements or attributes. Inst that is used for
additional instruction elements must be identified by means of the extension element
mechanism specified in [ Extension Elements].

This specification uses a prefix of xsl: for referring to elements in the XSLT namespace.
However, XSLT stylesheets are free to use any prefix, provided that there is a namespace
declaration that binds the prefix to the URI of the XSLT namespace.

An element from the XSLT namespace may have any attribute not from the XSLT
namespace, provided that the expanded-name of the attribute has a non-null namespace
URI. The presence of such attributes must not change the behavior of XSLT elements
and functions defined in this document. Thus, an XSLT processor is always free to ignore
such attributes, and must ignore such attributes without giving an error if it does not
recognize the namespace URI. Such attributes can provide, for example, unique
identifiers, optimization hints, or documentation.

It is an error for an element from the XSLT namespace to have attributes with expanded-
names that have null namespace URIs (i.e. attributes with unprefixed names) other than
attributes defined for the element in this document.

2.2 Stylesheet Element

<xsl:stylesheet
id = id
extension-element-prefixes = tokens
exclude-result-prefixes = tokens
version = number>
<!-- Content: (xsl:import*, top-level-elements) -->
</xsl:stylesheet>

<xsl:transform
id = id
extension-element-prefixes = tokens
exclude-result-prefixes = tokens
version = number>
<!-- Content: (xsl:import*, top-level-elements) -->
</xsl:transform>

A stylesheet is represented by an xsl:stylesheet element in an XML document.


xsl:transform is allowed as a synonym for xsl:stylesheet.
An xsl:stylesheet element must have a version attribute, indicating the version of XSLT
that the stylesheet requires. For this version of XSLT, the value should be 1.0. When the
value is not equal to 1.0, forwards-compatible processing mode is enabled The
xsl:stylesheet element may contain the following types of elements:

• xsl:import
• xsl:include
• xsl:strip-space
• xsl:preserve-space
• xsl:output
• xsl:key
• xsl:decimal-format
• xsl:namespace-alias
• xsl:attribute-set
• xsl:variable
• xsl:param
• xsl:template

An element occurring as a child of an xsl:stylesheet element is called a top-level element.

This example shows the structure of a stylesheet. Ellipses (...) indicate where attribute
values or content have been omitted. Although this example shows one of each type of
allowed element, stylesheets may contain zero or more of each of these elements.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="..."/>

<xsl:include href="..."/>

<xsl:strip-space elements="..."/>

<xsl:preserve-space elements="..."/>

<xsl:output method="..."/>

<xsl:key name="..." match="..." use="..."/>

<xsl:decimal-format name="..."/>

<xsl:namespace-alias stylesheet-prefix="..." result-prefix="..."/>

<xsl:attribute-set name="...">
...
</xsl:attribute-set>
<xsl:variable name="...">...</xsl:variable>

<xsl:param name="...">...</xsl:param>

<xsl:template match="...">
...
</xsl:template>

<xsl:template name="...">
...
</xsl:template>

</xsl:stylesheet>

The order in which the children of the xsl:stylesheet element occur is not significant
except for xsl:import elements and for error recovery. Users are free to order the elements
as they prefer, and stylesheet creation tools need not provide control over the order in
which the elements occur.

In addition, the xsl:stylesheet element may contain any element not from the XSLT
namespace, provided that the expanded-name of the element has a non-null namespace
URI. The presence of such top-level elements must not change the behavior of XSLT
elements and functions defined in this document; for example, it would not be permitted
for such a top-level element to specify that xsl:apply-templates was to use different rules
to resolve conflicts. Thus, an XSLT processor is always free to ignore such top-level
elements, and must ignore a top-level element without giving an error if it does not
recognize the namespace URI. Such elements can provide, for example,

• information used by extension elements or extension functions (see [14


Extensions]),
• information about what to do with the result tree,
• information about how to obtain the source tree,
• metadata about the stylesheet,
• structured documentation for the stylesheet.

2.3 Literal Result Element as Stylesheet

A simplified syntax is allowed for stylesheets that consist of only a single template for
the root node. The stylesheet may consist of just a literal result element (see [7.1.1
Literal Result Elements]). Such a stylesheet is equivalent to a stylesheet with an
xsl:stylesheet element containing a template rule containing the literal result element; the
template rule has a match pattern of /. For example

<html xsl:version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/strict">
<head>
<title>Expense Report Summary</title>
</head>
<body>
<p>Total Amount: <xsl:value-of select="expense-report/total"/></p>
</body>
</html>

has the same meaning as

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/strict">
<xsl:template match="/">
<html>
<head>
<title>Expense Report Summary</title>
</head>
<body>
<p>Total Amount: <xsl:value-of select="expense-report/total"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

A literal result element that is the document element of a stylesheet must have an
xsl:version attribute, which indicates the version of XSLT that the stylesheet requires. For
this version of XSLT, the value should be 1.0; the value must be a Number. Other literal
result elements may also have an xsl:version attribute. When the xsl:version attribute is
not equal to 1.0, forwards-compatible processing mode is enabled The allowed content of
a literal result element when used as a stylesheet is no different from when it occurs
within a stylesheet. Thus, a literal result element used as a stylesheet cannot contain top-
level elements.

In some situations, the only way that a system can recognize that an XML document
needs to be processed by an XSLT processor as an XSLT stylesheet is by examining the
XML document itself. Using the simplified syntax makes this harder.

Therefore, the simplified syntax should not be used for XSLT stylesheets that may be
used in such a situation. This situation can, for example, arise when an XSLT stylesheet
is transmitted as a message with a MIME media type of text/xml or application/xml to a
recipient that will use the MIME media type to determine how the message is processed.
2.4 Qualified Names

The name of an internal XSLT object, specifically a named template (see Named
Templates]), a mode (see [ Modes]), an attribute set (see [Named Attribute Sets]), a
key (see [12.2 Keys]), a decimal-format (see [ Number Formatting]), a variable or a
parameter (see [ Variables and Parameters]) is specified as a QName. If it has a prefix,
then the prefix is expanded into a URI reference using the namespace declarations in
effect on the attribute in which the name occurs. The expanded-name consisting of the
local part of the name and the possibly null URI reference is used as the name of the
object. The default namespace is not used for unprefixed names.

2.5 Forwards-Compatible Processing

An element enables forwards-compatible mode for itself, its attributes, its descendants
and their attributes if either it is an xsl:stylesheet element whose version attribute is not
equal to 1.0, or it is a literal result element that has an xsl:version attribute whose value is
not equal to 1.0, or it is a literal result element that does not have an xsl:version attribute
and that is the document element of a stylesheet using the simplified syntax (see [Literal
Result Element as Stylesheet]). A literal result element that has an xsl:version attribute
whose value is equal to 1.0 disables forwards-compatible mode for itself, its attributes, its
descendants and their attributes.

If an element is processed in forwards-compatible mode, then:

• if it is a top-level element and XSLT 1.0 does not allow such elements as top-
level elements, then the element must be ignored along with its content;
• if it is an element in a template and XSLT 1.0 does not allow such elements to
occur in templates, then if the element is not instantiated, an error must not be
signaled, and if the element is instantiated, the XSLT must perform fallback for
the element as specified in [ Fallback];
• if the element has an attribute that XSLT 1.0 does not allow the element to have
or if the element has an optional attribute with a value that the XSLT 1.0 does not
allow the attribute to have, then the attribute must be ignored.

Thus, any XSLT 1.0 processor must be able to process the following stylesheet without
error, although the stylesheet includes elements from the XSLT namespace that are not
defined in this specification:

<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:choose>
<xsl:when test="system-property('xsl:version') >= 1.1">
<xsl:exciting-new-1.1-feature/>
</xsl:when>
<xsl:otherwise>
<html>
<head>
<title>XSLT 1.1 required</title>
</head>
<body>
<p>Sorry, this stylesheet requires XSLT 1.1.</p>
</body>
</html>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
NOTE:If a stylesheet depends crucially on a top-level element introduced by a version of
XSL after 1.0, then the stylesheet can use an xsl:message element with terminate="yes"
(see [13 Messages]) to ensure that XSLT processors implementing earlier versions of
XSL will not silently ignore the top-level element. For example,
<xsl:stylesheet version="1.5"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:important-new-1.1-declaration/>

<xsl:template match="/">
<xsl:choose>
<xsl:when test="system-property('xsl:version') &lt; 1.1">
<xsl:message terminate="yes">
<xsl:text>Sorry, this stylesheet requires XSLT 1.1.</xsl:text>
</xsl:message>
</xsl:when>
<xsl:otherwise>
...
</xsl:otherwise>
</xsl:choose>
</xsl:template>
...
</xsl:stylesheet>

If an expression occurs in an attribute that is processed in forwards-compatible mode,


then an XSLT processor must recover from errors in the expression as follows:

• if the expression does not match the syntax allowed by the XPath grammar, then
an error must not be signaled unless the expression is actually evaluated;
• if the expression calls a function with an unprefixed name that is not part of the
XSLT library, then an error must not be signaled unless the function is actually
called;
• if the expression calls a function with a number of arguments that XSLT does not
allow or with arguments of types that XSLT does not allow, then an error must
not be signaled unless the function is actually called.

2.6 Combining Stylesheets

XSLT provides two mechanisms to combine stylesheets:

• an inclusion mechanism that allows stylesheets to be combined without changing


the semantics of the stylesheets being combined, and
• an import mechanism that allows stylesheets to override each other.

2.6.1 Stylesheet Inclusion

<!-- Category: top-level-element -->


<xsl:include
href = uri-reference />

An XSLT stylesheet may include another XSLT stylesheet using an xsl:include element.
The xsl:include element has an href attribute whose value is a URI reference identifying
the stylesheet to be included. A relative URI is resolved relative to the base URI of the
xsl:include element (see [3.2 Base URI]).

The xsl:include element is only allowed as a top-level element.

The inclusion works at the XML tree level. The resource located by the href attribute
value is parsed as an XML document, and the children of the xsl:stylesheet element in
this document replace the xsl:include element in the including document. The fact that
template rules or definitions are included does not affect the way they are processed.

The included stylesheet may use the simplified syntax described in [2.3 Literal Result
Element as Stylesheet]. The included stylesheet is treated the same as the equivalent
xsl:stylesheet element.

It is an error if a stylesheet directly or indirectly includes itself.

NOTE:Including a stylesheet multiple times can cause errors because of duplicate


definitions. Such multiple inclusions are less obvious when they are indirect. For
example, if stylesheet B includes stylesheet A, stylesheet C includes stylesheet A, and
stylesheet D includes both stylesheet B and stylesheet C, then A will be included
indirectly by D twice. If all of B, C and D are used as independent stylesheets, then the
error can be avoided by separating everything in B other than the inclusion of A into a
separate stylesheet B' and changing B to contain just inclusions of B' and A, similarly for
C, and then changing D to include A, B', C'.
2.6.2 Stylesheet Import

<xsl:import
href = uri-reference />

An XSLT stylesheet may import another XSLT stylesheet using an xsl:import element.
Importing a stylesheet is the same as including it (see [2.6.1 Stylesheet Inclusion])
except that definitions and template rules in the importing stylesheet take precedence
over template rules and definitions in the imported stylesheet; this is described in more
detail below. The xsl:import element has an href attribute whose value is a URI reference
identifying the stylesheet to be imported. A relative URI is resolved relative to the base
URI of the xsl:import element (see [3.2 Base URI]).

The xsl:import element is only allowed as a top-level element. The xsl:import element
children must precede all other element children of an xsl:stylesheet element, including
any xsl:include element children. When xsl:include is used to include a stylesheet, any
xsl:import elements in the included document are moved up in the including document to
after any existing xsl:import elements in the including document.

For example,

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="article.xsl"/>
<xsl:import href="bigfont.xsl"/>
<xsl:attribute-set name="note-style">
<xsl:attribute name="font-style">italic</xsl:attribute>
</xsl:attribute-set>
</xsl:stylesheet>

The xsl:stylesheet elements encountered during processing of a stylesheet that contains


xsl:import elements are treated as forming an import tree. In the import tree, each
xsl:stylesheet element has one import child for each xsl:import element that it contains.
Any xsl:include elements are resolved before constructing the import tree. An
xsl:stylesheet element in the import tree is defined to have lower import precedence
than another xsl:stylesheet element in the import tree if it would be visited before that
xsl:stylesheet element in a post-order traversal of the import tree (i.e. a traversal of the
import tree in which an xsl:stylesheet element is visited after its import children). Each
definition and template rule has import precedence determined by the xsl:stylesheet
element that contains it.

For example, suppose

• stylesheet A imports stylesheets B and C in that order;


• stylesheet B imports stylesheet D;
• stylesheet C imports stylesheet E.
Then the order of import precedence (lowest first) is D, B, E, C, A.

NOTE:Since xsl:import elements are required to occur before any definitions or template
rules, an implementation that processes imported stylesheets at the point at which it
encounters the xsl:import element will encounter definitions and template rules in
increasing order of import precedence.

In general, a definition or template rule with higher import precedence takes precedence
over a definition or template rule with lower import precedence. This is defined in detail
for each kind of definition and for template rules.

It is an error if a stylesheet directly or indirectly imports itself. Apart from this, the case
where a stylesheet with a particular URI is imported in multiple places is not treated
specially. The import tree will have a separate xsl:stylesheet for each place that it is
imported.

NOTE:If xsl:apply-imports is used (see [5.6 Overriding Template Rules]), the behavior
may be different from the behavior if the stylesheet had been imported only at the place
with the highest import precedence.

Embedding Stylesheets

Normally an XSLT stylesheet is a complete XML document with the xsl:stylesheet


element as the document element. However, an XSLT stylesheet may also be embedded
in another resource. Two forms of embedding are possible:

• the XSLT stylesheet may be textually embedded in a non-XML resource, or


• the xsl:stylesheet element may occur in an XML document other than as the
document element.

To facilitate the second form of embedding, the xsl:stylesheet element is allowed to have
an ID attribute that specifies a unique identifier.

NOTE:In order for such an attribute to be used with the XPath id function, it must
actually be declared in the DTD as being an ID.

The following example shows how the xml-stylesheet processing instruction [XML
Stylesheet] can be used to allow a document to contain its own stylesheet. The URI
reference uses a relative URI with a fragment identifier to locate the xsl:stylesheet
element:

<?xml-stylesheet type="text/xml" href="#style1"?>


<!DOCTYPE doc SYSTEM "doc.dtd">
<doc>
<head>
<xsl:stylesheet id="style1"
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:import href="doc.xsl"/>
<xsl:template match="id('foo')">
<fo:block font-weight="bold"><xsl:apply-templates/></fo:block>
</xsl:template>
<xsl:template match="xsl:stylesheet">
<!-- ignore -->
</xsl:template>
</xsl:stylesheet>
</head>
<body>
<para id="foo">
...
</para>
</body>
</doc>

Thus, we studied XSL

You might also like