0
votes

I am using XSLT 2.0 to transform my XML. I want no namespaces with CMMHeader in my output XML, i have tried all the traditional ways but they are not working. So please can somebody point out what i am doing wrong. Note:

I just want to remove namespaces with CMMHeader tag.

Input XML

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body><tns:GLBookingMessage xmlns:tns="http://com.example/cdm/finance/generalledger/v1"> 
<tns:GLBooking>

 <cdm:CompanyCodeTo xmlns:cdm="http://com.example/cdm/finance/generalledger/v1">3010</cdm:CompanyCodeTo>
  <cdm:PostingDate xmlns:cdm="http://com.example/cdm/finance/generalledger/v1">20141009</cdm:PostingDate> 
  <cdm:CreationDate xmlns:cdm="http://com.example/cdm/finance/generalledger/v1">20140901</cdm:CreationDate>
   <cdm:GLBookingLine xmlns:cdm="http://com.example/cdm/finance/generalledger/v1"> 
   <cdm:LineNumber>1</cdm:LineNumber>
    <cdm:AccountNumber>0000133200</cdm:AccountNumber> 
    <cdm:Description> </cdm:Description> 


       </cdm:GLBookingLine> 
     <cdm:GLBookingLine xmlns:cdm="http://com.example/cdm/finance/generalledger/v1"> 
     <cdm:LineNumber>2</cdm:LineNumber> 
     <cdm:AccountNumber>0000133205</cdm:AccountNumber>
      <cdm:Description> </cdm:Description>

      </cdm:GLBookingLine>
       </tns:GLBooking> 
      </tns:GLBookingMessage>
     </soapenv:Body></soapenv:Envelope>

XSLT 2.0:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 

xmlns:cdm="http://com.example/cdm/finance/generalledger/v1" 
xmlns:tns="http://com.example/cdm/finance/generalledger/v1" 
xmlns:cur="http://com.example/cdm/currencycodes/v1"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
exclude-result-prefixes="cdm tns"
>

<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:param name="Message_ID"/>
<xsl:template match="@* | node()">
<xsl:copy inherit-namespaces="no">
<xsl:apply-templates select="@* | node()"/>

</xsl:copy>
</xsl:template>
<xsl:template match="tns:GLBookingMessage">
<xsl:copy copy-namespaces="no">


<CMMHeader>
<MessageTimeStamp>

<xsl:value-of select="format-date(current-date(), '[Y0001]-[M01]-[D01]')"/>
<xsl:text>T</xsl:text>
<xsl:value-of select="format-time(current-time(), '[H01]:[m01]:[s01].[z]')"/>
</MessageTimeStamp>
<MessageId>
<xsl:value-of select="$Message_ID"/>    
</MessageId>
<ComponentId>
<xsl:text>GLBookingFileAdapter</xsl:text>
</ComponentId>
<From>  
<xsl:text>Silta</xsl:text>
</From>
<To>
<xsl:text>GLBookingQueue</xsl:text>
</To>
<CorrelationId> 
</CorrelationId>
<ProcessId>
</ProcessId>   
<EventId>

</EventId>
<Domain>    
<xsl:text>Finance</xsl:text>
</Domain>   

</CMMHeader>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>


</xsl:stylesheet>

Current Output:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <tns:GLBookingMessage xmlns:tns="http://com.example/cdm/finance/generalledger/v1">
         <CMMHeader xmlns:cur="http://com.example/cdm/currencycodes/v1"
                    xmlns:cdm="http://com.example/cdm/finance/generalledger/v1">
            <MessageTimeStamp>2014-11-14T05:06:44.</MessageTimeStamp>
            <MessageId/>
            <ComponentId>GLBookingFileAdapter</ComponentId>
            <From>Silta</From>
            <To>GLBookingQueue</To>
            <CorrelationId/>
            <ProcessId/>
            <EventId/>
            <Domain>Finance</Domain>
         </CMMHeader> 
         <tns:GLBooking> 
            <cdm:SubLedger xmlns:cdm="http://com.example/cdm/finance/generalledger/v1">Payroll </cdm:SubLedger> 
            <cdm:Identifier xmlns:cdm="http://com.example/cdm/finance/generalledger/v1">10004 </cdm:Identifier> 

            <cdm:GLBookingLine xmlns:cdm="http://com.example/cdm/finance/generalledger/v1"> 
               <cdm:LineNumber>1</cdm:LineNumber> 
               <cdm:AccountNumber>0000133200</cdm:AccountNumber> 
               <cdm:Description> </cdm:Description> 

            </cdm:GLBookingLine> 
            <cdm:GLBookingLine xmlns:cdm="http://com.example/cdm/finance/generalledger/v1"> 
               <cdm:LineNumber>2</cdm:LineNumber> 
               <cdm:AccountNumber>0000133205</cdm:AccountNumber> 
               <cdm:Description> </cdm:Description> 

            </cdm:GLBookingLine> 
         </tns:GLBooking> 
      </tns:GLBookingMessage>
   </soapenv:Body>
</soapenv:Envelope>

Required Output:

<?xml version="1.0" encoding="utf-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body>
          <tns:GLBookingMessage xmlns:tns="http://com.example/cdm/finance/generalledger/v1">
             <CMMHeader> 
                <MessageTimeStamp>2014-11-14T05:06:44.</MessageTimeStamp>
                <MessageId/>
                <ComponentId>GLBookingFileAdapter</ComponentId>
                <From>Silta</From>
                <To>GLBookingQueue</To>
                <CorrelationId/>
                <ProcessId/>
                <EventId/>
                <Domain>Finance</Domain>
             </CMMHeader> 
             <tns:GLBooking> 
                <cdm:SubLedger xmlns:cdm="http://com.example/cdm/finance/generalledger/v1">Payroll </cdm:SubLedger> 
                <cdm:Identifier xmlns:cdm="http://com.example/cdm/finance/generalledger/v1">10004 </cdm:Identifier> 

                <cdm:GLBookingLine xmlns:cdm="http://com.example/cdm/finance/generalledger/v1"> 
                   <cdm:LineNumber>1</cdm:LineNumber> 
                   <cdm:AccountNumber>0000133200</cdm:AccountNumber> 
                   <cdm:Description> </cdm:Description> 

                </cdm:GLBookingLine> 
                <cdm:GLBookingLine xmlns:cdm="http://com.example/cdm/finance/generalledger/v1"> 
                   <cdm:LineNumber>2</cdm:LineNumber> 
                   <cdm:AccountNumber>0000133205</cdm:AccountNumber> 
                   <cdm:Description> </cdm:Description> 

                </cdm:GLBookingLine> 
             </tns:GLBooking> 
          </tns:GLBookingMessage>
       </soapenv:Body>
    </soapenv:Envelope>
1

1 Answers

0
votes

I believe that if you change your stylesheet header to:

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:tns="http://com.example/cdm/finance/generalledger/v1">

you might get what you want. Hard to tell for sure because - once again(!) - your output, both required and claimed, does not match your input.