xml

Post on 07-Nov-2014

17 views 0 download

Tags:

Transcript of xml

XML was designed to transport and store data. HTML was designed to display data.

XML stands for eXtensible Markup Language. The XML standard was created by W3C to provide an easy to use and standardized way to store self-describing data (self-describing data is data that describes both its content and its structure).

What is XML?

XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display data XML tags are not predefined. You must define your own tags XML is designed to be self-descriptive XML is a W3C Recommendation

The Difference Between XML and HTML

XML is not a replacement for HTML.

XML and HTML were designed with different goals:

XML was designed to transport and store data, with focus on what data is HTML was designed to display data, with focus on how data looks

HTML is about displaying information, while XML is about carrying information.

XML Does Not DO Anything

Maybe it is a little hard to understand, but XML does not DO anything. XML was created to structure, store, and transport information.

The following example is a note to Tove, from Jani, stored as XML:

<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

The note above is quite self descriptive. It has sender and receiver information, it also has a heading and a message body.

But still, this XML document does not DO anything. It is just information wrapped in tags. Someone must write a piece of software to send, receive or display it.

With XML You Invent Your Own Tags

The tags in the example above (like <to> and <from>) are not defined in any XML standard. These tags are "invented" by the author of the XML document.

That is because the XML language has no predefined tags.

The tags used in HTML are predefined. HTML documents can only use tags defined in the HTML standard (like <p>, <h1>, etc.).

XML allows the author to define his/her own tags and his/her own document structure.

XML is Not a Replacement for HTML

XML is a complement to HTML.

It is important to understand that XML is not a replacement for HTML. In most web applications, XML is used to transport data, while HTML is used to format and display the data.

My best description of XML is this:

XML is a software- and hardware-independent tool for carrying information.

XML is a W3C Recommendation

XML became a W3C Recommendation on February 10, 1998.

XML is Everywhere

XML is now as important for the Web as HTML was to the foundation of the Web.

XML is the most common tool for data transmissions between all sorts of applications.

XML is used in many aspects of web development, often to simplify data storage and sharing.

XML Separates Data from HTML

If you need to display dynamic data in your HTML document, it will take a lot of work to edit the HTML each time the data changes.

With XML, data can be stored in separate XML files. This way you can concentrate on using HTML/CSS for display and layout, and be sure that changes in the underlying data will not require any changes to the HTML.

With a few lines of JavaScript code, you can read an external XML file and update the data content of your web page.

XML Simplifies Data Sharing

In the real world, computer systems and databases contain data in incompatible formats.

XML data is stored in plain text format. This provides a software- and hardware-independent way of storing data.

This makes it much easier to create data that can be shared by different applications.

XML Simplifies Data Transport

One of the most time-consuming challenges for developers is to exchange data between incompatible systems over the Internet.

Exchanging data as XML greatly reduces this complexity, since the data can be read by different incompatible applications.

XML Simplifies Platform Changes

Upgrading to new systems (hardware or software platforms), is always time consuming. Large amounts of data must be converted and incompatible data is often lost.

XML data is stored in text format. This makes it easier to expand or upgrade to new operating systems, new applications, or new browsers, without losing data.

XML Makes Your Data More Available

Different applications can access your data, not only in HTML pages, but also from XML data sources.

With XML, your data can be available to all kinds of "reading machines" (Handheld computers, voice machines, news feeds, etc), and make it more available for blind people, or people with other disabilities.

XML is Used to Create New Internet Languages

A lot of new Internet languages are created with XML.

Here are some examples:

XHTML  WSDL for describing available web services WAP and WML as markup languages for handheld devices RSS languages for news feeds RDF and OWL for describing resources and ontology SMIL for describing multimedia for the web 

If Developers Have Sense

If they DO have sense, future applications will exchange their data in XML.

The future might give us word processors, spreadsheet applications and databases that can read each other's data in XML format, without any conversion utilities in between.

The XML tag is very similar to that of the HTML tag. Each element is marked with an opening tag and a closing tag. Below, we have highlighted both the opening and closing tags from a piece of our example XML file.

XML Code:

<name>Robert</name><grade>A+</grade>

XML Tag

A tag is just a generic name for a <element>. An opening tag looks like <element>, while a closing tag has a slash that is placed before the element's name: </element>. From now on we will refer to the opening or closing of an element as open or close tags. All information that belongs to an element must be contained between the opening and closing tags of an element.

XML Attribute

Attributes are used to specify additional information about the element. It may help to think of attributes as a means of specializing generic elements to fit your needs. An attribute for an element appears within the opening tag.

If there are multiple values an attribute may have, then the value of the attribute must be specified. For example, if a tag had a color attribute then the value would be: red, blue, green, etc. The syntax for including an attribute in an element is:

<element attributeName="value">

In this example we will be using a madeup XML element named "friend" that has an optional attribute age.

XML Code:

<friend age="23">Samantha</friend>

Element Review

Elements are used to classify data in an XML document so that the data becomes "self-explanatory".

Opening and closing tags represent the start and end of an element. Attributes are used to include additional information on top of the data that falls between the

opening and closing tag.

Parts of an XML Document

An XML document is made up of a small group of building blocks. W3C wanted to keep XML simple, and judging by the relatively few components of an XML document, they seem to have succeeded. We have divided the components into sections and subsections.

Prologo XML Declarationo DTD Declaration

Root Element (Document)o Elements (Nested Elements)

Element Attributes and Values Data

Webpage standards now recommend that an HTML document follow this form, so that they can be considered valid XML. In an HTML file the root element is <html>.

XML Prolog

The XML prolog is an optional piece of information that must come before the root element when used. There are two pieces that make up the prolog: the XML declaration and the Document Type Declaration (DTD).

The XML declaration states which version of XML you are using, while the DTD describes the rules your XML document must follow.

XML Root Element (Document)

The root element, also referred to as the "document", dictates what kind of XML document it is. When creating an HTML file that is XML complaint, the root element will be <html>. The root element must be the first element in an XML document and there can only be one root element per file!

XML Element & Attributes

The meat of an XML document comes from the elements that are contained within the root element. Each element represents a different type of data that is being stored in the document. The element <p> might represent paragraph text, while the element <gif> may contain data for a GIF image.

Although not required, elements often have attributes that are associated with them. XML attributes are similar to HTML attributes in that they have a name:value relationship. An

example attribute for an <img> element might be "src", which represents the source location of the image.

XML Element & Attribute Code:

<img src = "C:/MyDocs/Happy.gif"></img>

XML Data

In addition to the information stored in the element itself (attributes), the bulk of data in XML usually appears between the opening and closing tag of an XML element. This is often referred to as the XML's "content". Below, we have an imaginary XML document that stores a story.

XML Code:

<story><author>Jill Doe</author><title>The Truth About the Family</title><page>

<paragraph>Here's a story of a lovely lady who...</paragraph><paragraph>...they became the Brady Bunch...</paragraph>

</page></story>

In an XML file, there can only be one root element. The root element must encapsulate all other elements--meaning, these other elements must show up after the opening root tag and before the closing root tag. Here is an example of an XML document with the root element "phonebook".

XML Code:

<phonebook><number></number><name></name>

</phonebook>

XML comments have the exact same syntax as HTML comments. Below is an example of a notation comment that should be used when you need to leave a note to yourself or to someone who may be viewing your XML.

XML Code:

<?xml version="1.0" encoding="ISO-8859-15"?><!-- Students grades are updated bi-monthly --><class_list>

<student>

<name>Robert</name><grade>A+</grade>

</student><student>

<name>Lenard</name><grade>A-</grade>

</student></class_list>

XML Commenting out XML

XML Comments let you do this easily, as this example below shows.

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

<class_list><student>

<name>Robert</name><grade>A+</grade>

</student><!--

<student><name>Lenard</name><grade>A-</grade>

</student> --></class_list>

XML Prolog

The prolog is an optional component of the XML document. If included, the prolog must be appear before the root element. A prolog consists of two parts: the XML declaration and the Document Type Declaration (DTD). Depending on your needs, you can choose to include both, either, or neither of these items in your XML document. The DTD is most oftenly used, so we will discuss its use and purpose first.

XML Document Type Declaration (DTD)

The Document Type Declaration is a file that contains the necessary rules that the XML code in this file must follow. You may think of the DTD as the grammar that the XML document must abide by to be a valid XML file.

In later lessons we will discuss how to create your own DTD, which will allow you to make your own XML rules. For now we will simply show you how to reference an existing DTD file.

Referencing an External DTD

There are two type declarations that may be used to reference an external DTD: PUBLIC and SYSTEM. When creating an XML document under the rules of a publicly distributed DTD, use PUBLIC. Otherwise, use the SYSTEM type declaration.

The example below shows a prolog that would be used for an HTML document that is using an XML prolog. The DTD is publicly available thanks to the W3C.

XML Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Let's take a look at each piece of this external DTD reference.

!DOCTYPE - Tell the XML processor that this piece of code defines the Document Type Definition html - Specifies the root element of the XML document. Here our example is an HTML file,

which has <html> as the root element. PUBLIC - Specifies that this a publicly available DTD. "-//W3C//D..." - The definition of the public document. Describing this is beyond the scope of

this tutorial. "http://www.w3.org/..." - The physical location of the DTD. Notice how this DTD resides on

w3's servers.

The XML Declaration

This is where you define what version of XML you are using. The current version is 1.0, which it has been for quite some time now. Check out the most recent XML version at w3.org.

<?xml version="1.0"?>

The declaration is not absolutely necessary, but should be included anyways.

XML & DTD Declaration Together

If you were to include both an XML declaration and a DTD declaration on an XML document then you would place the XML declaration first, followed by the DTD declaration. We have done just that in the example below.

<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Be sure to include the optional prolog when you want to run your document through an XML processor to check for validity. If you have a valid DTD, simply use the free markup validation tool at W3C.

XML Namespace

XML was designed to be a very robust markup language that could be used in many different applications. However, with XML being able to communicate between so many different platforms, there is one problem that tends to occur.

XML Element Overlap

When you are creating new elements, there is the chance that the element's name already exists. Imagine someone was creating a health-related XML document that included XHTML (that's HTML that is also valid XML).

XML Code:

<?xml version="1.0" encoding="ISO-8859-15"?><html><body><p>Welcome to my Health Resource</p></body>

<body><height>6ft</height><weight>155 lbs</weight></body>

</html>

Here, we have two very different elements that want to use the same name: body. The solution to this problem is to create XML Namespaces, which will differentiate between these two similarly named elements!

XML Namespace Syntax

The XML namespace is a special type of reserved XML attribute that you place in an XML tag. The reserved attribute is actually more like a prefix that you attach to any namespace you create. This attribute prefix is "xmlns:", which stands for XML NameSpace. The colon is used to separate the prefix from your namespace that you are creating.

As we mentioned in our XML Attribute Lesson, every XML attribute must be set equal to something. xmlns must have a unique value that no other namespace in the document has. What is commonly used is the URI (Uniform Resource Identifier) or the more commonly used URL.

To rectify the overlap in our health XML document, we will be using the W3C's XHTML URL and a made up URI for our second body element. Both the namespace attribute and its use in our document has been highlighted in red.

XML Code:

<?xml version="1.0" encoding="ISO-8859-15"?><html:html xmlns:html='http://www.w3.org/TR/xhtml1/'><html:body><html:p>Welcome to my Health Resource</html:p></html:body>

<health:body xmlns:health='http://www.example.org/health'><health:height>6ft</height><health:weight>155 lbs</weight></health:body>

</html:html>

By placing a namespace prefix before our elements, we have solved the overlapping problem!

XML Documents: Valid Versus Well-Formed

In XML, there are three ways to measure a document's validity: valid, well-formed, and broken. You probably only care that your XML document works, but knowing the requirements for each kind of validity may shed some light on problems that arise in the future.

Well-Formed XML

A well-formed XML document has to follow several rules that most other markup languages also follow. These are generic rules that must be followed for a document to be well-formed, as well as valid. The rules are as follows:

One Root Element - The XML document may only have one root element. See our Root Element Lesson for more information.

Proper Nesting - XML elements must be closed in the order they are opened. See our Nesting Lesson for more information.

Well-Formed Entities - Any entities that are referenced in the document must also be well-formed. See our Entity Lesson for more information.

The first example below is incorrect, and the second is well-formed. Try to figure out the error in the first example.

Broken XML Code:

<email> <to>Mr. Garcia <body>Hello there! How are we today?</to> </body></email>

Well-Formed XML Code:

<email> <to>Mr. Garcia</to> <body>Hello there! How are we today?</body></email>

XSLT - Introduction

XSLT is an XML-related technology that is used to manipulate and transform XML documents. The acronym XSLT stands for Extensible Stylesheet Language Transformations, which is a mouthful to say, but it sounds more complicated than it is.

With XSLT, you can take an XML document and choose the elements and values you want, then generate a new file with your choices. Because of XSLT's ability to change the content of an XML document, XSLT is referred to as the stylesheet for XML.

If you have already heard about HTML and CSS, you know that CSS is a way of styling HTML. In a similar relationship, XSLT is used to style and transform XML.

simple XML document that gets transformed by a complicated looking XSLT file.

XML Code:

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="class.xsl"?><class><student>Jack</student><student>Harry</student><student>Rebecca</student><teacher>Mr. Bean</teacher></class>

XSLT Code:

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

<xsl:template match="teacher"><p><u><xsl:value-of select="."/></u></p>

</xsl:template>

<xsl:template match="student"><p><b><xsl:value-of select="."/></b></p>

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

<html><body><xsl:apply-templates/></body></html>

</xsl:template>

</xsl:stylesheet>

The XML file class.xml is linked to the XSLT code by adding the xml-stylesheet reference. The XSLT code then applies its rules to transform the XML document.

Before XSLT: classoriginal.xml After XSLT rules are applied: class.xml

However, if you were to "view the source" of these XML files in your browser, you would just see the XML document and not the transformed file. XSLT does not change an XML document, but this example shows how XSLT can be used to temporarily manipulate XML.

Below, we have manually reconstructed the XSLT output that you see when you click class.xml. This HTML was created from an XML document bring transformed by our XSLT code.

XSLT Output (What you see in your browser):

<html><body>

<p><b>Jack</b></p><p><b>Harry</b></p><p><b>Rebecca</b></p><p><u>Mr. Bean</u></p>

</body></html>

As you can see, we used XSLT to convert the XML document into a simple webpage. Because we are an internet-related website, all of our XSLT lessons will be focusing on browser ready XSLT output. However, you can pretty much do anything with XSLT!

XSLT - xml-stylesheet

xml-stylesheet is a special declaration in XML for linking XML with stylesheets. Place this after your XML declaration to link your XML file to your XSLT code.

xml-stylesheet has two attributes:

1. type: the type of file being linked to. We will be using the value text/xsl to specify XSLT.2. href: the location of the file. If you saved your XSLT and XML file in the same directory, you can

simply use the XSLT filename.

If you have been following along with this tutorial, your XSLT file should be named class.xsl. Make sure that both your XSLT and XML file are in the same directory.

XML Code:

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="class.xsl"?><class>

<student>Jack</student><student>Harry</student><student>Rebecca</student><teacher>Mr. Bean</teacher>

</class>

Save this XML file as class.xml, and your XML file will be linked to your XSLT file.

Displaying your XML Files with CSS?

It is possible to use CSS to format an XML document.

Below is an example of how to use a CSS style sheet to format an XML document:

The CSS file

CATALOG

{

background-color: #ffffff;

width: 100%;

}

CD

{

display: block;

margin-bottom: 30pt;

margin-left: 0;

}

TITLE

{

color: #FF0000;

font-size: 20pt;

}

ARTIST

{

color: #0000FF;

font-size: 20pt;

}

COUNTRY,PRICE,YEAR,COMPANY

{

display: block;

color: #000000;

margin-left: 20pt;

}

Finally, view: The CD catalog formatted with the CSS file

Below is a fraction of the XML file. The second line links the XML file to the CSS file:

The CD catalog

<?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/css" href="cd_catalog.css"?><CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD></CATALOG>

Formatting XML with CSS is not the most common method.

DSO

DSO is an object that operates like a database on the client side. It will accept information that is organized in a certain way and will manipulate it with its own database engine. Like any object it has an interface with its own properties and methods, and you can manipulate the data stored in the object using these methods. The default behavior of XML DSO is to validate the document and to resolve external entities as the XML document is loaded.

<xml id="equipdet" src="equip.xml" async="false"></xml>

The simple HTML code creates an XML DSO with a DOM object and loads it with the file equip.xml. At the same time this file is loaded, equip.xml is validated and all the external entities are expanded. The async="false" attribute is added to make sure all the XML data is loaded before any other HTML processing takes place.

<?xml version="1.0" encoding="iso-8859-1"?><equipment> <details> <name>Hard Disk</name> <rate>2800</rate> <manufacturer>SeaGate</manufacturer> </details>

<details> <name>Motherboard</name> <rate>10000</rate> <manufacturer>Intel</manufacturer> </details> <details> <name>Monitor</name> <rate>8000</rate> <manufacturer>Samsung</manufacturer> </details> <details> <name>Rajadurai</name> <rate>Tuticorin</rate> <manufacturer>Tamilnad</manufacturer> </details></equipment>

The XML Data Source Object (DSO) is a Microsoft ActiveX control that’s built into Microsoft Internet Explorer 4+. Using this object, it is possible to extract content from an external XML file, or XML data embedded in an HTML file, into an HTML page.

Implementation

We can initialize an XML-DSO object using the <OBJECT> tag. The CLASSID for the XML-DSO is:

CLSID:550dda30-0541-11d2-9ca9-0060b0ec3d39

The above ID uniquely identifies the XML-DSO. And we initialize this control in a Web page as follows:

<OBJECT ID="SomeID" CLASSID="CLSID:550dda30-0541-

11d2-9ca9-0060b0ec3d39"></OBJECT>

Most OBJECTs have a number of parameters associated with them, but the XML-DSO does not require any such parameters.

Now, we can either extract the data from an external XML file, or, we can use XML Data Islands, where we embed XML code in the HTML page itself. Let’s take a look at both these solutions.

Examples

First, we’ll take a look at how to extract data from XML data islands (XML data that’s included in the HTML page itself). Take a look at the following code:

<!-- example1.htm -->

<html>

<head>

<title>XML DSO-example1.htm</title>

</head>

<body bgcolor="#FFFFFF">

<xml id="xmldb">

 <db>

   <member>

     <name>Premshree Pillai<name>

     <sex>male</sex>

   </member>

   <member>

     <name>Vinod</name>

     <sex>male</sex>

   </member>

 </db>

</xml>

<span datasrc="#xmldb" datafld="name"<</span>

<br>

<span datasrc="#xmldb" datafld="sex"></span>

</body>

</html>

The output of the above is:

Premshree Pillai

male

Note that, in the code for example1.htm, we have not initialised an XML-DSO object. Thus, when you use a XML data island, the object is implicitly created.

In the above code, we’ve included an XML data island using the <XML> tag. We have assigned it an ID, xmldb, for use later. Now, we can extract data from the XML data island using HTML tags like <A>, <SPAN>, <DIV> etc. As you can see, we have extracted data here using the <SPAN> tag. Note the attributes datasrc and datafld in the <SPAN> tag. datasrc is used to specify the ID of the data island you want to extract data from. datafld is used to specify the XML tag you want to extract the data from (here, name in first <SPAN> and sex in second <SPAN>).

Note that we have two <name> and <sex> tags in our XML data island, but that, using the above method, we can extract only the first instances of these tags. To extract all instances, we have to use the <TABLE> tag. Take a look at the following example:

<!-- example2.htm -->

<html>

<head>

<title>XML DSO-example2.htm</title>

</head>

<body bgcolor="#FFFFFF">

<xml id="xmldb">

 <db>

   <member>

     <name>Premshree Pillai<name>

     <sex>male</sex>

   </member>

   <member>

     <name>Vinod</name>

     <sex>male</sex>

   </member>

 </db>

</xml>

<table datasrc="#xmldb" border="1">

 <thead>

   <th>Name</th>

   <th>Sex</th>

 </thead>

 <tr>

   <td><div datafld="name"></div></td>

   <td><div datafld="sex"></div></td>

 </tr>

</table>

</body>

</html>

The output of the above is:

Here, we’ve used the <TABLE> tag and extracted the contents using the HTML tag, <DIV>, within the HTML column tag, <TD>. The table will automatically iterate through each instance of <member> (the parent of <name> and <sex>), thus, we can display all the names and ages in a formatted way.

Now, we’ll take a look at how to extract contents from an external XML file using XML-DSO. Consider the following XML file:

<!-- example3.xml -->  

<?xml version="1.0" ?>  

<ticker>  

 <item>  

   <message>JavaScript Ticker using XML DSO</message>  

     <URL>http://someURL.com</URL>  

 </item>  

</ticker>

Now, consider the following HTML page:

<!-- example3.htm -->  

<html>  

<head>  

<title>XML DSO-example3.htm</title>  

<script language="JavaScript">  

function load() {  

 var xmlDso=myXML.XMLDocument;  

 xmlDso.load("example3.xml");  

}  

</script>  

</head>  

<body bgcolor="#FFFFFF" onLoad="load()">  

 

<object id="myXML" CLASSID="clsid:550dda30-0541-11d2-9ca9-  

0060b0ec3d39" width="0" height="0">  

</object>  

 

<table datasrc="#myXML" border="1">  

 <thead>  

   <th>Message</th>  

   <th>URL</th>  

 </thead>  

 <tr>  

   <td><div datafld="message"></div></td>  

   <td><div datafld="URL"></div></td>  

 </tr>  

</table>  

 

</body>  

</html>

The output of the above is:

Observe the code of example3.htm. First, we’ve created a XML-DSO object with id as myXML. Note that we have added the width and height attributes to the <OBJECT> tag and set their values to 0. This is because we want to create an XML-DSO object, but we don’t want it to occupy any space in the Web page

Next, we have created a table with datasrc as myXML, similar to example 2. We have extracted the content using <DIV> tags (within TD tags) with datafld as message for the first column and URL for the second column. The additional code here is the <SCRIPT> we’ve added. As you can see in the script, we’ve set the variable xmlDso to myXML.XMLDocument, which refers to the object we have created. Next, we load example3.xml using the XML-DSO’s load()method. Now the file example3.xml is bound to the object, myXML. Everything else is similar to the previous examples.

Thus, when we want to load an external XML file using XML-DSO, we have to explicitly include the object, as well as a small bit of JavaScript to load the external XML file. The above script is very specific and cannot be used to load just any XML file. A more generic script is as follows:

<script language="JavaScript">  

var xmlDso;  

function load(xmlFile, objName) {  

 eval('xmlDso='+objName+'.XMLDocument');  

 xmlDso.load(xmlFile);  

}  

</script>

And, to load any XML file, use:

load("SomeXMLFile.xml","anyXmlDsoObject");  

XML DSO and JavaScript

It’s also possible to manipulate the XML DSO object using JavaScript. Consider the following XML file:

<!-- example4.xml -->  

<?xml version="1.0" ?>  

<myDB>  

 <member>  

   <name>Premshree Pillai</name>  

     <sex>male</sex>  

 </member>  

 <member>  

   <name>Vinod</name>  

   <sex>male</sex>  

 </member>  

 <member>  

   <name>Santhosh</name>  

   <sex>male</sex>  

 </member>  

</myDB>

Now, consider the following HTML file:

<!-- example4.htm -->  

<html>  

<head>  

<title>XML DSO-example4.htm</title>  

<script language="JavaScript">  

function load() {  

 var xmlDso=myDB.XMLDocument;  

 xmlDso.load("example4.xml");  

 /* Get the complete record set */  

 var memberSet=myDB.recordset;  

 /* Go to next data */  

 memberSet.moveNext();  

}  

</script>  

</head>  

<body bgcolor="#FFFFFF" onLoad="load()">  

<object id="myDB" CLASSID="clsid:550dda30-0541-11d2-9ca9-  

0060b0ec3d39" width="0" height="0">  

</object>  

<span datasrc="#myDB" datafld="name"></span>  

</body>  

</html>Now, the output of the above will be:Vinod

XSLT is a language for transforming XML documents into XHTML documents or to other XML documents.

What is XSLT?

XSLT stands for XSL Transformations XSLT is the most important part of XSL XSLT transforms an XML document into another XML document XSLT uses XPath to navigate in XML documents XSLT is a W3C Recommendation

XSLT = XSL Transformations

XSLT is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by transforming each XML element into an (X)HTML element.

With XSLT you can add/remove elements and attributes to or from the output file. You can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more.

A common way to describe the transformation process is to say that XSLT transforms an XML source-tree into an XML result-tree.

XSLT uses XPath to find information in an XML document. XPath is used to navigate through elements and attributes in XML documents.

In the transformation process, XSLT uses XPath to define parts of the source document that should match one or more predefined templates. When a match is found, XSLT will transform the matching part of the source document into the result document.

An XSL style sheet consists of one or more set of rules that are called templates.

A template contains rules to apply when a specified node is matched.

The <xsl:template> element is used to build templates.

The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document).

The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation:

The <xsl:for-each> element allows you to do looping in XSLT.