Deleate element except one of its children


I’m new to xslt, and I need some help in wrting xslt code so it can do the following:

If “UML:Package” element has “xmi.idref” attribute then delete its grandPa element block.
Otherwise: If “UML:Package” element doesn’t has “xmi.idref” attribute then delete “UML:Package” element except the content of its of its child element “UML:Namespace.ownedElement”.

Thanks in Advance,