Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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
Performance xsl:选择另存为变量_Performance_Xslt - Fatal编程技术网

Performance xsl:选择另存为变量

Performance xsl:选择另存为变量,performance,xslt,Performance,Xslt,我正忙于尽可能提高xsl的性能。这就是我所拥有的 <xsl:when test=".//div[starts-with(@class,'ls-col ') or @class='ls-col']"> <xsl:apply-templates select=".//div[starts-with(@class,'ls-col ') or @class='ls-col']" mode="col"/> </xsl:when>` 有没有一种方法可以保存它并在

我正忙于尽可能提高xsl的性能。这就是我所拥有的

<xsl:when test=".//div[starts-with(@class,'ls-col ') or @class='ls-col']">
    <xsl:apply-templates select=".//div[starts-with(@class,'ls-col ') or @class='ls-col']" mode="col"/>
</xsl:when>`

有没有一种方法可以保存它并在应用模板中使用它。

在这种情况下,实际上不需要xsl:when。只需执行xsl:apply模板

<xsl:apply-templates 
   select=".//div[starts-with(@class,'ls-col ') or @class='ls-col']" mode="col"/>


如果没有匹配的div标记,那么xsl:apply-templates将不匹配任何内容,因此此时不会输出任何内容。因此,没有理由事先检查这些标记的存在。

正如Tim C所说,如果它是xsl:if,那么当条件不成立时,您可以依靠应用模板什么也不做。但如果存在“否则”分支,只需将条件放在变量中:

<xsl:variable name="c" select=".//div[starts-with(@class,'ls-col ') or @class='ls-col']"/>
<xsl:choose>
<xsl:when test="$c">
    <xsl:apply-templates select="$c" mode="col"/>
</xsl:when>
<xsl:otherwise>...

...

Hi。还有另一部分需要选择,因此如果没有div class=“lscol”,它将应用另一个模板。
<xsl:variable name="c" select=".//div[starts-with(@class,'ls-col ') or @class='ls-col']"/>
<xsl:choose>
<xsl:when test="$c">
    <xsl:apply-templates select="$c" mode="col"/>
</xsl:when>
<xsl:otherwise>...