【问题标题】:Flexible XSL Date / DateTime Transformation灵活的 XSL 日期/日期时间转换
【发布时间】:2013-03-02 02:02:10
【问题描述】:

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

这既烦人又麻烦。

为了提高 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 毫秒开销。这是必须改进的瓶颈。

【问题讨论】:

    标签: xslt tibco businessworks businessevents


    【解决方案1】:

    只需使用

    <xsl:template match="*[. castable as xs:date]">
     <!-- Your code here -->
    </xsl:template>
    

    【讨论】:

    • 如此简单,正是我所需要的。谢谢!
    • @JHarnach,不客气。是的,XSLT 既强大又优雅。观看 XSLT 3.0,了解几乎无法想象的新功能。
    猜你喜欢
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-13
    • 2014-07-01
    • 1970-01-01
    相关资源
    最近更新 更多