代码之家  ›  专栏  ›  技术社区  ›  Martin Bring

累积最大值,为每个父记录计算

  •  0
  • Martin Bring  · 技术社区  · 16 年前

    是否有人使用了累积最大functoid并注意到性能问题?

    摘要
    如果要映射字段的最大值,可以使用functoid累积最大值。

    问题
    在使用了一段时间后,我们注意到大型文件的性能下降。

    检查XSLT ONE会注意到每个循环记录都进行了最大计算…

    可以将计算移动到父级,并在自定义XSL路径中指出新的XSLT,但我确实希望在映射工具中保持映射的可能性。

    有什么建议吗?

    亲切问候
    马丁带来

    http://martinbring.blogspot.com

    1 回复  |  直到 16 年前
        1
  •  3
  •   Martin Bring    16 年前

    通过去掉累积的最大值并添加3个脚本functoid,以另一种方式进行计算,解决了这个问题。 绘图时间减少了40倍。

    11MB,10000行,以前在200分钟内被映射,现在在5分钟内被映射。

    解决方案
    一个脚本functoid“inline xslt call template”,没有输入或输出,包含exslt中库的max()部分 Math library found here . 我没有使用整个库,而是解压缩文件并“提取”max()模板。

     <xsl:template name="GetMax">
       <xsl:param name="nodes" /> 
    
        <xsl:choose>
          <xsl:when test="not($nodes)">NaN</xsl:when> 
          <xsl:otherwise>
            <xsl:for-each select="$nodes">
              <xsl:sort data-type="number" order="descending" /> 
              <xsl:if test="position() = 1">
              <xsl:value-of select="number(.)" /> 
            </xsl:if>
           </xsl:for-each>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:template>
    

    一个脚本functoid“inline xslt call template”,没有输入或输出,其中包含一个变量,该变量在模板上选择属性点,并将节点设置为要计算

    <xsl:variable name="var:MaxValueDate">
        <xsl:call-template name ="GetMax">
                <xsl:with-param name ="nodes" select="Root//Parent/ValueToCalculate" />
        </xsl:call-template>
    </xsl:variable>  
    

    一个脚本functoid,“inline xslt”带有一个输出,使用变量用其值填充输出元素。

    <OutputElement>
            <xsl:value-of select="$var:MaxValueDate" />
    </OutputElement>
    

    哇!