top of page

What is XML?

 

So, what is XML? Whenever a group of people asks this question, I always look at the individuals’ body language. A significant portion of the group leans forward eagerly, wanting to learn more. The others either roll their eyes in anticipation of hype and half-formed theories, or cringe in fear of a long, dry history of markup languages. As a result, I’ve learned to keep my explanation brief.

 

The essence of XML is in its name: Extensible Markup Language.

 

Extensible

 

XML is extensible. It lets you define your own tags, the order in which they occur, and how they should be processed or displayed. Another way to think about extensibility is to consider that XML allows all of us to extend our notion of what a document is: it can be a file that lives on a file server, or it can be a transient piece of data that flows between two computer systems (as in the case of Web Services).

 

Markup

 

The most recognizable feature of XML is its tags, or elements (to be more accurate). In fact, the elements you’ll create in XML will be very similar to the elements you’ve already been creating in your HTML documents. However, XML allows you to define your own set of tags.

 

Language

 

XML is a language that’s very similar to HTML. It’s much more flexible than HTML because it allows you to create your own custom tags. However, it’s important to realize that XML is not just a language. XML is a meta-language: a language that allows us to create or define other languages. For example, with XML we can create other languages, such as RSS, MathML (a mathematical markup language), and even tools like XSLT. More on this later.

XSLT

eXtensible Stylesheet Language Transformations(XSLT)

  • XSLT can be used to tansform XML files to different types like pdf, doc, xml, HTML etc. 

  • We can perform a lot of operations in XSLT which profides predefined operations(Eg: sorting). 

  • http://www.w3.org/TR/xslt

  • xsltproc is a unix package that can be used to test xslt

 

They contain <xsl:stylesheet> as root tag. They also contain <xsl:template> tags(one or more)

Templates are matched to XML tags in the source data. The template content replaces the source XML after transformation. 

 

XML Document

XSLT Document

XSLT Transformation Engine

Result Document

Commonly used XSLT Elements 

<xsl:stylesheet>

<xsl:template match="xpath expression">

<xsl:value-of select="xpath">

<xsl:attribute>

<xsl:text>

<xsl:for-each select="xpath">

<xsl:if test="condition">

<xsl:choose>

<xsl:when>

<xsl:otherwise>

 

 

Sample XSLT Template

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

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

 

<xsl:template match="/">

  <html>

  <body>

  <h2>My CD Collection</h2>

    <table border="1">

      <tr bgcolor="#9acd32">

        <th style="text-align:left">Title</th>

        <th style="text-align:left">Artist</th>

        <th style="text-align:left">Country</th>

      </tr>

      <xsl:for-each select="catalog/cd">

      <tr>

        <td><xsl:value-of select="title"/></td>

        <td><xsl:value-of select="artist"/></td>

        <td><xsl:value-of select="country"/></td>

      </tr>

      </xsl:for-each>

    </table>

  </body>

  </html>

</xsl:template>

</xsl:stylesheet>

 

Let us use online tool to work on XSLT examples.

 

http://www.xpathtester.com/xslt

 

Let us test the below XML file and the XSLT file.

 

Example1

 

XML File

<?xml version="1.0"?>

<SampleString>

   Welcome to XSLT!

</SimpleString>

 

XSLT File

 

 

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

version="1.0">

<xsl:template match="/SampleString">

<html>

<head>

<title>Hi XSLT!</title>

</head>

<body>

<h1>

<xsl:value-of select="text()"/>

</h1>

</body>

</html>

</xsl:template>

<xsl:value-of select="text()" />

</xsl:stylesheet>

 

Output

 

<html>

<head>

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Hi XSLT!</title>

</head>

<body>

<h1>

   Welcome to XSLT!

</h1>

</body>

</html>

 

 

 

 

bottom of page