如何通过匹配控制点时间戳的时间戳来获得状态



我想获得与控制点时间戳相匹配的状态。比赛不必匹配毫秒

我不确定该怎么做。

我正在使用XSLT 1.0 预期输出

<ProtectionOrderStatus>
    <ProtectionOrderStatusCode>SBJO</ProtectionOrderStatusCode>
    <ProtectionOrderStatusDate>2016-05-09</ProtectionOrderStatusDate>
</ProtectionOrderStatus>

我的XML 1.0代码

<?xml version="1.0" encoding="UTF-8"?>
<Integration>
    <ControlPoint Timestamp="5/9/2016 2:34:34 PM" UserID="Kuku">SAVE</ControlPoint>
    <ProtectionOrders>
        <ProtectionOrder Op="E" InternalProtectionOrderID="11831">
            <Statuses>
                <Status>
                    <Current>true</Current>
                    <Active>No</Active>
                    <Date>05/09/2016</Date>
                    <Type Word="DISMISSED">Dismissed</Type>
                    <TimestampCreate Op="A">05/09/2016 14:34:48:633</TimestampCreate>
                </Status>
                <Status Op="A">
                    <Current>false</Current>
                    <Active>Yes</Active>
                    <Date Op="A">05/09/2016</Date>
                    <Type Op="A" Word="SBJO">Signed By Judicial Officer</Type>
                    <TimestampCreate>05/09/2016 14:34:34:737</TimestampCreate>
                </Status>
                <Status>
                    <Current>false</Current>
                    <Active>No</Active>
                    <Date>12/30/2014</Date>
                    <Type Word="DRAFT">Draft</Type>
                    <TimestampCreate>05/09/2016 14:34:14:987</TimestampCreate>
                </Status>
            </Statuses>
        </ProtectionOrder>
    </ProtectionOrders>
</Integration>

我的XSLT代码

<?xml version="1.0" encoding="UTF-8"?>
    <ProtectionOrderStatus>
    <ProtectionOrderStatusCode>
        <xsl:value-of select="Statuses/Status/Type/@Word"/>
    </ProtectionOrderStatusCode>
    <ProtectionOrderStatusDate>
        <xsl:value-of select="Statuses/Status/Date"/>
    </ProtectionOrderStatusDate>
</ProtectionOrderStatus>

我的XSLT正在产生以下输出,这是错误的

        <ProtectionOrderStatus>
        <ProtectionOrderStatusCode>DISMISSED</ProtectionOrderStatusCode>
        <ProtectionOrderStatusDate>2016-05-09</ProtectionOrderStatusDate>
    </ProtectionOrderStatus>

以下样式表:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="ctl" select="Integration/ControlPoint/@Timestamp"/>
<xsl:variable name="date" select="substring-before($ctl, ' ')"/>
<xsl:variable name="time" select="substring-before(substring-after($ctl, ' '), ' ')"/>
<xsl:variable name="month" select="substring-before($date, '/')"/>  
<xsl:variable name="day" select="substring-before(substring-after($date, '/'), '/')"/>
<xsl:variable name="year" select="substring-after(substring-after($date, '/'), '/')"/>
<xsl:variable name="h12" select="substring-before($time, ':')"/>
<xsl:variable name="pm" select="contains($ctl,'PM')"/>
<xsl:variable name="h" select="$h12 mod 12 + 12 * $pm"/>
<xsl:variable name="ts">
    <xsl:value-of select="format-number($month, '00')"/>
    <xsl:text>/</xsl:text>
    <xsl:value-of select="format-number($day, '00')"/>
    <xsl:text>/</xsl:text>
    <xsl:value-of select="$year"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="$h"/>
    <xsl:text>:</xsl:text>
    <xsl:value-of select="substring-after($time, ':')"/>
</xsl:variable>
<xsl:template match="/">
    <xsl:variable name="status" select="//Status[starts-with(TimestampCreate, $ts)]"/>
    <ProtectionOrderStatus>
        <ProtectionOrderStatusCode>
            <xsl:value-of select="$status/Type/@Word"/>
        </ProtectionOrderStatusCode>
        <ProtectionOrderStatusDate>     
            <xsl:value-of select="$status/Date"/>
        </ProtectionOrderStatusDate>
    </ProtectionOrderStatus>
</xsl:template>
</xsl:stylesheet>

应用于您的示例输入,将返回:

<?xml version="1.0" encoding="UTF-8"?>
<ProtectionOrderStatus>
   <ProtectionOrderStatusCode>SBJO</ProtectionOrderStatusCode>
   <ProtectionOrderStatusDate>05/09/2016</ProtectionOrderStatusDate>
</ProtectionOrderStatus>

注意

  • 这假定TimestampCreate中的小时为不是零填充到双数(在这方面您的示例是模棱两可的);

  • 如果多个Status与条件匹配,则只会返回第一个值。

相关内容

  • 没有找到相关文章

最新更新