Professional Documents
Culture Documents
Theory:
• 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
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:
Theory:
What is JavaScript?
JavaScript Statements
This JavaScript statement tells the browser to write "Hello Dolly" to the web page:
document.write("Hello Dolly");
JavaScript Variables
A variable can have a short name, like x, or a more descriptive name, like carname.
• 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:
Given that x=10 and y=5, the table below explains the assignment operators:
Given that x=5, the table below explains the comparison operators:
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:
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.
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.
To access and to set values inside an array, you must use the index numbers as follows:
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
Theory:
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.
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).
• 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.
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 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:
init()
• 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()
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()
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.
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.
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
Another example of in-line occurs when you want to change only the left and right
margins of one paragraph.
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
Theory:
What is XML?
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
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
Inline Reusabiliy
Although there are countless applications that use XML, here are a
few examples of the applications that are making use of this
technology.
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.
In XML all elements must be properly nested within each other like this:
<b><i>This text is bold and italic</i></b>
The XML declaration: Always the first line in the xml document:
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.
In XML all the elements must have a closing tag like this:
<To>Rohan</To>
<From>Amit</From>
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>
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/>
Comments in XML
XML Elements are extensible. They have relationships. They have simple naming
rules.
XML Element
To: Rohan
From: Amit
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 :
To: Rohan
From: Amit
Subject : Surprise....
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.
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>
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:
Note: If the attribute value itself contains single quotes it is necessary to use double
quotes, like in this example:
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:
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.
Experiment No.6
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.
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.
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
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.
<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>
• 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
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:decimal-format name="..."/>
<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,
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>
<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.
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 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') < 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 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.
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 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.
<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>
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
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: