1. What is the XSLT?

XSLT stands for Extensible Stylesheet Language Transformations(XSLT).This is developed by World Wide Web Consortium(W3C).This is written in XML.We use XSLT when we want to transform an XML document into the oter XML document.Generally we use XSLT when we want to make transformation from a XML document into another XML document,Convert a XML document into the HTML or XHTML document, creating dynamic web pages, can convert an XML document into PDF document. We saved the XSLT file by using .xsl or .xslt extension.Recent version of XSLT is XSLT2.0 launched at 23rd Jan 2007.It is a part of XSL.Editor od first version of XSLT are James Clark.

2. Who developed XSLT?

It was developed by World Wide Web consortium.

3. What does XSLT processing models involve?

As far as the XSLT processing model is concerned it involves one or more XML documents as well as one ore more XSLT style sheet modules. It also requires XSLT template processing engine (the processor) as well as one or more result documents.

4. Can you use the XSLT to convert html into VXML?

Yes, we can definitely use the XSLT to convert the html into VXML.

5. Do you feel that you are a good XSLT programmer?

This is definitely a very tricky question. You might be quite confused while answering to this question. Hence you should practice to answer this as well as similar questions at your home. Go for the interview only when you are hundred percent sure that you are ready for the interview.

6. Which was the first processor related to XSLT?

James Clark's XT was the first processor.

7. Do you feel that you have chosen the right technology XSLT?

Yes, I have definitely chosen the right technology. The XSLT has a very bright future as the entire expert team feels.

8. Are you ready to relocate?

Yes why not! If I will get a good opportunity then I am definitely ready to relocate.

9. How to use filtering in XSLT?

We can filter the XNL output by using filter operators.Some Legal filter operators are given below:
1.=(equal to)
2.!=(not equal to)
3.<(less than)
4.>(greater than)
I have given you a example. In this I have uses '=' equal to filer operation.

<?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>Book Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Author</th>
</tr>
<xsl:for-each select="catalog/book[author='Jhon Smith']">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

10. How to use <xsl:sort>element in XSLT?

We use <xsl:sort> element to sort the given output.
Example:
<?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>Book Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Author</th>
</tr>
<xsl:for-each select="catalog/book">
<xsl:sort select="author"/>
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:styleshee

Download Interview PDF

11. How you define template in XSLT?

When XSL style sheet has one or more set of rules are told as templates.
We used <xsl:template> element to create templates.
We can attach a template with an XML document by using match attribute.The match attribute value is an XPath exprssion.Like: match="/" use to define whole document.
Example:
<?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> Book Collection </h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Author</th>
</tr>
<tr>
<td>.</td>
<td>.</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

12. How to transform an XML into XHTML?

Below, I write an example which show you how transform an XML into XHTML.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html"/>
<xsl:template match="/persons">
<html>
<head>
<title>Test an XML Example</title>
</head>
<body>
<h1>Persons</h1>
<ul>
<xsl:apply-templates select="person">
<xsl:sort select="family-name" />
</xsl:apply-templates>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="person">
<li>
<xsl:value-of select="family-name"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="name"/>
</li>
</xsl:template>
</xsl:stylesheet>
To get output on the XHTML we write like that,

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <title>Test an XML Example</title> </head>
<body>
<h1>Persons</h1>
<ul>
<li>gupta, Abhi</li>
<li>jain, sudi</li>
</ul>
</body>
</html>

13. How to transform an XML document into another XML document?

Here,I given you a exampl which show you how to transform an XML document into another XML document.
Example:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/persons">
<root> <xsl:apply-templates select="person"/> </root>
</xsl:template>
<xsl:template match="person">
<name username="{@username}">
<xsl:value-of select="name" />
</name>
</xsl:template>
</xsl:stylesheet>
We can tranform above XML document into another document like that,
<?xml version="1.0" encoding="UTF-8"?>
<root>
<name username="jhoh">jhon</name>
<name username="smith">smith</name>
</root>

14. How we compare XSLT and XPath?

Some comparison b/w XSLT and XPath and given below:<br>1.XSLT is depends upon W3C XPath language.Which is use to identify subset of source document tree. XPath is also used to provide the function range.<br>2.Both XSLT and XPath published at same time than we can say that XSLT2.0 trusts on XPath2.0 and XSLT1.0 trusts on XPath1.0.

15. How to use filtering function in XSLT?

We can filter the XNL output by using filter operators.Some Legal filter operators are given below:
1.=(equal to)
2.!=(not equal to)
3.<(less than)
4.>(greater than)
I have given you a example. In this I have uses '=' equal to filer operation.

<?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>Book Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Author</th

16. How to perform XML transformation in Java?

XSL transformation is the process of transforming one XML file into another XML, HTML or other type of file based upon selective rules and condition. XSL(XML Style Sheet language) is used to define those rules and condition in a .xls file, which is called style sheet document. Any XSLT engine can read those instruction defined in style sheet document and transform source XML file into something expected. Core of XSLT is, transformation engine and style sheet document. XSLT engine can be written in Java or any other language. Java has XSLT support via javax.xml.transform package which specifies classes like Templates, TransformFactory, an implementation of abstract factory design pattern, which can be used to read XSL file and transform XML files.

17. Explain how to remove a particular element from XML?

Removing element from XML document via XSL transformation or XSLT is easy if you are familiar with Identity template. You need to write two templates one is Identity template, which copies every thing and other for matching with particular element and doing nothing just like shown below, which will then result in removal of a that particular element. See an example of removing XML elements using XSLT for details.

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

18. Explain how to remove a particular attribute from XML?

Process of removing an attribute is similar to removing elements from XML document, as discussed in above XSLT interview question. Along with Identity template, define another template to match with that particular attribute as shown below.

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

19. Explain how to rename a particular element and attribute from XML using XSL?

Renaming attribute is also similar to removing or deleting attribute as discussed in XSLT question 1, but instead of not doing anything when an attribute matches, you need to create an attribute and copy value of current attribute into new attribute. Identity template will be same and you need to add another template for renaming attribute using XSL:

<xsl:template match="@id">
<xsl:attribute name="emp_id">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>

if you are using XSLT 2.0 than instead of separate <xsL:value-of> element you can use select attribute directly with <xsL:attribute> as shown below

<xsl:attribute name="emp_id" select=".">

20. Tell me what is Identity template in XSL, why do you use it?

Identity template in XSL is used to create deep copy of source XML file. It's template matches to every node() and attribute and copy everything to create copy of original xml file. many people define Identity template in its own file like Identity.xsl but some people also preferred to keep in main XSL file as top template. Identity template has several uses in XSL transformation, like if you want to remove any attribute or element you will most likely copy everything using Identity template and create another template for not doing anything for those attribute or elements.

<xsl:template match="@|node()">
<xsl:copy>
<xsl:apply-templates select="@|node()"/>
</xsl:copy>
</xsl:template>

Above template is called Identity template. If you look at definition first template matches any attribute or
any node and then copies current node including any attributes and child nodes.

21. Do you know why we use select="@|node()" in the <xsl:apply-templates/> element on Identity template? What will happen if we use <xsl:apply-templates/> without select attribute?

This is an extension or follow up questions of previous XSLT question about Identity template. we use select="@|node() to copy all child element and any attribute.if we don't use that than <xsl:apply-templates/> will default on select="node()" which will copy child nodes except attributes.

22. What is XSL template? What output this XSL template will produce given a particular xml file?

This kind of XSL transformation questions are more popular to gauge real understanding of templates. they can write template in front of you and may ask you to explain, most simple example of this is writing Identity template as discussed in XSLT interview question
Alternatively they may give you XSL and XML file and ask you about about of transformation. This are tricky questions in XSL and in order to answer these question you need to be familiar with XSL language, which is the primary reason people ask it. On the other hand this is an excellent opportunity to show you how well you know about XSL working or how template executes, by clearly explaining what a particular template does.

23. Explain how to retrieve value of an attribute for an element using XSLT?

This XSLT interview question is pretty common in many XML interviews as well. If candidate has worked in XSLT then this is a fairly easy question as it just need to come up with a XSLT template which can copy an attribute from an element like below:

<xsl:template match="/employees/employee">
Value of attribute Id is :
<xsl:value-of select="@id"></xsl:value-of>
</xsl:template>

24. How to generate dynamic HTML pages from relational database using XSLT?

This is one of the XSLT interview questions which checks practical knowledge of candidate in XSL. This is one of the most common application of XSLT I have seen where data stored in relational database is converted into XML and by using XSLT transformed into HTML pages. Database stored procedure can be used for first part and having all the logic of rendering HTML in XSLT you don't need to change your query now and then if you need to change structure of HTML pages. If candidate successfully answer this XSLT interview question then there is very good chance that he has a good understanding of how things works with database, xml and XSLT.

Now let's see couple of XSLT Interview question for practice, you need to find answer of these two questions by yourself, and once you find the answer, you can also post them as comment here. The reason, I am not giving answer of these question here because, they are extremely basic and should come as experience, i.e. you would better write code for that. That will enable you to understand other XSLT questions as well.

Download Interview PDF

25. Do you know how to transform an XML file into HTML using XSL transformation (XSLT)?

That's all on my list of XSLT and XML transformation interview questions and answers. XSLT is one of the important skill to have in your resume, if you are using XML in your project. Since XML is mostly used as transportation protocol and middle and back office systems, those roles look for candidates which are good in XML, XSL and XSLT transformation. So if you are applying for any middle and back office Java development role in Investment banks, make sure to prepare XSLT well.