I am trying to understand functinality of identity template.
<xsl:template match='@* | node()'>
<xsl:apply-templates select='@* | node()'/>
</xsl:template>
The above template if present in start of our XSL document, we call it identity template and its function is to call all the templates i.,e., by matching every thing under @* and node() in match. Then it goes to second line apply- templates where it recursively selects all the templates/nodes. please correct me if i am wrong here.
My question is if we have this template placed in middle of XSLT,but not in starting, and we dont want all the matching action, but only of a certain message stored in a variable like
<xsl:template match='$variable holding entire soap envelope'>
<xsl:apply-templates select='@* | node()'/>
</xsl:template>
Do we still call it identity template and will still it processes same like identity template in first action.?
Sorry if my question is not clear.
Thanks for help.
The identity transformation template copies every node so it looks like
As for a match pattern starting with a variable reference like
match='$variable'
, I don't think this is even allowed in XSLT 1.0.No, templates overriding to the identity transformation would not themselves be considered to be identity transformations.
The way to use the identity transformation template is to let it copy everything from the input XML to the output XML by default but to override the identity transformation with more specific
match
patterns where desired.For example, consider this SOAP message:
If we wanted to transform this message to another that's nearly the same, but perhaps with different
m:msg
content, we could use an identity transformation with an override form:msg
:Applying the above XSLT to the input SOAP message produces an identical SOAP message but with new
m:msg
element contents: