【问题标题】:Saxon he 9.4 performance -xsltSaxon he 9.4 性能 -xslt
【发布时间】:2015-10-09 14:13:23
【问题描述】:

我在 xslt 中有以下两个模板:

<xsl:template name="calculateAbsoluteEntryNodeIndex">
    <!-- current 'entry' node -->
    <xsl:param name="entryNode"/>
    <!-- current 'entry' node index (position) in xml tree-->
    <xsl:param name="entryNodePosition"/>
    <xsl:choose>
        <!--if the current 'entry' node contains 'namest' attribute then its ('namest') value is treated as 
  the absolute index (of the current 'entry' node)-->
        <xsl:when test="$entryNode/@namest">
            <!--writing result-->
            <xsl:value-of select="number($entryNode/@namest)"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select="number($entryNode/@nameend)"/>
        </xsl:when>
        <xsl:otherwise>
            <!--getting last 'Nameend' attribute value-->
            <xsl:variable name="lastNameEndValue">
                <xsl:choose>
                    <!--check if exists any 'entry' node before the current 'entry' node (on the current 'row' level) having 'nameend' attribute defined 
        ('entry' has to have index number less than $entryNodePosition) -->
                    <xsl:when test="$entryNode/preceding-sibling::entry[@nameend]">
                        <!--get 'named' attribute value of the last matched "entry" node and convert it to number -->
                        <xsl:value-of select="number(($entryNode/preceding-sibling::entry/@nameend)[last()])"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="0"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <!--getting 'entry' node index of the matched 'Nameend' attribute  -->
            <xsl:variable name="lastNameendNodePosition">
                <xsl:choose>
                    <!-- if lastNameEndValue != 0 -->
                    <xsl:when test="$lastNameEndValue != '0'">
                        <!-- calculate index of the 'entry' node matched in $lastNameEndValue selection =>it is done by counting all preceding siblings of the node matched in 
              $lastNameEndValue increased by 1-->
                        <xsl:value-of select="count(($entryNode/preceding-sibling::entry[@nameend])[last()]/preceding-sibling::entry) + 1"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="0"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <!--writing result-->
            <xsl:value-of select="$entryNodePosition - $lastNameendNodePosition + $lastNameEndValue"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select="$entryNodePosition - $lastNameendNodePosition + $lastNameEndValue"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

还有

我运行了一些与 saxon he 9.4.-TP:profile.html 相关的分析 模板calculateAbsoluteEntryNodeIndex 25268028 在此模板上花费的总时间为 174966.587 毫秒。 整个 xslts 的执行总时间为:337196.696 毫秒。 似乎在转换大约 14000 行 xml 的大表时遇到了问题。知道这里可能会出现什么问题。

表的结构是。

<?xml version="1.0" encoding="UTF-8"?>
<table tabledef="excel">
    <tgroup cols="1">
        <colspec colname="1" colnum="1" colwidth="100%"/>
        <thead>
            <row>
                <entry morerows="1">
                    <p>
                        Text 
                    </p>
                </entry>
        </thead>
        <tbody>
            <row>
                <entry align="left">
                    <p>1</p>
                </entry>
            </row>
        </tbody>
    </tgroup>
</table>

【问题讨论】:

    标签: performance saxon


    【解决方案1】:

    这里没有足够的信息:例如,row 中的兄弟entry 元素的典型数量是多少?这个模板多久执行一次?我猜你可能每个条目都执行一次,而且它显然是条目数的二次方。

    表达式$entryNode/preceding-sibling::entry[@nameend]的重复显然是浪费。

    在不知道代码实际在做什么的情况下,很难就是否有其他更快的编写方式提供建议。也许使用 xsl:number 进行一些计数会更好;这很难说。或者,不要执行独立处理每个条目的“for-each”,而是考虑执行通过节点向前工作的兄弟递归,传递有关已处理节点的参数信息,因此您不必向后搜索到前面的兄弟节点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-30
      • 2017-01-16
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-03
      • 2018-06-11
      相关资源
      最近更新 更多