Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XSLT1.0:分组和选择计算最小值的时间_Xslt_Xpath - Fatal编程技术网

XSLT1.0:分组和选择计算最小值的时间

XSLT1.0:分组和选择计算最小值的时间,xslt,xpath,Xslt,Xpath,我试图按如下方式计算XML中一组JMeter结果的最小和最大时间,但当我使用。/httpSample[@lb=current()/@lb]/@t调用我的最小模板时,它无法正确计算时间 <httpSample t="758" lt="0" ts="1330176857546" s="false" lb="/app1/" tn="space Guest Users 2-4" dt="text" by="1446"/> <httpSample t="213" lt="0" ts="1

我试图按如下方式计算XML中一组JMeter结果的最小和最大时间,但当我使用
。/httpSample[@lb=current()/@lb]/@t
调用我的最小模板时,它无法正确计算时间

<httpSample t="758" lt="0" ts="1330176857546" s="false" lb="/app1/" tn="space Guest Users 2-4" dt="text" by="1446"/>
<httpSample t="213" lt="0" ts="1330176858088" s="false" lb="/app2/" tn="space Logged In Users 1-28" dt="text" by="1446"/>
<httpSample t="153" lt="0" ts="1330176858088" s="false" lb="/app2/" tn="space Logged In Users 1-28" dt="text" by="1446"/>
<httpSample t="113" lt="0" ts="1330176858088" s="false" lb="/app2/" tn="space Logged In Users 1-28" dt="text" by="1446"/>
<httpSample t="153" lt="0" ts="1330176858149" s="false" lb="/app3/" tn="space Logged In Users 1-29" dt="text" by="1446"/>
<httpSample t="340" lt="0" ts="1330176857967" s="false" lb="/app3/" tn="space Logged In Users 1-26" dt="text" by="1446"/>

我建议你做不同的分组。下面是XSLT2.0解决方案的方向-如果您想要XSLT1.0解决方案,请告诉我。加强以下内容应该不难

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
        <output>
            <xsl:for-each-group select="root/httpSample" group-by="@lb">
                <httpSampleGroup>
                    <lb><xsl:value-of select="current-grouping-key()"/></lb>
                    <minT><xsl:value-of select="min(current-group()/@t)"/></minT>
                </httpSampleGroup>
            </xsl:for-each-group>
        </output>
    </xsl:template>
</xsl:stylesheet>

通过您的输入(加上根节点),这将

<?xml version="1.0" encoding="UTF-8"?>
<output>
    <httpSampleGroup>
        <lb>/app1/</lb>
        <minT>758</minT>
    </httpSampleGroup>
    <httpSampleGroup>
        <lb>/app2/</lb>
        <minT>113</minT>
    </httpSampleGroup>
    <httpSampleGroup>
        <lb>/app3/</lb>
        <minT>153</minT>
    </httpSampleGroup>
</output>

/附件1/
758
/附件2/
113
/附件3/
153

我只稍微触碰了一下您的代码,现在它可以正常工作了

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

 <xsl:template match="/">
    <xsl:for-each select=
    "/testResults/httpSample[not(@lb = preceding::*/@lb)]">

                <xsl:variable name="lab" select="@lb" />
                <xsl:variable name="count" select="count(../httpSample[@lb = current()/@lb])" />
                <xsl:variable name="failureCount" select="count(../httpSample[@lb = current()/@lb][attribute::s='false'])" />
                <xsl:variable name="successCount" select="count(../httpSample[@lb = current()/@lb][attribute::s='true'])" />
                <xsl:variable name="successPercent" select="$successCount div $count" />
                <xsl:variable name="totalTime" select="sum(../httpSample[@lb = current()/@lb]/@t)" />
                <xsl:variable name="averageTime" select="$totalTime div $count" />

                <xsl:message>
                    times:
                     <xsl:for-each select="../httpSample[@lb = current()/@lb]">
                       <xsl:if test="not(position() = 1)">,</xsl:if>
                       <xsl:value-of select="@t"/>
                     </xsl:for-each>
                </xsl:message>

                <xsl:variable name="minTime">
                    <xsl:call-template name="min">
                        <xsl:with-param name="nodes" select="../httpSample[@lb = current()/@lb]/@t" />
                    </xsl:call-template>
                </xsl:variable>

                Min time: <xsl:value-of select="$minTime"/>
   </xsl:for-each>
 </xsl:template>

     <xsl:template name="min">
        <xsl:param name="nodes" select="/.." />

        <!-- Broken when we get here -->
        <xsl:choose>
            <xsl:when test="not($nodes)">NaN</xsl:when>
            <xsl:otherwise>
                <xsl:for-each select="$nodes">
                    <xsl:sort data-type="number" />
                    <xsl:if test="position() = 1">
                        <xsl:value-of select="number(.)" />
                    </xsl:if>
                </xsl:for-each>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
<testResults>
    <httpSample t="758" lt="0" ts="1330176857546"
    s="false" lb="/app1/"
    tn="space Guest Users 2-4" dt="text"
    by="1446"/>
    <httpSample t="213" lt="0" ts="1330176858088"
    s="false" lb="/app2/"
    tn="space Logged In Users 1-28" dt="text"
    by="1446"/>
    <httpSample t="153" lt="0" ts="1330176858088"
    s="false" lb="/app2/"
    tn="space Logged In Users 1-28" dt="text"
    by="1446"/>
    <httpSample t="113" lt="0" ts="1330176858088"
    s="false" lb="/app2/"
    tn="space Logged In Users 1-28" dt="text"
    by="1446"/>
    <httpSample t="153" lt="0" ts="1330176858149"
    s="false" lb="/app3/"
    tn="space Logged In Users 1-29" dt="text"
    by="1446"/>
    <httpSample t="340" lt="0" ts="1330176857967"
    s="false" lb="/app3/"
    tn="space Logged In Users 1-26" dt="text"
    by="1446"/>
</testResults>
<testResults>
    <httpSample t="758" lt="0" ts="1330176857546"
    s="false" lb="/app1/"
    tn="space Guest Users 2-4" dt="text"
    by="1446"/>
    <httpSample t="213" lt="0" ts="1330176858088"
    s="false" lb="/app2/"
    tn="space Logged In Users 1-28" dt="text"
    by="1446"/>
    <httpSample t="153" lt="0" ts="1330176858088"
    s="false" lb="/app2/"
    tn="space Logged In Users 1-28" dt="text"
    by="1446"/>
    <httpSample t="113" lt="0" ts="1330176858088"
    s="false" lb="/app2/"
    tn="space Logged In Users 1-28" dt="text"
    by="1446"/>
    <httpSample t="153" lt="0" ts="1330176858149"
    s="false" lb="/app3/"
    tn="space Logged In Users 1-29" dt="text"
    by="1446"/>
    <httpSample t="340" lt="0" ts="1330176857967"
    s="false" lb="/app3/"
    tn="space Logged In Users 1-26" dt="text"
    by="1446"/>
</testResults>
            Min time: 758

            Min time: 113

            Min time: 153