所以我有以下xml输入:
<Readings>
<Data>
<Reading TimeStamp="2013/07/08 18:00" RawReading="0.328" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/08 19:00" RawReading="0.454" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/08 20:00" RawReading="1.963" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/08 21:00" RawReading="3.123" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/08 22:00" RawReading="2.456" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/08 23:00" RawReading="1.851" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 00:00" RawReading="1.123" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 01:00" RawReading="1.701" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 02:00" RawReading="1.675" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 03:00" RawReading="1.725" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 04:00" RawReading="0.260" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 05:00" RawReading="0.036" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 06:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 07:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 08:00" RawReading="0.777" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 09:00" RawReading="0.222" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 10:00" RawReading="0.222" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 11:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 12:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 13:00" RawReading="0.011" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 14:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 15:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 16:00" RawReading="0.311" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 17:00" RawReading="0.845" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 18:00" RawReading="0.794" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 19:00" RawReading="1.661" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 20:00" RawReading="1.703" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 21:00" RawReading="1.434" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 22:00" RawReading="1.000" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 23:00" RawReading="0.864" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 00:00" RawReading="0.726" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 01:00" RawReading="0.754" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 02:00" RawReading="0.780" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 03:00" RawReading="0.747" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 04:00" RawReading="0.707" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 05:00" RawReading="0.768" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 06:00" RawReading="0.669" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 07:00" RawReading="0.183" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 08:00" RawReading="0.159" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 09:00" RawReading="0.222" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 10:00" RawReading="0.266" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 11:00" RawReading="0.158" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 12:00" RawReading="0.104" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 13:00" RawReading="0.133" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 14:00" RawReading="0.314" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 15:00" RawReading="0.141" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 16:00" RawReading="1.572" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 17:00" RawReading="1.557" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 18:00" RawReading="1.805" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 19:00" RawReading="0.638" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 20:00" RawReading="0.251" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 21:00" RawReading="2.270" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 22:00" RawReading="1.972" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 23:00" RawReading="0.914" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/11 00:00" RawReading="0.848" QualityFlag="R 00 00"/>
</Data>
</Readings>
我需要它看起来像这样
<Readings>
<Data>
<Reading TimeStamp="2013/07/08 18:00" RawReading="0.328" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/08 19:00" RawReading="0.454" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/08 20:00" RawReading="1.963" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/08 21:00" RawReading="3.123" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/08 22:00" RawReading="2.456" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/08 23:00" RawReading="1.851" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 00:00" RawReading="1.123" QualityFlag="R 00 00"/>
</Data>
<Data>
<Reading TimeStamp="2013/07/09 01:00" RawReading="1.701" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 02:00" RawReading="1.675" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 03:00" RawReading="1.725" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 04:00" RawReading="0.260" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 05:00" RawReading="0.036" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 06:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 07:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 08:00" RawReading="0.777" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 09:00" RawReading="0.222" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 10:00" RawReading="0.222" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 11:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 12:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 13:00" RawReading="0.011" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 14:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 15:00" RawReading="0.111" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 16:00" RawReading="0.311" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 17:00" RawReading="0.845" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 18:00" RawReading="0.794" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 19:00" RawReading="1.661" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 20:00" RawReading="1.703" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 21:00" RawReading="1.434" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 22:00" RawReading="1.000" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/09 23:00" RawReading="0.864" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 00:00" RawReading="0.726" QualityFlag="R 00 00"/>
</Data>
<Data>
<Reading TimeStamp="2013/07/10 01:00" RawReading="0.754" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 02:00" RawReading="0.780" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 03:00" RawReading="0.747" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 04:00" RawReading="0.707" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 05:00" RawReading="0.768" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 06:00" RawReading="0.669" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 07:00" RawReading="0.183" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 08:00" RawReading="0.159" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 09:00" RawReading="0.222" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 10:00" RawReading="0.266" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 11:00" RawReading="0.158" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 12:00" RawReading="0.104" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 13:00" RawReading="0.133" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 14:00" RawReading="0.314" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 15:00" RawReading="0.141" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 16:00" RawReading="1.572" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 17:00" RawReading="1.557" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 18:00" RawReading="1.805" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 19:00" RawReading="0.638" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 20:00" RawReading="0.251" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 21:00" RawReading="2.270" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 22:00" RawReading="1.972" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/10 23:00" RawReading="0.914" QualityFlag="R 00 00"/>
<Reading TimeStamp="2013/07/11 00:00" RawReading="0.848" QualityFlag="R 00 00"/>
</Data>
</Readings>
当时间戳 = 00:00 时需要中断。我曾尝试使用位置、变量等,但我对此太陌生了,不知道我做错了什么!这是我的代码:
<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:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="Data">
<xsl:copy-of select="@*"/>
<xsl:variable name="cutoff"/>
<xsl:if test="Reading[contains(@TimeStamp,'01:00')]">
<xsl:value-of select="Reading[@TimeStamp]"/>
</xsl:if>
<xsl:apply-templates select="Reading[position() mod 24 = 1]">
<xsl:with-param name="pos" select="$cutoff"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Reading">
<xsl:param name="pos"/>
<Data>
<xsl:copy-of select=".|following-sibling::*[position() < pos]"/>
</Data>
</xsl:template>
请帮忙!