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

时间:2014-01-28 16:57:41

标签: 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>

当我在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>

那么如何以“正确的顺序”输出日期?

2 个答案:

答案 0 :(得分:6)

而不是使用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>

答案 1 :(得分:1)

您有两种选择:

  1. 目的地类型必须是序列吗?你可以改变它 到xs:all。
  2. 更改您循环的位置。你必须附上 E2EDT13001GRP中的for-each在三个单独的元素内 每个DocumentIssueDate,SheduledDeliveryDate和。的定义 发货日期。这样,输出将始终按该顺序出现。