I have a SOAP web service that is defined contract-first--the request and response xml are defined by xsds that use a number of different namespaces, and there are 100s of elements defined in xsds. However the web service calls a legacy layer which does not use namespaces in the xml. Therefore I have a transformation layer between the web service and the legacy layer which uses xslt to transform the request and response xml. On the way in the tranformation layer uses an xslt to strip namespace prefixes from the request xml, which is working OK, because there are only a small number of namespace prefixes to match against.
However on the way out I need an xslt that will add the namespace prefixes back into the response, and I am not sure how to do this. The response may consist of dozens of different element types; which may belong to one of several different namespaces in the xsds. For example, I may have a response like this:
<order>
<item name="table"/>
<customer name="jim"/>
</order>
I need to transform this into:
<order
xmlns:types1="http://types1.company.com" xmlns:types2="http://types2.company.com">
<types1:item name="table"/>
<types2:customer name="jim"/>
</order>
Is the only way to do this is to have a big table in the xslt that matches the element name in the response (e.g., "item", "customer") against the prefix that should be used?
Or would it be better to right some code that loads in the xsd as xml, and then matches the response elements to the elements in the xsd and derives the correct namespace that way?