1

所以我有以下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() &lt; pos]"/>
    </Data>
</xsl:template>

请帮忙!

4

2 回答 2

0

Here's an option if you can switch to XSLT 2.0...

XML Input

<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>

XSLT 2.0

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

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

    <xsl:template match="Data">
        <xsl:for-each-group select="Reading" group-ending-with="*[matches(@TimeStamp,' 00:00$')]">
            <Data>
                <xsl:apply-templates select="current-group()"/>
            </Data>
        </xsl:for-each-group>
    </xsl:template>

</xsl:stylesheet>

XML Output

<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>
于 2013-07-24T19:15:17.427 回答
0

请试一试:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

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

  <xsl:template match="Data">
    <xsl:apply-templates
      select="Reading[1] | 
              Reading[substring-after(
                         preceding-sibling::Reading[1]/@TimeStamp, ' ') = 
                      '00:00']"
      mode="startRun"/>
  </xsl:template>

  <xsl:template match="Reading" mode="startRun">
    <Data>
      <xsl:apply-templates select="." />
    </Data>
  </xsl:template>

  <xsl:template match="Reading">
    <xsl:call-template name="copy" />
    <xsl:variable name="shouldStop"
                  select="substring-after(@TimeStamp, ' ') = '00:00'" />
    <xsl:apply-templates 
      select="following-sibling::Reading[1][not($shouldStop)]"/>
  </xsl:template>
</xsl:stylesheet>

在您的示例输入上运行时,它会产生您描述的输出。

于 2013-07-24T18:58:26.337 回答