views:

355

answers:

2
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com">
 <soapenv:Body>
  <upsertResponse>
   <result>
    <created>true</created>
    <id>0011</id>
    <success>true</success>
   </result>
   <result>
    <created>false</created>
    <id>0012</id>
    <success>true</success>
   </result>
  </upsertResponse>
 </soapenv:Body>
</soapenv:Envelope>

**How can I transform this to** 

<upsertResponse>
 <result>
  <created>true</created>
  <id>0011</id>
  <success>true</success>
 </result>
 <result>
  <created>false</created>
  <id>0012</id>
  <success>true</success>
 </result>
</upsertResponse>
A: 

Use an <xsl:match> to select the <upsertResponse> element, then put an <xsl:copy> inside of it. That should do the trick. Sorry I don't have the exact syntax, but hopefully this points you in the right direction.

Jerry Bullard
What's an `<xsl:match>`?
Tomalak
Sorry. I meant "xsl:template match". It has been a while.
Jerry Bullard
A: 

This is an example of XSL that takes the first child of first child of root and makes it root node of new XML:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

     <xsl:template match="/">
          <xsl:copy-of select="./*[1]/*[1]/*[1]" />
     </xsl:template>

</xsl:stylesheet>

Please note that you can take only one node and not multiple nodes since placing few nodes as root of XML is not valid.

Elisha
This is working perfectly,Except that the root node now has a Namespace assigned.<?xml version="1.0" encoding="UTF-8"?><upsertResponse xmlns="urn:enterprise.soap.sforce.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <result> <created>true</created> <id>0011</id> <success>true</success> </result> <result> <created>false</created> <id>0012</id> <success>true</success> </result></upsertResponse>
Shree
In XML the decedents are implicitly part of the namespace or their parent (unless declared explicitly other namespace). Since the original parent does not appear in the new XML the new root explicitly declares it.
Elisha