【发布时间】:2010-08-27 13:32:50
【问题描述】:
我正在开发一个 XSLT 1.0 样式表(并使用 xsltproc 应用它)。我脚本中的一个模板应该对给定父节点中的第一个 <sect1> 元素和最后一个 <sect1> 元素执行一些特殊处理。现在这种特殊处理是这样实现的:
<xsl:template match="sect1">
<xsl:if test="not(preceding-sibling::sect1)">
<!-- Special handling for first sect1 element goes here. -->
</xsl:if>
<!-- Common handling for all sect1 elements goes here. -->
<xsl:if test="not(following-sibling::sect1)">
<!-- Special handling for last sect1 element goes here. -->
</xsl:if>
</xsl:template>
我想知道(只是出于好奇,脚本的运行速度对我来说很好):有没有更有效的方法来做到这一点? XSLT 处理器是否可能会在第一次找到匹配项后停止组装 preceding-sibling::sect1 节点集,因为它知道它只需要找到一个或零个元素?
【问题讨论】:
标签: optimization xslt xpath