2013-05-17 29 views
0

此XML從Dynamics AX的生成需要轉換(XSLT):需要以創建一個XSLT得到預期的出站XML文件Dynamics AX的出站XML轉換

<?xml version="1.0" encoding="UTF-16"?> 
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message"> 
    <Header> 
    <MessageId>{3BCFB0D6-EAB4-430E-9921-E365F189046D}</MessageId> 
    <Action>http://schemas.microsoft.com/dynamics/2008/01/services/LedgerExchangeRateService/read</Action> 
    </Header> 
    <Body> 
    <MessageParts xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message"> 
     <LedgerExchangeRate xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/LedgerExchangeRate"> 
     <SenderId>Womar</SenderId> 
     <CurrencyPair class="entity"> 
      <FromCurrencyCode>US</FromCurrencyCode> 
      <ToCurrencyCode>DKK</ToCurrencyCode> 
      <ExchangeRateType>Default</ExchangeRateType> 
      <ExchangeRateDisplayFactor>Hundred</ExchangeRateDisplayFactor> 
      <ExchangeRate class="entity"> 
      <ExchangeRate>500.000000000000</ExchangeRate> 
      <ValidFrom>2013-05-17</ValidFrom> 
      </ExchangeRate> 
      <RateType class="entity"> 
      <Name>Default</Name> 
      </RateType> 
     </CurrencyPair> 
     </LedgerExchangeRate> 
    </MessageParts> 
    </Body> 
</Envelope> 

改造後的文件將是如下:

<?xml version="1.0" encoding="utf-8"?> 
<exchangeRateImport action="create" xmlns="http://schemas.v.com/2005/ImosOps" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <baseCurrency>US</baseCurrency> 
    <currency>EU</currency> 
    <rate>55.00000000</rate> 
    <effectiveDate>2013-05-17</effectiveDate> 
</exchangeRateImport> 

我已經創建了XLRT,如下所示,結果不同。請幫忙。

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
       xmlns:axEnv="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" 
       xmlns:axExchRate="http://schemas.microsoft.com/dynamics/2008/01/documents/LedgerExchangeRate"> 
    <xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="no"/> 
    <xsl:template match="/"> 
    <exchangeRateImport imosMsg:action="update" xmlns:imosMsg="http://schemas.veson.com/2005/ImosMsg" xmlns="http://schemas.veson.com/2005/ImosOps" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     <baseCurrency> 
     <xsl:value-of select="axEnv:Envelope/axEnv:body/axEnv:MessageParts/axExchRate:LedgerExchangeRate/axExchRate:CurrencyPair/axExchRate:FromCurrencyCode"/> 
     </baseCurrency> 
     <currency/> 
     <rate/> 
     <effectiveDate/> 
    </exchangeRateImport> 
    </xsl:template> 
</xsl:stylesheet> 

結果:

<exchangeRateImport imosMsg:action="update" xmlns="http://schemas.veson.com/2005/ImosOps" xmlns:imosMsg="http://schemas.veson.com/2005/ImosMsg" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:axEnv="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" xmlns:axExchRate="http://schemas.microsoft.com/dynamics/2008/01/documents/LedgerExchangeRate"><baseCurrency></baseCurrency><currency /><rate /><effectiveDate /></exchangeRateImport> 

回答

1

你變換的主要原因是不工作的是,axEnv:body元素沒有被發現,因爲它有一個資本B源XML。

我不完全理解你需要什麼,因爲你說你需要的XML幾乎不符合源數據。不過,這是我最好的猜測。我希望它有幫助。

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
    xmlns:axEnv="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" 
    xmlns:axExchRate="http://schemas.microsoft.com/dynamics/2008/01/documents/LedgerExchangeRate" 
    exclude-result-prefixes="axEnv axExchRate"> 

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

    <xsl:template match="/"> 
    <xsl:apply-templates select="axEnv:Envelope/axEnv:Body/axEnv:MessageParts/axExchRate:LedgerExchangeRate/axExchRate:CurrencyPair"/> 
    </xsl:template> 

    <xsl:template match="axExchRate:CurrencyPair"> 

    <exchangeRateImport 
     imosMsg:action="update" 
     xmlns="http://schemas.veson.com/2005/ImosOps" 
     xmlns:imosMsg="http://schemas.veson.com/2005/ImosMsg" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     <baseCurrency> 
     <xsl:value-of select="axExchRate:FromCurrencyCode"/> 
     </baseCurrency> 
     <currency> 
     <xsl:value-of select="axExchRate:ToCurrencyCode"/> 
     </currency> 
     <rate> 
     <xsl:value-of select="axExchRate:ExchangeRate/axExchRate:ExchangeRate"/> 
     </rate> 
     <effectiveDate> 
     <xsl:value-of select="axExchRate:ExchangeRate/axExchRate:ValidFrom"/> 
     </effectiveDate> 
    </exchangeRateImport> 

    </xsl:template> 

</xsl:stylesheet> 

輸出

<?xml version="1.0" encoding="utf-8"?> 
<exchangeRateImport 
    xmlns="http://schemas.veson.com/2005/ImosOps" 
    xmlns:imosMsg="http://schemas.veson.com/2005/ImosMsg" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    imosMsg:action="update"> 

    <baseCurrency>US</baseCurrency> 
    <currency>DKK</currency> 
    <rate>500.000000000000</rate> 
    <effectiveDate>2013-05-17</effectiveDate> 
</exchangeRateImport> 
+0

嗨鮑羅廷,都非常感謝烏拉圭回合的貢獻第一。真的很感激它。 – Dip

+0

嗨鮑羅廷,非常感謝你的貢獻。真的很感激它。基本上,源系統「動態ax」生成基於自己的xsd的xml文件,其中目標xml具有dfrnt格式,但信息集是固定的。所以,在源系統中,我們可以選擇上傳一個xsl文件,它將從源xml進行轉換。我們稱之爲AIF(應用集成框架)。我剛開始學習xslt。我可以知道是否可以從輸出文件 – Dip

+0

@Dip中刪除源名稱空間爲xmlns:axEnv =「http:../ documents/Message」和xmlns:axExchRate =「http:.. LedgerExchangeRate」@Dip:是的,您可以添加一個'exclude-result-prefixes'屬性指向''根元素。我相應地改變了我的答案。 – Borodin