首页 > 解决方案 > xsl 输出 eclipse 中的额外命名空间

问题描述

由于我们公司正在从 AX 转移到 SAP,我也在从 Visual Studio 到 Eclipse 进行“转变”。我认为从一个小的 xslt 项目开始会很好,但是在尝试我现有的(用 VS 制作的)xsl 时,我注意到了一些差异。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice">
  <xsl:output method="xml" indent="yes" />

  <xsl:strip-space elements="*" />

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="msxsl:SalesType">
    <xsl:choose>
      <xsl:when test="(../msxsl:SalesType) = 'ReturnItem'">
        <xsl:element name="MessageType" namespace="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice">384</xsl:element>
      </xsl:when>
      <xsl:otherwise>
        <xsl:element name="MessageType" namespace="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice">380</xsl:element>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

生成带有 msxsl 前缀 xmlns:msxsl="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice">380 的输出 xml:

<?xml version="1.0" encoding="UTF-8"?>
<Envelope
     xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/Message">
       <Header>
             <MessageId>{0E415D3C-6D46-4E4E-B8CA-9729B11BA}</MessageId>
             <SourceEndpoint>BAB</SourceEndpoint>
             <DestinationEndpoint>INVOIC_WKMP</DestinationEndpoint>
       <Action>http://schemas.microsoft.com/dynamics/2008/01/services/SalesSalesInvoiceService/read
             </Action>
       </Header>
       <Body>
             <MessageParts>
                    <SalesInvoice xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice">
                          <CustInvoiceJour class="entity">
                                 <AccountcategoryId>FFF</AccountcategoryId>
                                 <msxsl:MessageType
                                 xmlns:msxsl="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice">380</msxsl:MessageType>
                          </CustInvoiceJour>
                    </SalesInvoice>
             </MessageParts>
       </Body>
</Envelope>

而 Visual Studio xsl 省略了 xmlns:msxsl 规范(这是正确的):

<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/Message">
  <Header>
    <MessageId>{0E415D3C-6D46-4E4E-B8CA-9729B11BA}</MessageId>
    <SourceEndpoint>BAB</SourceEndpoint>
    <DestinationEndpoint>INVOIC_WKMP</DestinationEndpoint>
    <Action>http://schemas.microsoft.com/dynamics/2008/01/services/SalesSalesInvoiceService/read</Action>
  </Header>
  <Body>
    <MessageParts>
      <SalesInvoice xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice">
        <CustInvoiceJour class="entity">
          <AccountcategoryId>FFF</AccountcategoryId>
          <MessageType>380</MessageType>
        </CustInvoiceJour>
      </SalesInvoice>
    </MessageParts>
  </Body>
</Envelope>

由于它已经在http://schemas.microsoft.com/dynamics/2008/01/documents/SalesInvoice命名空间中,因此我不想在此处添加此内容。我有什么办法可以在 Eclipse 中改变这一点?

亲切的问候,

麦克风

标签: eclipsexslt

解决方案


不,Visual Studio 省略此命名空间是不正确的。如果您不想包含它,则应使用xsl:exclude-result-prefixes="msxsl".


推荐阅读