I have a input and desired output xml file , but not able to write generic xsl transformer for that. Can anybody here help me out ? address/billing may have more elements at runtime, which should be directly copied to main person block.
<searchPersonResponse>
<persons>
<person>
<name>name2</name>
<address>
<billing>
<city>xx</city>
<state>yyyy</state>
<zip>zzzzz</zip>
</billing>
</address>
</person>
<person>
<name>name1</name>
<address>
<billing>
<city>xx</city>
<state>yyyy</state>
<zip>zzzzz</zip>
</billing>
</address>
</person>
</persons>
</searchPersonResponse>
desired output xml
<searchPersonResponse>
<persons>
<person>
<name>name2</name>
<city>xx</city>
<state>yyyy</state>
<zip>zzzzz</zip>
</person>
<person>
<name>name1</name>
<city>xx</city>
<state>yyyy</state>
<zip>zzzzz</zip>
</person>
</persons>
</searchPersonResponse>
EDITED: OP is only looking to “unwrap” address and billing elements when address is present with a billing child. XSLT now does that. Also, OP mentions needs a XSLT 1.0 solution; no XSLT 2.0 features were being used, so I simply changed the version to “1.0”.
This XSLT:
When applied to this XML:
Produces the desired result:
The identity template will copy all nodes and attributes. The address and billing matching template (which matches either element) will copy their children but not themselves.