2015-07-21 65 views
1

我正嘗試將以下XML轉換爲不同的xml格式。 我已經複製了我用於轉換的XSLT文件,但是我收到了無效的模式錯誤。XSLT轉換-AIF Dynamics AX

<?xml version="1.0" encoding="utf-8" ?> 
<?xml-stylesheet type="text/xsl" href="InternalVendGroup.xslt"?> 
<ns0:VendorGroup xmlns:ns0="http://InternalVendorGroup"> 
    <Header> 
    <Fld1>VendGroup1</Fld1> 
    <Fld2>VendGroup Description</Fld2> 
    <MessageId>{5FC77A8F-67D2-4BF1-A671-FF5A81EF0DDC}</MessageId> 
    </Header> 
</ns0:VendorGroup> 

XSLT轉換代碼:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:InternalSO="http://InternalVendGroup"> 
    <xsl:template match="InternalSO:AxdVendGroup"> 
    <Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message"> 
     <Header> 
     <MessageId> 
      <xsl:value-of select="Header/MessageId"/> 
     </MessageId> 
     <Action>http://schemas.microsoft.com/dynamics/2008/01/services/VendVendGroupService/create</Action> 
     </Header> 
     <Body> 
     <MessageParts> 
      <AxdVendGroup xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/VendGroup"> 
      <VendGroup class="entity"> 
       <VendGroup> 
       <xsl:value-of select="Header/Fld1"/> 
       </VendGroup> 
       <Name> 
       <xsl:value-of select="Header/Fld2" /> 
       </Name> 
      </VendGroup> 
      </AxdVendGroup> 
     </MessageParts> 
     </Body> 
    </Envelope> 
    </xsl:template> 
</xsl:stylesheet> 

改造後我正在以下,這不是想要的結果。

<?xml version="1.0" encoding="utf-8"?> 



    VendGroup1 

    VendGroup Description 

    {5FC77A8F-67D2-4BF1-A671-FF5A81EF0DDC} 

爲什麼所有的標籤都在轉換過程中丟失?

+0

爲什麼所有的標籤都在轉換過程中丟失? – Gainster

+0

這是你的問題嗎?如果是這樣,編輯您的文章。或者,如果這不是您的問題,請向您的帖子添加問題。 –

回答

3

爲什麼所有的標籤都在轉換過程中丟失?

因爲你的模板不匹配任何東西。

<xsl:template match="InternalSO:AxdVendGroup"> 

,因爲它不匹配任何:

  1. 沒有在你的XML命名AxdVendGroup元素;正確的名字是VendorGroup;
  2. 您已將InternalSO:前綴綁定到 "http://InternalVendGroup"命名空間;但您的XML輸入 使用的命名空間是"http://InternalVendorGroup"

嘗試,而不是:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:InternalSO="http://InternalVendorGroup"> 

<xsl:template match="InternalSO:VendorGroup"> 
    <!-- the rest of your template --> 
</xsl:template> 

</xsl:stylesheet> 

警告:我沒有檢查你的模板的實際內容。

+0

我改變了它,但仍然沒有好...。<?xml version =「1.0」encoding =「UTF-8」?>

http://schemas.mic – Gainster

+0

@Gainster這是什麼意思? –

+0

這是我的第一個xslt,如果您使用代碼段顯示,我將非常有幫助。 – Gainster