AIF中的XSLT转换

时间:2013-08-21 13:32:34

标签: xml xslt axapta dynamics-ax-2012 aif

我正在尝试使用xsl转换转换以下BankPositivePay消息。

我的XML消息是:

<?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> 

我使用的xsl文件是

<?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>

我写的xsl文件只是没有生成AccountID。

我得到的输出文件如下:

<?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>

1 个答案:

答案 0 :(得分:0)

我将XSL转换文件中select属性的值更改为"//BankPositivePay:BankPositivePay/BankPositivePay:BankAccountTable/BankPositivePay:BankChequeTable"而不是“消息:正文/消息:MessageParts / BankPositivePay:BankPositivePay / BankPositivePay:BankAccountTable / BankPositivePay:AccountID”,它现在正在运行。我的工作XSLT文件就像:

<?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>