Archive

Posts Tagged ‘XML’

XML+XSLT=(xHTML,HTML,pdf etc.,)


XSL: XML Style-Sheet Language

XML is mainly used to give a raw XML file to give some shape. By including one stylesheet tag to XML file we can give much nicer look.

<?xml-stylesheet type=”text/xsl” href=”profile.xsl”?>

The above tag adds all the styles defined in the profile.xsl to the xml in which is written.

XSLT: XML Style-Sheet Language Transformation

Basically XML is not much human interactive so it is very much needed to transform xml to human interactive file like HTML or XHTML or pdf etc.,

Why XSLT only?

We can use any programming languages like C, C++, Java or Python etc., to transform XML file content to interactive representation in the form of html, xhtml or pdf etc., but the XSLT was written to be light weight and very easy to do the transformation.  It is a w3 standard.

XSLT Engine:

There are two different ways of transformation one is at the client side and the other is at the server side. When we want to do the transformation at the client side browser(Both xml and xsl files have to sent to the client’s browser). In this method the client  must have the XSLT engine installed but we cannot guarantee that. Hence forth we go for much promising method of transforming the file at the server side itself and sending that file to the client browser.

There are many XSLT engines, among them some I’m mentioning below, you can also download them

Saxon

MSXML

AltovaXML

I’ve worked with the Saxon which is an open source XSLT engine. We can download the jar file, after downloading the jar file we have to use the below command to apply style to the xml file.

Java –jar saxon9he.jar –s:profile.xml –xsl:profile.xsl –o:profile.xhtml

In the above command you can replace the source files profile.xml and profile.xsl with your own source xml and xsl files. The output profile.xhtml signifies with which name you want to create the output file

Here is an example transformation:

XML File(profile.xml)

<?xml version=”1.0″?>

<?xml-stylesheet type=”text/xsl” href=”profile.xsl”?>

<Profile>

<Name>Chittampally Vasanth Raja</Name>

<RollNo>10IT05F</RollNo>

<PhoneNo>+91 9999999999</PhoneNo>

<Email>abcdef@gmail.com</Email>

<CollegeAddress> NITK Surathkal</CollegeAddress>

<PermanentAddress>  Andhrapradesh </PermanentAddress>

<Interests>Learning New Technolgy</Interests>

<Hobbies>Blogging</Hobbies>

<AboutMe>hard working, enthusiastic, sociable, cheerful, optimistic and always willing to learn new thing</AboutMe>

<Image>10IT05F.png</Image>

</Profile>

XSL File:(Profile.xsl)

<?xml version=”1.0″?>

<xsl:stylesheet

version=”1.0″

xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;

<xsl:output method=”xml”

doctype-system=”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;

doctype-public=”-//W3C//DTD XHTML 1.0 Transitional//EN” indent=”yes”/>

<xsl:template match=”/”>

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<title>Profile Page</title>

<body bgcolor=”#FAFAD2″>

<table align=”center” width=”100%” >

<table border=”1″ align=”center”>

<tr>

<th colspan=”3″ bgcolor=”#9acd32″>Profile </th>

</tr>

<tr>

<td>Name</td>

<td><xsl:value-of select=”Profile/Name”/></td>

<td rowspan=”9″><xsl:text disable-output-escaping=”yes”>&lt;img src=”</xsl:text><xsl:value-of select=”Profile/Image” />” alt=”Vasanth Raja photograph <xsl:text disable-output-escaping=”yes”>” /&gt;</xsl:text>

</td>

</tr>

<tr>

<td>Roll Number</td>

<td><xsl:value-of select=”Profile/RollNo” /></td>

</tr>

<tr>

<td>Phone Number</td>

<td><xsl:value-of select=”Profile/PhoneNo” /></td>

</tr>

<tr>

<td>Email</td>

<td><xsl:value-of select=”Profile/Email” /> </td>

</tr>

<tr>

<td>College Address</td>

<td>

<table>

<tr>

<td><xsl:value-of select=”Profile/CollegeAddress/RoomNo”/></td>

</tr>

<tr>

<td><xsl:value-of select=”Profile/CollegeAddress/Hostel”/> </td>

</tr>

<tr>

<td><xsl:value-of select=”Profile/CollegeAddress/College”/></td>

</tr>

</table>

</td>

</tr>

<tr>

<td>Permanent Address</td>

<td><table>

<tr>

<td>House No:</td>

<td> <xsl:value-of select=”Profile/PermanentAddress/H.No”/></td>

</tr>

<tr>

<td>Town:</td>

<td><xsl:value-of select=”Profile/PermanentAddress/Town” /></td>

</tr>

<tr>

<td>District:</td>

<td><xsl:value-of select=”Profile/PermanentAddress/Dist” /></td>

</tr>

<tr>

<td>State:</td>

<td><xsl:value-of select=”Profile/PermanentAddress/State” /></td>

</tr>

<tr>

<td>Pin Code:</td>

<td><xsl:value-of select=”Profile/PermanentAddress/Pin” /></td>

</tr>

</table>

</td>

</tr>

<tr>

<td>Interests</td>

<td><xsl:value-of select=”Profile/Interests”/></td>

</tr>

<tr>

<td>Hobbies</td>

<td><xsl:value-of select=”Profile/Hobbies”/></td>

</tr>

<tr>

<td>About Me</td>

<td><xsl:value-of select=”Profile/AboutMe”/></td>

</tr>

</table>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

Advertisements

My first video ever I uploaded to Youtube!!


This is the first video which I’ve ever uploaded to Youtube. This video gives brief idea about the various technologies, XML, XHTML,XSL, XSLT, XSD, Schema, DTD, Validation, Stylesheets (CSS)., RSS, DOM which constitute a very complex web sites.