2

我正在尝试使用 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>
4

1 回答 1

0

我将 XSL 转换文件中选择属性的值更改为"//BankPositivePay:BankPositivePay/BankPositivePay:BankAccountTable/BankPositivePay:BankChequeTable"“Message:Body/Message: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>
于 2013-08-26T15:22:43.343 回答