xml xslt example


I am trying below example


books.xml looks like

<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>

XSLT file looks like

<!DOCTYPE html>

function loadXMLDoc(dname)
if (window.XMLHttpRequest)
  xhttp=new XMLHttpRequest();
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
try {xhttp.responseType="msxml-document"} catch(err) {} // Helping IE
return xhttp;

var x=loadXMLDoc("books.xml");
var xml=x.responseXML;

// code for IE
if (window.ActiveXObject || xhttp.responseType=="msxml-document")
for (i=0;i<nodes.length;i++)

// code for Chrome, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();

while (result)


Open in new window

I am expected to see output like


what is the extension of the xpath i supposed to give.

How can i run this example myselef on my windows laptop machine with or without eclipse. Please advise.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The code you posted is not XSLT. But if you want to get the price you will need to change the xpath expression to


instead of

gudii9Author Commented:
The code you posted is not XSLT.

Is that is XPATH? what is the extension i supposed to give?
book.xml and then book.xpath would be file names of the xml and xpath files?

How do i run this example say using eclipse
Yes, the correct term is xpath. I don't know how to run it, it's using some active x objects, so I guess through IE.
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

The example is an HTML document (as others have already commented).  It is using two files that MUST reside on the server.
books.html - The HTML document that drives the processing
bookx.xml - The XML data document

If you just try to open the files on the local file system, the javascript engine will crash with an access denied (it is a security violation to be able to access local files).

The line: xhttp.open("GET",dname,false); is the line that loads the XML document into memory.  The open() function is used to generate a HTTP request to retrieve the contents of the URL stored in 'dname'

To run the HTML locally, you will need to setup a HTTP server that will run under localhost.  The server can be any one of the following:
IIS - Web server that can be installed on Windows
Apache - Web server that can be installed on any OS (Windows, OSX, Linux...)

My recommendation is that you install Apache.  Since that works better with eclipse.
gudii9Author Commented:
I have apache tomcat integrated with eclipse. Just create regular java project and copy above xml and xslt to default package and run the xml like 'run as server' which talks to xslt and displays the html by applying styles?
please advise
As many people has already stated.  it is not xslt.  The file is a HTML file. To create the same in eclipse, create a new Project of type 'Static Web Project'.  The project should look like this:
Once the files are created, right click on the project and choose run as->Run on Server

On the browser window, navigate to the http://localhost:8080/Books/books.html (it will default to http://localhost:8080/Books/ with will generate an error).
gudii9Author Commented:
I got output as

So it is html file only not sxlt file.
what is dname and xmlhttprequest, ActivexObject and different code for different browser.
what is relationship between xslt and xpath. since in this example they did not use xslt at all but still they used xmpath(within html itself)
Please advise
There are multiple technologies in the example (and none of them is xslt).  XSLT is a language for transforming XML files the output of the XSLT transform can be another XML file or in some cases other formats (plain text, html, CSV...).  For a description of this language you can look at the wikipedia page.

For the technologies used in the example they are as follows:
XMLHttpRequest - Javascript API for creating dynamic requests (used in AJAX)
ActiveXObject - Technology used by Internet Explorer to run native code in browser
Microsoft.XMLHTTP - dynamic request component for creating dynamic requests in IE5.5 and IE6 (IE7-IE11 can use XMLHttpRequest)
XPATH - Query language for querying and navigating XML documents.  XPATH is a component of many languages and API's (XSLT, Java, C#,  Javascript)
Dynamic HTML - technique for creating HTML content at "runtime" (it is used in AJAX as well)

All of the links are from the wikipedia pages on each subject.  I am sure there are better tutorials for each of the technologies.  I supplied the links so you can get more general information if you desire.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.