2015-07-21 100 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