title: need help to do XML to XML transformation using XSLT
body: <p>I am trying to use xslt to read the contents of the input xml and generate the output xml .
  I am able to generate the output xml using xslt but could not copy the data from input xml to the generated output xml. for now I have directly hardcoded the values in the xsl file . </p>
  
  <p>below are the input xml and the expected output xml along with the XSL .</p>
  
  <p>Need help to modify the the xsl to read the element &amp; attribute data from the input xml and put them in corrosponding elemwnts/attributes of the generated output xml  </p>
  
  <p>input xml</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;soapenv:Body&gt;
  &lt;ns0:Envelope xmlns:ns0="urn:test.com:xi:testsoap2soap"&gt;
  &lt;Header&gt;
    &lt;m_Header mustUnderstand="0"&gt;
       &lt;m_SessionID&gt;SessionID1&lt;/m_SessionID&gt;
    &lt;/m_Header&gt;
  &lt;/Header&gt;
  &lt;Body&gt;
    &lt;Generate&gt;
       &lt;iPolicyID&gt;473441&lt;/iPolicyID&gt;
       &lt;sNoticeTypeID&gt;C&lt;/sNoticeTypeID&gt;
       &lt;iAdvDays&gt;0&lt;/iAdvDays&gt;
       &lt;PolicyQuestions arrayType="npts:wspPolicyQuestion[0]" nil="true" offset="[0]" type="SOAP-ENC:Array"&gt;
          &lt;wspPolicyQuestion&gt;
             &lt;iQuestionID/&gt;
             &lt;mQuestion/&gt;
             &lt;sStateID/&gt;
             &lt;mAnswer/&gt;
             &lt;BasePolicyType/&gt;
             &lt;SysPolicyType/&gt;
          &lt;/wspPolicyQuestion&gt;
       &lt;/PolicyQuestions&gt;
       &lt;sReasonID&gt;myReason&lt;/sReasonID&gt;
       &lt;mReasonText&gt;myreasontext&lt;/mReasonText&gt;
       &lt;Agencies arrayType="npts:wspAgency[0]" nil="true" offset="[0]" type="SOAP-ENC:Array"&gt;
          &lt;wspAgency&gt;
             &lt;iAgencyID/&gt;
             &lt;Address/&gt;
             &lt;sName1/&gt;
             &lt;sAgen800/&gt;
             &lt;sAgencyRefNbr/&gt;
          &lt;/wspAgency&gt;
       &lt;/Agencies&gt;
       &lt;iUnderwriterID&gt;0&lt;/iUnderwriterID&gt;
       &lt;iFaxID&gt;7284&lt;/iFaxID&gt;
       &lt;PopupQuestions arrayType="npts:wspPopupQuestion[0]" nil="true" offset="[0]" type="SOAP-ENC:Array"&gt;
          &lt;wspPopupQuestion&gt;
             &lt;iPopUpID/&gt;
             &lt;mText/&gt;
             &lt;cVarType/&gt;
             &lt;sVarLen/&gt;
             &lt;sReasonID/&gt;
             &lt;mAnswer/&gt;
             &lt;ISNID/&gt;
             &lt;BasePolicyType/&gt;
          &lt;/wspPopupQuestion&gt;
       &lt;/PopupQuestions&gt;
       &lt;ExtraNotices arrayType="npts:wspExtraNotice[0]" nil="true" offset="[0]" type="SOAP-ENC:Array"&gt;
          &lt;wspExtraNotice&gt;
             &lt;iExtraNoticeID/&gt;
             &lt;iAddressID/&gt;
             &lt;sName1/&gt;
             &lt;sName2/&gt;
             &lt;mText/&gt;
          &lt;/wspExtraNotice&gt;
       &lt;/ExtraNotices&gt;
       &lt;dtMail&gt;2013-01-08&lt;/dtMail&gt;
       &lt;iMailLeadDays&gt;0&lt;/iMailLeadDays&gt;
       &lt;dtEffective&gt;2013-01-25&lt;/dtEffective&gt;
       &lt;iMailingTypeID&gt;77&lt;/iMailingTypeID&gt;
       &lt;bDateAutoCalc&gt;false&lt;/bDateAutoCalc&gt;
       &lt;sAsOfPhrase/&gt;
       &lt;sFreeformTitle/&gt;
       &lt;mFreeformText/&gt;
       &lt;FreeformReceipients&gt;0&lt;/FreeformReceipients&gt;
       &lt;RemittanceSlip arrayType="npts:wspRemittanceSlip[5]" nil="true" offset="[0]" type="SOAP-ENC:Array"&gt;
          &lt;wspRemittanceSlip&gt;
             &lt;FieldName&gt;DocType&lt;/FieldName&gt;
             &lt;FieldValue&gt;7&lt;/FieldValue&gt;
          &lt;/wspRemittanceSlip&gt;
          &lt;wspRemittanceSlip&gt;
             &lt;FieldName&gt;ScanLine&lt;/FieldName&gt;
             &lt;FieldValue&gt;027 0018949170X013091774 01012013 7 00000002559600 1&lt;/FieldValue&gt;
          &lt;/wspRemittanceSlip&gt;
          &lt;wspRemittanceSlip&gt;
             &lt;FieldName&gt;BPNumber&lt;/FieldName&gt;
             &lt;FieldValue&gt;1009738961&lt;/FieldValue&gt;
          &lt;/wspRemittanceSlip&gt;
          &lt;wspRemittanceSlip&gt;
             &lt;FieldName&gt;RefNumber&lt;/FieldName&gt;
             &lt;FieldValue&gt;00018949170X01309177&lt;/FieldValue&gt;
          &lt;/wspRemittanceSlip&gt;
          &lt;wspRemittanceSlip&gt;
             &lt;FieldName&gt;CouponName&lt;/FieldName&gt;
             &lt;FieldValue&gt;ABC Company&lt;/FieldValue&gt;
          &lt;/wspRemittanceSlip&gt;
       &lt;/RemittanceSlip&gt;
       &lt;sRemittanceSlipLayout&gt;remit_slip_bpr.txt&lt;/sRemittanceSlipLayout&gt;
       &lt;sRemittanceSlipTemplate&gt;remit_slip_bpr.pdf&lt;/sRemittanceSlipTemplate&gt;
       &lt;PrintAction&gt;32&lt;/PrintAction&gt;
       &lt;CopyOptions&gt;0&lt;/CopyOptions&gt;
       &lt;CCListOptions&gt;0&lt;/CCListOptions&gt;
    &lt;/Generate&gt;
   &lt;/Body&gt;
   &lt;/ns0:Envelope&gt;
   &lt;/soapenv:Body&gt;
   &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>output xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;SOAP-ENV:Header&gt;
      &lt;npts:m_Header xmlns:npts="urn:TestService" SOAP-ENV:mustUnderstand="0"&gt;
          &lt;m_SessionID&gt;SESSIONID1&lt;/m_SessionID&gt;
      &lt;/npts:m_Header&gt;
  &lt;/SOAP-ENV:Header&gt;
  &lt;SOAP-ENV:Body&gt;
      &lt;npts:Generate xmlns:npts="urn:TestService"&gt;
          &lt;iPolicyID&gt;473441&lt;/iPolicyID&gt;
          &lt;sNoticeTypeID&gt;C&lt;/sNoticeTypeID&gt;
          &lt;iAdvDays&gt;0&lt;/iAdvDays&gt;
          &lt;npts:PolicyQuestions xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-SCH="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENC:arrayType="npts:wspPolicyQuestion[0]" SOAP-SCH:nil="true" SOAP-ENC:offset="[0]" SOAP-SCH:type="SOAP-ENC:Array"/&gt;
          &lt;sReasonID&gt;myreason&lt;/sReasonID&gt;
          &lt;mReasonText&gt;myreasontext&lt;/mReasonText&gt;
          &lt;npts:Agencies xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-SCH="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENC:arrayType="npts:wspAgency[0]" SOAP-SCH:nil="true" SOAP-ENC:offset="[0]" SOAP-SCH:type="SOAP-ENC:Array"/&gt;
          &lt;iUnderwriterID&gt;0&lt;/iUnderwriterID&gt;
          &lt;iFaxID&gt;728477&lt;/iFaxID&gt;
          &lt;npts:PopupQuestions xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-SCH="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENC:arrayType="npts:wspPopupQuestion[0]" SOAP-SCH:nil="true" SOAP-ENC:offset="[0]" SOAP-SCH:type="SOAP-ENC:Array"/&gt;
          &lt;npts:ExtraNotices xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-SCH="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENC:arrayType="npts:wspExtraNotice[0]" SOAP-SCH:nil="true" SOAP-ENC:offset="[0]" SOAP-SCH:type="SOAP-ENC:Array"/&gt;
          &lt;dtMail&gt;2013-01-08&lt;/dtMail&gt;
          &lt;iMailLeadDays&gt;0&lt;/iMailLeadDays&gt;
          &lt;dtEffective&gt;2013-01-25&lt;/dtEffective&gt;
          &lt;iMailingTypeID&gt;77&lt;/iMailingTypeID&gt;
          &lt;bDateAutoCalc&gt;false&lt;/bDateAutoCalc&gt;
          &lt;sAsOfPhrase/&gt;
          &lt;sFreeformTitle/&gt;
          &lt;mFreeformText/&gt;
          &lt;FreeformReceipients&gt;0&lt;/FreeformReceipients&gt;
          &lt;npts:RemittanceSlip xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-SCH="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENC:arrayType="npts:wspRemittanceSlip[5]" SOAP-ENC:offset="[0]" SOAP-SCH:type="SOAP-ENC:Array"&gt;
              &lt;wspRemittanceSlip&gt;
                  &lt;FieldName&gt;DocType&lt;/FieldName&gt;
                  &lt;FieldValue&gt;7&lt;/FieldValue&gt;
              &lt;/wspRemittanceSlip&gt;
              &lt;wspRemittanceSlip&gt;
                  &lt;FieldName&gt;ScanLine&lt;/FieldName&gt;
                  &lt;FieldValue&gt;027 0018949170X013091774 01012013 7 00000002559600 1&lt;/FieldValue&gt;
              &lt;/wspRemittanceSlip&gt;
              &lt;wspRemittanceSlip&gt;
                  &lt;FieldName&gt;BPNumber&lt;/FieldName&gt;
                  &lt;FieldValue&gt;1009738961&lt;/FieldValue&gt;
              &lt;/wspRemittanceSlip&gt;
              &lt;wspRemittanceSlip&gt;
                  &lt;FieldName&gt;RefNumber&lt;/FieldName&gt;
                  &lt;FieldValue&gt;00018949170X01309177&lt;/FieldValue&gt;
              &lt;/wspRemittanceSlip&gt;
              &lt;wspRemittanceSlip&gt;
                  &lt;FieldName&gt;CouponName&lt;/FieldName&gt;
                  &lt;FieldValue&gt;ABC Company&lt;/FieldValue&gt;
              &lt;/wspRemittanceSlip&gt;
          &lt;/npts:RemittanceSlip&gt;
          &lt;sRemittanceSlipLayout&gt;remit_slip_bpr.txt&lt;/sRemittanceSlipLayout&gt;
          &lt;sRemittanceSlipTemplate&gt;remit_slip_bpr.pdf&lt;/sRemittanceSlipTemplate&gt;
          &lt;PrintAction&gt;32&lt;/PrintAction&gt;
          &lt;CopyOptions&gt;0&lt;/CopyOptions&gt;
          &lt;CCListOptions&gt;0&lt;/CCListOptions&gt;
      &lt;/npts:Generate&gt;
  &lt;/SOAP-ENV:Body&gt;
   &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>xsl used to get output xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                             xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope"
                             xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                             xmlns:npts="urn:TestService"
                             xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
                             xmlns:SOAP-SCH="http://www.w3.org/2001/XMLSchema-instance"
                             xmlns:ns0="urn:test.com:xi:testsoap2soap"&gt;
     &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt;
     &lt;xsl:template match="/"&gt;
  &lt;xsl:element name="SOAP-ENV:Envelope"&gt;
  &lt;xsl:element name="SOAP-ENV:Header"&gt;
  &lt;xsl:element name="npts:m_Header"&gt;
  &lt;xsl:attribute name="SOAP-ENV:mustUnderstand"&gt;&lt;xsl:value-of select="m_Header/@mustUnderstand"/&gt;&lt;/xsl:attribute&gt;
  &lt;xsl:element name="m_SessionID"&gt;SESSIONID1&lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;xsl:element name="SOAP-ENV:Body"&gt;
  &lt;xsl:element name="npts:Generate"&gt;
  &lt;xsl:element name="iPolicyID"&gt;473441&lt;/xsl:element&gt;
  &lt;xsl:element name="sNoticeTypeID"&gt;C&lt;/xsl:element&gt;
  &lt;xsl:element name="iAdvDays"&gt;0&lt;/xsl:element&gt;
  &lt;xsl:element name="npts:PolicyQuestions"&gt;
  &lt;xsl:attribute name="SOAP-ENC:arrayType"&gt;npts:wspPolicyQuestion[0]&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-SCH:nil"&gt;true&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-ENC:offset"&gt;[0]&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-SCH:type"&gt;SOAP-ENC:Array&lt;/xsl:attribute&gt;
  &lt;/xsl:element&gt;
  &lt;xsl:element name="sReasonID"&gt;myreason&lt;/xsl:element&gt;
  &lt;xsl:element name="mReasonText"&gt;myreasontext&lt;/xsl:element&gt;
  &lt;xsl:element name="npts:Agencies"&gt;
  &lt;xsl:attribute name="SOAP-ENC:arrayType"&gt;npts:wspAgency[0]&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-SCH:nil"&gt;true&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-ENC:offset"&gt;[0]&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-SCH:type"&gt;SOAP-ENC:Array&lt;/xsl:attribute&gt;
  &lt;/xsl:element&gt;
  &lt;xsl:element name="iUnderwriterID"&gt;0&lt;/xsl:element&gt;
  &lt;xsl:element name="iFaxID"&gt;728477&lt;/xsl:element&gt;
  &lt;xsl:element name="npts:PopupQuestions"&gt;
  &lt;xsl:attribute name="SOAP-ENC:arrayType"&gt;npts:wspPopupQuestion[0]&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-SCH:nil"&gt;true&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-ENC:offset"&gt;[0]&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-SCH:type"&gt;SOAP-ENC:Array&lt;/xsl:attribute&gt;
  &lt;/xsl:element&gt;
  &lt;xsl:element name="npts:ExtraNotices"&gt;
  &lt;xsl:attribute name="SOAP-ENC:arrayType"&gt;npts:wspExtraNotice[0]&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-SCH:nil"&gt;true&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-ENC:offset"&gt;[0]&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-SCH:type"&gt;SOAP-ENC:Array&lt;/xsl:attribute&gt;
  &lt;/xsl:element&gt;
  &lt;xsl:element name="dtMail"&gt;2013-01-08&lt;/xsl:element&gt;
  &lt;xsl:element name="iMailLeadDays"&gt;0&lt;/xsl:element&gt;
  &lt;xsl:element name="dtEffective"&gt;2013-01-25&lt;/xsl:element&gt;
  &lt;xsl:element name="iMailingTypeID"&gt;77&lt;/xsl:element&gt;
  &lt;xsl:element name="bDateAutoCalc"&gt;false&lt;/xsl:element&gt;
  &lt;xsl:element name="sAsOfPhrase"&gt;&lt;/xsl:element&gt;
  &lt;xsl:element name="sFreeformTitle"&gt;&lt;/xsl:element&gt;
  &lt;xsl:element name="mFreeformText"&gt;&lt;/xsl:element&gt;
  &lt;xsl:element name="FreeformReceipients"&gt;0&lt;/xsl:element&gt;
  &lt;xsl:element name="npts:RemittanceSlip"&gt;
  &lt;xsl:attribute name="SOAP-ENC:arrayType"&gt;npts:wspRemittanceSlip[5]&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-ENC:offset"&gt;[0]&lt;/xsl:attribute&gt;
  &lt;xsl:attribute name="SOAP-SCH:type"&gt;SOAP-ENC:Array&lt;/xsl:attribute&gt;
  &lt;xsl:element name="wspRemittanceSlip"&gt;
  &lt;xsl:element name="FieldName"&gt;DocType&lt;/xsl:element&gt;
  &lt;xsl:element name="FieldValue"&gt;7&lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;xsl:element name="wspRemittanceSlip"&gt;
  &lt;xsl:element name="FieldName"&gt;ScanLine&lt;/xsl:element&gt;
  &lt;xsl:element name="FieldValue"&gt;027 0018949170X013091774 01012013 7 00000002559600 1&lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;xsl:element name="wspRemittanceSlip"&gt;
  &lt;xsl:element name="FieldName"&gt;BPNumber&lt;/xsl:element&gt;
  &lt;xsl:element name="FieldValue"&gt;1009738961&lt;/xsl:element&gt;
  &lt;/xsl:element&gt; 
  &lt;xsl:element name="wspRemittanceSlip"&gt;
  &lt;xsl:element name="FieldName"&gt;RefNumber&lt;/xsl:element&gt;
  &lt;xsl:element name="FieldValue"&gt;00018949170X01309177&lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;xsl:element name="wspRemittanceSlip"&gt;
  &lt;xsl:element name="FieldName"&gt;CouponName&lt;/xsl:element&gt;
  &lt;xsl:element name="FieldValue"&gt;ABC Company&lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;xsl:element name="sRemittanceSlipLayout"&gt;remit_slip_bpr.txt&lt;/xsl:element&gt;
  &lt;xsl:element name="sRemittanceSlipTemplate"&gt;remit_slip_bpr.pdf&lt;/xsl:element&gt;
  &lt;xsl:element name="PrintAction"&gt;32&lt;/xsl:element&gt;
  &lt;xsl:element name="CopyOptions"&gt;0&lt;/xsl:element&gt;
  &lt;xsl:element name="CCListOptions"&gt;0&lt;/xsl:element&gt;
   &lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>`</p>