如何确保XSLT中输出元素的顺序?

Ste*_*veC 0 xslt biztalk biztalk-2010

如何确保XSLT中输出元素的顺序?

我有一个在BizTalk映射中使用的XSLT,它提取三个日期Ok,但由于源数据的顺序,生成的XML是ShipmentDate,ScheduledDeliveryDate,然后是DocumentIssueDate.

<Dates>
  <xsl:for-each select="s0:E2EDT13001GRP">
    <xsl:variable name="qualifier" select="string(s0:E2EDT13001/s0:QUALF/text())" />
    <xsl:variable name="isDocumentIssueDate" select="string(userCSharp:LogicalEq($qualifier , &quot;015&quot;))" />
    <xsl:variable name="isSheduledDeliveryDate" select="string(userCSharp:LogicalEq($qualifier , &quot;007&quot;))" />
    <xsl:variable name="isShipmentDate" select="string(userCSharp:LogicalEq($qualifier , &quot;003&quot;))" />
    <xsl:variable name="date" select="s0:E2EDT13001/s0:NTANF/text()" />

    <xsl:if test="$isDocumentIssueDate='true'">
      <DocumentIssueDate>
        <xsl:value-of select="$date" />
      </DocumentIssueDate>
    </xsl:if>

    <xsl:if test="$isScheduledDeliveryDate='true'">
      <ScheduledDeliveryDate>
        <xsl:value-of select="$date" />
      </ScheduledDeliveryDate>
    </xsl:if>

    <xsl:if test="$isShipmentDate='true'">
      <ShipmentDate>
        <xsl:value-of select="$date" />
      </ShipmentDate>
    </xsl:if>

  </xsl:for-each>
</Dates>
Run Code Online (Sandbox Code Playgroud)

当我在Visual Studio中测试地图时,我得到的错误是XML对XSD无效......

<xs:complexType>
  <xs:sequence>
    <xs:element name="DocumentIssueDate" type="xs:string" />
    <xs:element name="SheduledDeliveryDate" type="xs:string" />
    <xs:element name="ShipmentDate" type="xs:string" />
  </xs:sequence>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)

那么如何以"正确的顺序"输出日期呢?

Ian*_*rts 5

而不是使用for-each,只需逐个拉出你需要的位:

<Dates>
  <DocumentIssueDate>
    <xsl:value-of select="s0:E2EDT13001GRP[
       userCSharp:LogicalEq(s0:E2EDT13001/s0:QUALF, '015')]
        /s0:E2EDT13001/s0:NTANF" />
  </DocumentIssueDate>
  <ScheduledDeliveryDate>
    <xsl:value-of select="s0:E2EDT13001GRP[
       userCSharp:LogicalEq(s0:E2EDT13001/s0:QUALF, '007')]
        /s0:E2EDT13001/s0:NTANF" />
  </ScheduledDeliveryDate>
  <!-- etc. -->
</Dates>
Run Code Online (Sandbox Code Playgroud)