XSLT (XSL Transformations) Question:

Download Job Interview Questions and Answers PDF

Tell me what is Identity template in XSL, why do you use it?

XSLT Interview Question
XSLT Interview Question

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.

Download XSLT Interview Questions And Answers PDF

Previous QuestionNext Question
Explain how to rename a particular element and attribute from XML using XSL?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?