What is XSLT in XML? - Example & Functions

Instructor: Lonny Meinecke

Lonny teaches psychology classes at King University, and has a bachelor's degree in IT and a doctorate in psychology.

This lesson will introduce something called XSLT, which is used with XML to help make web pages look more interesting. The lesson will describe XSLT, provide an example, and explain a few of its functions.

What is XSLT?

The best way to describe XSLT is to call it a way to add some style to the plain old text that XML files are composed of, whenever we want to look at them. (XML by itself isn't very pretty.) What's an XML file, you ask? Well, the best way to describe XML is to call it a way to put information (of almost any kind) into documents so that we can exchange them with somebody else. You see, XML is a nice way to pass information around on the internet, because others can understand that information even if they don't know anything about it. Unfortunately, even if it's understandable, XML just isn't pretty. That's why XSLT comes to the rescue.

A Brief History of Style

Once upon a time, web pages were really, really boring. They were single screens full of text - all one size, and all one font. There were no pictures, no videos, no sounds, not even much in the way of nicely formatted tables. Along came a few forward-thinkers like AOL and CompuServe, and that text started to look a little less boring. But those solutions were anything but universal, and we needed something universal. Ted Nelson brought hyperlinks to text with Xanadu, and Douglas Engelbart invented a mouse so we could click on them. But it was still pretty boring no matter what you clicked on.

The first World Wide Web page
world-wide-web page

Some folks at CERN (yes, that famous place in Switzerland that smashes atoms into little pieces), gave us the World Wide Web, and made it free to share. Next thing you know, that plain old text was colorful, diverse, and anything but boring. (Letting people all over the world do stuff freely seems to have that effect!) HTML was born, which is a way to write web pages and add S-T-Y-L-E.

Along came XML (a way to exchange information using tags), and we were back to square one. It's not HTML anymore, so how do you add style to XML? The XML decorator cavalry rode in as XPath (a way to navigate XML) and brought the XSL style wagons with it. The result -- XSLT -- lets us decorate the boring text between the tags of an XML file and dress up the way those pages will look.

By the way, the World Wide Web Consortium (W3C) brought us XSL, which stands for eXtensible Stylesheet Language. With it came XSLT, which means XSL Transformations (a way to blend XML, XPath and XSL, and render a pretty page). Got it? XML is about content, and XSL has style, but XSLT is the interior decorator that puts the two together with some real class.

Example of XSLT

As we have seen, XSLT works by combining content (XML) with a stylesheet (XSL). Here is an example of that. This first file is a simple XML file called 'bookcase.xml' that lists the two books in our bookcase. (Yes, our books are few, but we have class in our choice of those two books!) All this file contains is just the title and author of those two books.

Example XML file
xml example

Now, we present an example of XSLT. This is an XSL file that will help us display our two books in a nice table. We won't go into everything here, but we will explain a few of these functions in the next section.

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create An Account