Wednesday, July 17, 2013

XSLT Interview Questuions & Answers

1. What os XSLT?
XSLT stands for XSL Transformations. XSLT is a language for transforming XML documents into XHTML documents or to other XML documents.XPath is a language for navigating in XML documents.

2.What is XSLT?

  • XSLT stands for XSL Transformations
  • XSLT is the most important part of XSL
  • XSLT transforms an XML document into another XML document
  • XSLT uses XPath to navigate in XML documents
  • XSLT is a W3C Recommendation.


3.How Does it Work?
In the transformation process, XSLT uses XPath to define parts of the source document that should match one or more predefined templates. When a match is found, XSLT will transform the matching part of the source document into the result document.

4.How you define template in XSLT?
An XSL style sheet consists of one or more set of rules that are called templates.

A template contains rules to apply when a specified node is matched.
The <xsl:template> element is used to build templates.

The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document).

5.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>

6.How to transform an XML into XHTML? 
Below, I write an example which show you how ransform 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>

7.How to use <xsl:sort>element in XSLT?
The <xsl:sort> element is used to sort the output.
To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each> element in the XSL file:
<?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>Title</th>
      <th>Artist</th>
    </tr>
    <xsl:for-each select="catalog/cd">
      <xsl:sort select="artist"/>
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

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

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

10.What is the function of XSLT?

  •  XSLT is the transformation language used for XML documents and it performs high level of functions.
  • XSLT provides a way to solve the complex problems like styling and the operations related to the generation of table and its contents. 
  • It also provides the support for the indexes and other processing languages that can be integrated with one another. 
  • The transformation language is used to provide XSL to generate the HTML pages using the XML data. 
  • It defines the semantics and syntax using the XSLT language and expresses the XML document in a well formed manner.

11.What are the specifications defined in XSLT?

  • -The specifications are defined using the syntax and semantics of XSLT language and uses the namespace fundamentals of XML.
  • XML names can include both the elements that are defined using the XSLT and those that are not defined. 
  •  XSLT defines the parameters and XML namespace that can be used to refer the syntax and semantics of XSLT namespace. 
  • The semantics that are used with XSLT namespace need to be defined in the correct order. 
  • It provides the syntax for all the specifications that needs to be written and allow the user to use the elements given.

12.What are the rules defined by the transformation of XSL?
 The transformation of XSL provides the XSLT that describes the rules to define the transformation of the source tree into result tree.

  • It also provides the pattern that is associated with the templates and also with the structure of it. 
  • It uses the templates that allow the creation of the result tree by using the modification made in source tree. 
  • The transformation is described in the rules for transforming the pattern templates according to the requirement. 
  • The pattern is made against the elements and it is matched using the source tree and with other elements.


13.What are the steps in the instantiation of a template?

  • The template can be instantiated using the source element of the tree and it can create some part of the result tree. 
  • The template can consist of elements using the XSLT namespace that provides the instructions for creating the fragments. 
  • After the template instantiation the instructions are executed using the tree fragments. 
  • The instructions are processed and it is descendant of the source elements that consists under the source tree.
  • Processing the elements in the source tree creates a result tree fragment on which template rule can be applied.

14.What is the stylesheet structure used with XSLT?

  • XSLT uses the namespaces that provide the recognition for the elements for the use in the stylesheet.
  • XSLT uses the elements that get recognized using the stylesheet not the source document that is used.
  • The list of XSLT defined elements are used in the category of B elements and it is not extended using the additional elements or attributes. 
  • The extensions that are used provide the separate namespace used for additional instruction elements.
  • The structure must have identification for the element mechanism that is specified in the elements.

15.How important is an element’s attributes used in XSLT?

  •  Elements are the core part of XSLT namespace as it uses an attribute with the elements. 
  • XSLT provide the expanded name to be given using the non-null namespace URI that can be used in the namespace. 
  • The attributes are present to change the behaviour of XSLT element and functions that gets defined in XML documents. 
  • XSLT processor is used to process the attributes and provide the recognition for the namespace URI.
  •  The attribute provide unique identifier or optimization hints in the documents so that they can be used.

16.What are the different elements contain in xsl:stylesheet?

  • xsl:stylesheet is an element container that consists of the following types of elements:
  • xsl:import: this is used to import the file from one place to another by using the command. 
  • xsl:include: this includes the libraries and the functions used in XSLT stylesheet language. 
  • xsl:strip-space: this is used to strip the additional space provided by the whitespaces, etc. 
  •  xsl:output: this represents the output of the input that is being provided to the XSLT. 
  •  xsl:key: this consists of the key that is used to open the protected files and documents. 
  •  xsl:template: this is used to provide the template that can be included using the command.

17.Write a program to show the element is occurring as a child?

  • The element can be used as a child when it is used in xsl:stylesheet element that is the top-level element.
  • The element structure is made in a hierarchical fashion so that it is easy to implement it. 
  • Ellipses (...) are used to indicate that attribute values or content for the use of creating files.
  • The program is written as follows:
  • <xsl:stylesheet version="1.0 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="..."/>
<xsl:include href="..."/>
<xsl:strip-space elements="..."/>
<xsl:variable name="...">...</xsl:variable>
<xsl:param name="...">...</xsl:param>
<xsl:template match="...">...</xsl:template>
<xsl:template name="...">...</xsl:template>
</xsl:stylesheet>

18.What happens about the presence of the top-level element?

  •  The top-level elements don’t have any effect on the behaviour of XSLT elements. 
  •  The functions that are defined with it also don’t have any affect in the document. 
  •  The top-level elements are not permitted to be used by specifying the xsl:apply templates. 
  •  XSLT process is provided to ignore the top-level elements and ignore some of it if an error occurs.
  •  XSLT top-element element doesn’t recognize the namespace URI and can be provided using other sources.

19.What is provided by the elements that don’t recognize the namespace URI?

  • The elements that doesn’t recognize the namespace URI provides features like:
  • The information, which is used by the extension, element or function and implemented it in an application. 
  • The information is provided regarding the work that needs to be done on the source tree.
  • The information is being provided regarding the output that needs to generate using the result tree. The metadata that needs to be gathered using the stylesheet with proper keywords and other search results.
  • The documents need to be clear and structured for the stylesheets and for its use.
20.Write a program to show Literal Result Element as Stylesheet?

  • The stylesheets consist of a single template that can be considered for the root node. 
  • The stylesheet can also consist of the literal result element that provides the output of the search made for a particular element. 
  • The stylesheet is equivalent to the stylesheet being made using the xsl:stylesheet element that consists of the template rule and the element.
  • The template rule describes to have a pattern match for the root node and the displaying properties of it. 


<html xsl:version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/strict">
<head>
<title>Hello world</title>
</head>
<body>
<p>Hello: <xsl:value-of select="world/total"/></p>
</body>
</html>

No comments:

Post a Comment