1
votes

I have this XML:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <txnId>0</txnId>
    <headerNotes>
        <reservationId>505524998</reservationId>
        <computerId>93725091</computerIdId>
        <customerNumber>2166552</customerNumber>
        <modifiedDate>2015-07-27T13:36:19.000+0000</modifiedDate>
        <modifiedBy>sa_oapig</modifiedBy>
        <requestedBy>sa_oapig</requestedBy>
        <serialNumber>1</serialNumber>
        <note/>
        <headerSummary>
            <reserve>Reservation info</reserve>
            <actionTaken>Changed</actionTaken>
        </headerSummary>
        <headerDetails>
            <reserve>Reservation info</reserve>
            <actionBy/>
            <field/>
            <original/>
            <new/>
        </headerDetails>
    </headerNotes>
  </Root>

I want to transform the above XML to new SOAP format using XSLT transformation, The main thing here is that I don't need Root element and headerNotes, but needed subelements of it and the other condition is that headerNotes three subelements should be again embeded into their own tags as shown in the below requirement. I need the exact XSLT code to transform to below XML inside soap envelop

 <reservationId>505524998</reservationId>
 <computerId>93725091</computerIdId>
 <customerNumber>2166552</customerNumber>
 <modifiedDate>2015-07-27T13:36:19.000+0000</modifiedDate>
 <modifiedBy>sa_oapig</modifiedBy>
 <requestedBy>sa_oapig</requestedBy>
 <serialNumber>1</serialNumber>
 <note/>
 <headerSummary>
     <reserve>Reservation info</reserve>
     <actionTaken>Changed</actionTaken>
 </headerSummary>
 <headerDetails>
     <reserve>Reservation info</reserve>
     <actionBy/>
     <field/>
     <original/>
     <new/>
  </headerDetails>

I have tried using the below xslt code, but no luck

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
    <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>

    <xsl:template match="Root">
    <xsl:for-each select="/Root/headerNotes">
    <reservationId>
        <reservationId><xsl:value-of select="reservationId" /> </reservationId>
    </reservationId>
    <computerId>
        <computerId> <xsl:value-of select="computerId" /> </computerId>
    </computerId>
    <customerNumber>
        <customerId><xsl:value-of select="customerNumber"/></customerId>
    </customerNumber>
    </xsl:for-each>
    </xsl:template>
    <xsl:template match="headerNotes">
    <xsl:copy-of select="./*" />
    </xsl:template>
    <xsl:template match="headerSummary">
    <xsl:copy-of select="." />
    </xsl:template>
    <xsl:template match="headerDetails">
    <xsl:copy-of select="." />
    </xsl:template>
</xsl:stylesheet>

I am looking for the xslt code which can be useful to use it in my code.Once I have the solution, it will help in my transformation.

Thank you

1
Are you sure that's the exact result you want? An XML fragment, without a single root element? - michael.hor257k
I would like to transform this output into SOAP body. please help me - Ram Reddy
I see no SOAP in your output, so it's not clear what you want. - michael.hor257k
I will hardcore the soap tags and want to put the xslt transformation in soap body - Ram Reddy

1 Answers

1
votes

I think you're way overcomplicating it...

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="/Root">
    <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> 
      <env:Body>
        <xsl:apply-templates select="headerNotes/*"/>
      </env:Body>
    </env:Envelope>
  </xsl:template>
  
</xsl:stylesheet>