我们正在从分组的消息周期中接收数据,我们需要将每个消息周期的每个值分成相应的小时周期。我们正在使用IF测试,但存在一些缺陷。
如果IF语句中的数据变量给我们1,则转换器将从正确的时间间隔中获取值并将其输出。有没有更干净的方法来获取值
我们正在使用此if语句
<xsl:template name="DataCheck">
<xsl:param name="hour"/>
<xsl:param name="Direction"/>
<xsl:param name="shortdayhour"/>
<xsl:for-each select="//*[local-name()='direction.code']/text()">
<xsl:choose>
<xsl:when test="//*[local-name()='direction.code']/text() = $Direction">
<xsl:variable name="starttime" select="substring(//*[local-name()='timeInterval']/text(),12,2)"/>
<xsl:variable name="endtimestring" select="substring(//*[local-name()='timeInterval']/text(),30,2)"/>
<xsl:variable name="shortdayfirsthour" select="substring(concat('0',($hour + $shortdayhour)),1,2)"/>
<xsl:variable name="endtime">
<xsl:choose>
<xsl:when test="$endtimestring = '00'">
<xsl:value-of select="'24'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$endtimestring"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$hour = $starttime or $shortdayfirsthour or ($hour > $starttime and $hour < $endtime) or (($endtime < $starttime or $endtimestring = $starttime) and (($hour > $starttime) or ($hour < $endtime)))">
<xsl:value-of select="'1'"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'0'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
输入
<InformationOrigin_TimeSeries>
<type>16G</type>
<Period>
<timeInterval>2019-01-10T05:00Z/2019-01-10T10:00Z</timeInterval>
<direction.code>Z02</direction.code>
<quantity.amount>262957</quantity.amount>
</Period>
<Period>
<timeInterval>2019-01-10T10:00Z/2019-01-11T03:00Z</timeInterval>
<direction.code>Z02</direction.code>
<quantity.amount>89054</quantity.amount>
</Period>
<Period>
<timeInterval>2019-01-11T03:00Z/2019-01-11T05:00Z</timeInterval>
<direction.code>Z03</direction.code>
<quantity.amount>89046</quantity.amount>
</Period>
</InformationOrigin_TimeSeries>
</Account>
输出
<Data TimeFrom="2019-07-10T04:00:00Z" TimeTo="2019-07-10T05:00:00Z" datacheck="111" count="3" Value="0"/>
<Data TimeFrom="2019-07-10T05:00:00Z" TimeTo="2019-07-10T06:00:00Z" datacheck="111" count="3" Value="0"/>
<Data TimeFrom="2019-07-10T06:00:00Z" TimeTo="2019-07-10T07:00:00Z" datacheck="111" count="3" Value="0"/>
<Data TimeFrom="2019-07-10T07:00:00Z" TimeTo="2019-07-10T08:00:00Z" datacheck="111" count="3" Value="0"/>
<Data TimeFrom="2019-07-10T08:00:00Z" TimeTo="2019-07-10T09:00:00Z" datacheck="111" count="3" Value="0"/>
<Data TimeFrom="2019-07-10T09:00:00Z" TimeTo="2019-07-10T10:00:00Z" datacheck="111" count="3" Value="0"/>