need to convert an xml file having a tag(dynamicVariable) that has an attribute(name).This xml file has to be converted using xsl into the same xml file such that the tag (dynamicVariable) should have the same structure along with it and its the tag-content also should be the value of the attribute.
need to convert the below xml file
<Content>
<alertHeader>
<text xmlns="http://abc.com" xmlns:w="http://def.com"> Claim
<dynamicVariable name="Claim_Reference" />: More Information Needed
</text>
<contactUs>false</contactUs>
</alertHeader>
<body>
<text> ATM/Debit Card Claim:
<strong><dynamicVariable name="Claim_Reference" /></strong>
</text>
</body>
</Content>
into the same format but the tag having ‘name’ attribute should appear in the output xml file as this format
<dynamicVariable name="Claim_Reference" />Claim_Reference</dynamicVariable>
Can anyone provide the necessary xsl file in converting the same. Hope that its done using
<xsl:copy></xsl:copy> or <xsl:copy-of /> tags .
As simple as this:
When this transformation is applied on the provided XML document:
the wanted, correct result is produced:
Explanation:
The identity rule copies every node “as-is”.
A single template overrides the identity template. It matches any that has athe name “
dynamicVariable” regardless of namespace, and that is a child ofstrong(thus specifying more context helps us process only this occurence ofdynamicVariablebut leave the preceding one “as-is”).The overriding tempalte shallo-copies the current node, then copies its attributes, then finally creates a text-node child whose contents is the string value of the
nameattribute of the current (matched) element.