1

我们正在使用 Tibco BusinessWorks 将 XML 文档传递给 Tibco BusinessEvents 流程。因为 BusinessEvents 没有 DATE 格式,只有 DATETIME,所以我们必须在发送到 BusinessEvents 之前更改源 XML 文档中的 Dates,并将响应的 DateTime 值映射回简单的 Dates。

这既烦人又麻烦。

为了提高 BusinessWorks 的性能,我正在编写一个样式表来处理映射。这就是我所拥有的。

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:inf="http:/the.company.namespace">

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

<xsl:template match="inf:PriorExpirationDate | inf:OrderDate | inf:SegmentEffectiveDate |
                    inf:SegmentExpirationDate | inf:CancelDate | inf:NewBusinessEffectiveDate |
                    inf:NewBusinessExpirationDate | inf:RenewalEffectiveDate | inf:RenewalExpirationDate |
                    inf:QuestionDate | inf:ViolationDate | inf:ConvictionDate |
                    inf:EffectiveDate | inf:RatingDate | inf:AdvanceDate |
                    inf:SIDRevisionDate | inf:DriverLicensedDate |
                    inf:ESignatureDate | inf:UploadDate | inf:CancelDate |
                    inf:CancelProcessedDate | inf:CancelEffectiveDate | inf:CreatedDate |
                    inf:QuoteCreationDate | inf:QuoteModifiedDate | inf:QuoteExpirationDate |
                    inf:RateStartDate | inf:RateEndDate | inf:ChangeEffectiveDate | inf:PostDate |
                    inf:EffectiveDate | inf:ExpirationDate | inf:BirthDate |
                    inf:InstallmentDueDate | inf:CommercialDriverLicenseDate ">
    <xsl:element name="{name()}">
        <xsl:value-of
            select="concat(format-date(text(),'[Y0001]-[M01]-[D01]'), 'T00:00:00')" />
    </xsl:element>
</xsl:template>

虽然功能齐全,但这并不理想。我宁愿不必枚举我需要转换的每个元素,我宁愿指定一个需要转换的 TYPE。

(1) XSL 是否提供此功能?

(2)或者,有些元素名称在一个位置可能是 DATE,而在其他位置可能是 DATETIME。如果我知道父级的名称,是否有排除某些 DATETIME 元素的有效方法?

(3)最后,有没有人看到超出问题范围的改进空间?

一些上下文:原始映射是在 BusinessWorks 的编辑器中完成的,GUI 会在其中生成自己的映射文件,即数百行的 if/then/else 语句系列。对于一个 50k 的文档(我们的平均值),对于在不到 50 毫秒内完成其实际工作的 Web 服务,这相当于每次转换的近 20 毫秒开销。这是必须改进的瓶颈。

4

1 回答 1

2

只需使用

<xsl:template match="*[. castable as xs:date]">
 <!-- Your code here -->
</xsl:template>
于 2013-03-14T04:04:10.583 回答