XSLT is wealthy, highly effective and given its help in Java and a number of other different programming languages, it comes the pure selection of XML transformation. What you could do is write XSL information, also called XML model sheets to specify your transformation rule, after which the XSLT engine will remodel every incoming XML paperwork as per your XSL file.
Although XSLT is wealthy, it’s may also be very advanced for Java programmers, who’re used to the procedural model of coding, as XSLT uses recursion lots. So if you’re a Java programmer, who has used XSLT or going for a Job interview, the place XSLT is a key ability, you higher be ready with some fashionable XSLT interview questions.
On this article, I’m sharing my checklist of XSLT questions, which is collected from the web, associates, and colleagues and often requested as part of XML Interview questions.
XSLT or XML transformation Interview Questions Solutions
Right here is my checklist of XSLT questions, which is often requested to Java builders for initiatives, who makes use of XML extensively for transferring knowledge, producing dynamic HTML and different XML transformation process.
Query 1: What’s XSL transformation or XSLT? How do you carry out XML transformation in Java?
Any XSLT engine can learn these instruction outlined in model sheet doc and remodel supply XML file into one thing anticipated. Core of XSLT is, transformation engine and model sheet doc. XSLT engine will be written in Java or another language.
Java has XSLT help through javax.xml.remodel package deal which specifies lessons like Templates, TransformFactory, an implementation of summary manufacturing facility design sample, which can be utilized to learn XSL file and remodel XML information. See XSL transformation in Java for extra particulars
Query 2: The way to take away a selected ingredient from XML?
Reply : Eradicating ingredient from XML doc through XSL transformation or XSLT is straightforward if you’re aware of Id template. It’s essential write two templates one is Id template, which copies each factor and different for matching with explicit ingredient and doing nothing similar to proven beneath, which can then lead to removing of a that exact ingredient. See an instance of eradicating XML parts utilizing XSLT for particulars.
<xsl:template match=”/root/product”/>
Query 3: The way to take away a selected attribute from XML?
Reply : Means of eradicating an attribute is much like eradicating parts from XML doc, as mentioned in above XSLT interview query. Together with Id template, outline one other template to match with that exact attribute as proven beneath.
<xsl:template match=”@product_synonym”/>
Query 4: The way to rename a selected ingredient and attribute from XML utilizing XSL?
Reply : Renaming attribute can also be much like eradicating or deleting attribute as mentioned in XSLT query 1, however as an alternative of not doing something when an attribute matches, you could create an attribute and replica worth of present attribute into new attribute. Id template might be identical and you could add one other template for renaming attribute utilizing XSL:
<xsl:template match=”@id”>
<xsl:attribute identify=”emp_id”>
<xsl:value-of choose=”.” />
</xsl:attribute>
</xsl:template>
if you’re utilizing XSLT 2.0 than as an alternative of separate <xsL:value-of> ingredient you need to use choose attribute straight with <xsL:attribute> as proven beneath
<xsl:attribute identify=”emp_id” choose=”.”>
Query 5: What’s Id template in XSL, why do you utilize it?
Many individuals outline Id template in its personal file like Id.xsl however some individuals additionally most popular to maintain in essential XSL file as high template. Id template has a number of makes use of in XSL transformation, like if you wish to take away any attribute or ingredient you’ll probably copy all the pieces utilizing Id template and create one other template for not doing something for these attribute or parts as mentioned in XSLT interview questions 1 and a pair of.
<xsl:template match=”@|node()”>
<xsl:copy>
<xsl:apply-templates choose=”@|node()”/>
</xsl:copy>
</xsl:template>
Above template is known as Id template. In the event you take a look at definition first template matches any attribute or
any node after which copies present node together with any attributes and baby nodes.
Query 6 : Why we use choose=”@|node()” within the <xsl:apply-templates/> ingredient on Id template? what’s going to occur if we use <xsl:apply-templates/> with out choose attribute?
Reply : That is an extension or comply with up questions of earlier XSLT query about Id template. we use choose=”@|node() to repeat all baby ingredient and any attribute.if we do not use that than <xsl:apply-templates/> will default on choose=”node()” which can copy baby nodes besides attributes.
Query 7: Are you able to clarify me this XSL template? What output this XSL template will produce given a selected xml file?
Reply : This sort of XSL transformation questions are extra fashionable to gauge actual understanding of templates. they’ll write template in entrance of you and should ask you to elucidate, most straightforward instance of that is writing Id template as mentioned in XSLT interview query 3.
Alternatively they might provide you with XSL and XML file and ask you about about of transformation. This are difficult questions in XSL and so as to reply these query you could be aware of XSL language, which is the first purpose individuals ask it.
Alternatively this is a wonderful alternative to indicate you the way effectively you recognize about XSL working or how template executes, by clearly explaining what a selected template does.
Query 8 : The way to retrieve worth of an attribute for a component utilizing XSLT?
Reply : This XSLT interview query is fairly frequent in lots of XML interviews as effectively. If candidate has labored in XSLT then it is a pretty straightforward query because it simply have to provide you with a XSLT template which may copy an attribute from a component like beneath:
<xsl:template match=”/staff/worker”>
Worth of attribute Id is :
<xsl:value-of choose=”@id”></xsl:value-of>
</xsl:template>
Query 9 : How do you generate dynamic HTML pages from relational database utilizing XSLT?
Database saved process can be used for first half and having all of the logic of rendering HTML in XSLT you needn’t change your question every now and then if you could change construction of HTML pages.
If candidate efficiently solutions this XSLT interview query then there is excellent likelihood that he has understanding of how issues works with database, xml and XSLT.
Now let’s see a few XSLT Interview questions for apply, you could discover solutions of those two questions by your self, and as soon as you discover the reply, you can even publish them as feedback right here. The explanation, I’m not giving solutions of those questions right here is as a result of, they’re extraordinarily primary and will come as expertise, i.e. you’d higher write code for that. That can allow you to grasp different XSLT questions as effectively.
10. The way to remodel one XML to a different XML doc utilizing XSLT remodel?
11. The way to remodel an XML file into HTML utilizing XSL transformation (XSLT)?
That’s all on my checklist of XSLT and XML transformation interview questions and solutions. XSLT is likely one of the essential ability to have in your resume if you’re utilizing XML in your challenge. Since XML is usually used as transport protocol and center and back-office programs, these roles search for candidates that are good in XML, XSL and XSLT transformation. So if you’re making use of for any center and again workplace Java growth position in Funding banks, be certain to arrange XSLT effectively.