XSLT Interview Questions & Answers

4 avg. rating (80% score) - 1 votes

XSLT Interview Questions & Answers

Looking for XSLT job interview questions and answers? Need interview questions to answer well for the recruiter questions. XSLT is the most demanding job role in the current job market. Finding job is easy in the current job market but winning job interview is tough task as it involves more preparation and analysis of the skillset on which you are applying for the jobs. Wisdomjobs has made this task simpler with our XSLT job interview questions and answers page. XSLT is a language for changing XML documents into other XML documents, or different formats, for example, HTML for web pages, plain content or XSL Formatting Objects, which may in this manner be changed over to different formats, for example, PDF, PostScript and PNG.

XSLT Interview Questions

XSLT Interview Questions
    1. Question 1. What Is Xslt Data Model?

      Answer :

      XSLT shares the same data model of XPATH with some additions. XSLT accepts a XSLT stylesheet as an input and output is another XML, text or another document. The model is based on text nodes. These text nodes are embedded within element nodes.

      The model is a hierarchical structure like a tree. The tree has a variety of nodes like- text nodes, attribute nodes, element nodes, comment nodes, and processing instruction nodes. For every node type there is a way of determining a string-value for a node of that type.

    2. Question 2. Explain The Role Of Xpath?

      Answer :

      XPATH is used to scan the XML document for navigation of elements and attributes. It contains a library of standard functions string ad numeric values. For navigation, XPATH makes use of path expressions to select nodes or sets of nodes in a XML document.

    3. Question 3. What Is Xslt Stylesheet?

      Answer :

      XSL stylesheet is just like a XML document used as a program text or a source. It contains sets of rules and instructions used for transformations. XSLT stylesheet along with the XML source documents are the inputs to the XSLT processor.

      The template rule contains two parts: a pattern used to match the nodes in the source document and a template which can be instantiated to form part of the result tree.

      A stylesheet is represented by an xsl:stylesheet element in an XML document.

    4. Question 4. Explain Its Relationships Of Xslt With Xsl?

      Answer :

      XSLT stands for eXtensible Stylesheet Language Transformations. It is a language used to convert XML documents to XHTML or other XML documents. This conversion is done by transforming each XML element into an (X)HTML element..

      it uses XPath to find information in a XML document. XSLT is nothing but transforming XSL's. Xpath defines the parts of the source document that must match one or more predefined templates. Once a match is found, XSLT will transform the match into the result document.

    5. Question 5. Do You Know What Are The Roles Of Xslt?

      Answer :

      The roles of XSLT are:

      1. XSLT is used to transform an XML document into another XML document such as HTML, etc.
      2. XSLT can be used to add or remove elements and attributes to or from the output file.
      3. XSLT can also be used for rearranging and sorting elements.
      4. It can also be used for performing tests and making decisions about hiding and displaying of elements.

    6. Question 6. What Is Xslt?

      Answer :

      XSLT stands for XSL Transformations and is a language used to transform XML documents into XHTML documents or to other XML documents.

    7. Question 7. Do You Know How To Transform An Xml File Into Html Using Xsl Transformation (xslt)?

      Answer :

      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.

    8. Question 8. How To Generate Dynamic Html Pages From Relational Database Using Xslt?

      Answer :

      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.

    9. Question 9. Explain How To Retrieve Value Of An Attribute For An Element Using Xslt?

      Answer :

      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>

    10. Question 10. 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?

      Answer :

      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.

    11. Question 11. Tell Me What Is Identity Template In Xsl, Why Do You Use It?

      Answer :

      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.

    12. Question 12. Explain How To Rename A Particular Element And Attribute From Xml Using Xsl?

      Answer :

      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=".">

    13. Question 13. Explain How To Remove A Particular Attribute From Xml?

      Answer :

      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"/>

    14. Question 14. Explain How To Remove A Particular Element From Xml?

      Answer :

      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"/>

    15. Question 15. How To Perform Xml Transformation In Java?

      Answer :

      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.

    16. Question 16. How To Use Filtering Function In Xslt?

      Answer :

      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>

    17. Question 17. How We Compare Xslt And Xpath?

      Answer :

      Some comparison b/w XSLT and XPath and given below:

      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.

      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.

    18. Question 18. How To Transform An Xml Document Into Another Xml Document?

      Answer :

      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>

    19. Question 19. How To Transform An Xml Into Xhtml?

      Answer :

      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>

    20. Question 20. How You Define Template In Xslt?

      Answer :

      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>

    21. Question 21. How To Use <xsl:sort>element In Xslt?

      Answer :

      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>

    22. Question 22. How To Use Filtering In Xslt?

      Answer :

      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>

    23. Question 23. What Is The Xslt?

      Answer :

      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.

    24. Question 24. Who Developed Xslt?

      Answer :

      It was developed by World Wide Web consortium.

    25. Question 25. What Does Xslt Processing Models Involve?

      Answer :

      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.

    26. Question 26. Can You Use The Xslt To Convert Html Into Vxml?

      Answer :

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

    27. Question 27. Which Was The First Processor Related To Xslt?

      Answer :

      James Clark's XT was the first processor.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

XML DOM Tutorial