2

I am trying to transform the following BankPositivePay message using a xsl transformation.

The XML message I have is:

<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
 <Header>
  <MessageId>{A604C46E-F3E3-4BCB-9F7A-E8FD8749A7FC}</MessageId>
  <Action>http://tempuri.org/BankPositivePayService/find</Action>
 </Header>
 <Body>
  <MessageParts xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
   <BankPositivePay xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/BankPositivePay">
    <BankAccountTable class="entity">
     <AccountID>USA OPER</AccountID>
     <AccountNum>34567</AccountNum>
     <CurrencyCode>USD</CurrencyCode>-<LedgerDimension><MainAccount xmlns="http://schemas.microsoft.com/dynamics/2008/01/sharedtypes">110110</MainAccount></LedgerDimension>-<BankChequeTable class="entity"><AccountID>USA OPER</AccountID><AmountCur>3500.00</AmountCur><ChequeNum>1132</ChequeNum><ChequeStatus>Payment</ChequeStatus><RecipientAccountNum>1001</RecipientAccountNum><TransDate>2013-08-16</TransDate>-<VendTable class="entity"><Currency>USD</Currency>-<DefaultDimension>-<Values xmlns="http://schemas.microsoft.com/dynamics/2008/01/sharedtypes">-<Value><Name>CustomDepartment</Name><Value>060</Value></Value></Values></DefaultDimension><VendGroup>10</VendGroup></VendTable>-<CompanyInfo class="entity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AxdEntity_CompanyInfo_CompanyInfo"><DataArea>ceu</DataArea></CompanyInfo></BankChequeTable></BankAccountTable></BankPositivePay></MessageParts></Body></Envelope> 

The xsl file that I am using is

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:Message="http://schemas.microsoft.com/dynamics/2011/01/documents/Message"

xmlns:BankPositivePay="http://schemas.microsoft.com/dynamics/2008/01/documents/BankPositivePay"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="no"/>

<xsl:template match="Message:Envelope">
   <Test>
     <Header>
       <records>
         <record>
           <xsl:value-of select="Message:Body/Message:MessageParts/BankPositivePay:BankPositivePay/BankPositivePay:BankAccountTable/BankPositivePay:AccountID"/>
         </record>
       </records>
     </Header>
   </Test>
</xsl:template>
</xsl:stylesheet>

The xsl file that I have written is just not producing the AccountID.

The output file that I get is like:

<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
 <Header>
  <MessageId>{CBC894EE-B70F-44E8-B37E-EA6B8F2BA327}</MessageId>
  <Action>http://tempuri.org/BankPositivePayService/find</Action>
 </Header>
 <Body>
  <MessageParts xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
   <Test xmlns="">
    <Header>
     <records><record/></records>
    </Header>
   </Test>
  </MessageParts>
 </Body>
</Envelope>
LarsH
  • 27,481
  • 8
  • 94
  • 152
Alok
  • 244
  • 2
  • 8
  • 23
  • 1
    I don't think that output can possibly come from that stylesheet. Are you sure that's the stylesheet that is really being executed? Are there other templates you're not showing us? Your output indicates e.g. a template that matches "Message:MessageParts". – LarsH Aug 21 '13 at 18:41
  • I am not sure how but that is the output I am getting. When I ran it in other scenario with the input xml as: – Alok Aug 21 '13 at 20:00

1 Answers1

0

I changed the value of select attribute in XSL transformation file as "//BankPositivePay:BankPositivePay/BankPositivePay:BankAccountTable/BankPositivePay:BankChequeTable" instead of `"Message:Body/Message:MessageParts/BankPositivePay:BankPositivePay/BankPositivePay:BankAccountTable/BankPositivePay:AccountID" and it is working now. My working XSLT file is like:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:Message="http://schemas.microsoft.com/dynamics/2011/01/documents/Message"
xmlns:BankPositivePay="http://schemas.microsoft.com/dynamics/2008/01/documents/BankPositivePay">
  <xsl:output method="text" indent="yes" encoding="utf-8" omit-xml-declaration="no"/>
  <xsl:template match="/">
    <header>
      <records>
        <xsl:for-each select="//BankPositivePay:BankPositivePay/BankPositivePay:BankAccountTable/BankPositivePay:BankChequeTable">
          <record>
            <xsl:value-of select="BankPositivePay:AccountID"/>
          </record>
          <record1>
            <xsl:value-of select="BankPositivePay:AccountNum"/>
          </record1>
          <record2>
            <xsl:value-of select="BankPositivePay:ChequeStatus"/>
          </record2>
          <record3>
            <xsl:value-of select="BankPositivePay:ChequeNum"/>
          </record3>
          <record4>
            <xsl:value-of select="BankPositivePay:AmountCur"/>
          </record4>
          <record5>
            <xsl:value-of select="BankPositivePay:TransDate"/>
          </record5>
          <record6>
            <xsl:value-of select="BankPositivePay:RecipientAccountNum"/>
          </record6>

          <test>
            <xsl:text>
            &#160;
</xsl:text>
          </test>

        </xsl:for-each>
      </records>
    </header>
  </xsl:template>
</xsl:stylesheet>
Alok
  • 244
  • 2
  • 8
  • 23