XSLT (XSL Transformations) Question:

Download Job Interview Questions and Answers PDF

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

XSLT Interview Question
XSLT Interview Question

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

Download XSLT Interview Questions And Answers PDF

Previous QuestionNext Question
Explain how to remove a particular attribute from XML?Tell me what is Identity template in XSL, why do you use it?