My xml file looks like below.
<rule>
<name>86</name>
<ruleId>100</ruleId>
<ruleVersion>1.0</ruleVersion>
<brlVersion>1.0</brlVersion>
</rule>
I need to replace name with brlName and i need to add another tag as drlName.The output should looks like below.
<rule>
<brlName>86</brlName>
<ruleId>100</ruleId>
<ruleVersion>1.0</ruleVersion>
<brlVersion>1.0</brlVersion>
<drlName>86_1.0</drlName>
</rule>
Please help me with corresponding xsl to get desired output. Appreciated your help!
This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Explanation:
Using and overriding the identity rule/template -- the most fundamental and powerful XSLT design pattern.
Override on any element named
name
and creating an element namedbrlName
(rename).Override on the last last element child of the top element. Calling the identity rule by name for this node (copying) and then creating an element named
drlName
with a specific text-node child as per the requirements.Using and overriding the identity rule/template is the most fundamental and powerful XSLT design pattern. You can learn more about it here.
This is the typical task for the identity transform (the first template rule in the transform below). Just two overrides (the last two rules).
XSLT 1.0 tested under Saxon 6.5.5