|
Totel:15 Click:
1 2 3
XSLT Interview Questions And Answers
Page 1
Questions 1 How you define functions in XSLT?
Answer XSLT has more than 100 build-in functions.This functions are made for string values,date and time comparison,numeric values,sequence manipulation, Node and QName and boolean variable etc.
We can find out the XSLT function namespace from
http://www.w3.org/2005/02/xpath-functions
I have given you some XSLT build-in functions.
current(),document(),element-variable(),function-variable(),key,gererated-id() etc.
Questions 2 How to use <xsl:apply-template> element in XSLT?
Answer Using <xsl:apply-template>element we can apply a template on current element or can apply on the child nodes of current element.
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>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="book">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="author"/>
</p>
</xsl:template>
<xsl:template match="title">
Title: <span style="color:#ff0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
<xsl:template match="author">
Author: <span style="color:#00ff00">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
Questions 3 Give an example of XSL file with choose condition?
Answer Using choose conditon in XSL file we can add some multi conditional test cases.
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">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price > 150">
<td bgcolor="#ff00ff">
<xsl:value-of select="author"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="author"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
In the above program we display those entries of Author column with pink color WHEN book price is higher than 150.
Questions 4 How to use <xsl:choose> element inXSLT?
Answer When we want to use <xsl:choose> element in XSL file.Than we use <xsl:when> and<xsl:otherwise> inside the <xsl:choose> element.Using them we can show multiple conditional test cases.
Syntax:
<xsl:choose>
<xsl:when test="expression">
... Than gives that output ...
</xsl:when>
<xsl:otherwise>
... Than gives that output ....
</xsl:otherwise>
</xsl:choose>
Questions 5 How to use<xsl:if> element in XSLT?
Answer Using <xsl:if> element we can test the content of an XSL document.
Syntax:
<xsl:if test="expression">
...Write here output it will dispay when condition is true...
</xsl:if>
I have given you example to use of <xsl:if> element.
<?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:if test="price > 150">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
It will give the title of book with related author which book cost greater than 150.
Goto Page:
1 2 3
XSLT Objective Questions And Answers
XSLT Objective Questions And Answers
XSLT Interview Questions And Answers
XSLT Subjective Questions And Answers
R4R,XSLT Objective, XSLT Subjective, XSLT Interview Questions And Answers,XSLT,XSLT Interview,XSLT Questions ,XSLT Answers
|