gpt4 book ai didi

xslt - for-each 中 'hits' 的计数

转载 作者:行者123 更新时间:2023-12-02 04:17:19 25 4
gpt4 key购买 nike

我有下面的代码。在 if-sentenses 返回 true 并执行代码块 4 次后,我会让 for-each 停止运行。因为我不知道代码块何时执行了 4 次,所以我不能使用我的第一个想法 position()。

任何帮助将不胜感激。

<xsl:for-each select="$itm//item[@template='news item']">
<xsl:sort select="sc:fld('start date',.)" data-type="text" order="descending"/>
<xsl:if test="sc:formatdate($date,'yyyyMMddHHmm') &gt; sc:formatdate(sc:fld('start date',.),'yyyyMMddHHmm')">
<xsl:if test="sc:formatdate($date,'yyyyMMddHHmm') &lt; sc:formatdate(sc:fld('end date',.),'yyyyMMddHHmm')">
<!--EXECUTE A CODE BLOCK-->
</xsl:if>
</xsl:if>
</xsl:for-each>

最佳答案

<!-- convenience variables -->
<xsl:variable name="dtFormat" select="'yyyyMMddHHmm'" />
<xsl:variable name="theDate" select="sc:formatdate($date, $dtFormat)" />

<!-- don't loop over nodes testing a condition on each one separately,
just select the interesting ones directly -->
<xsl:variable name="MatchingFields" select="
$itm//item[@template='news item'][
sc:formatdate(sc:fld('start date', .), $dtFormat) &lt; $theDate
and
sc:formatdate(sc:fld('end date', .), $dtFormat) &gt; $theDate
]
" />

<!-- now do something with the nodes -->
<xsl:for-each select="$MatchingFields">
<xsl:sort select="sc:fld('start date',.)" data-type="text" order="descending"/>
<!--EXECUTE A CODE BLOCK-->
</xsl:for-each>

<!-- you can also count them (this is your "hit counter") -->
<xsl:value-of select="count($MatchingFields)" />

关于xslt - for-each 中 'hits' 的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2290525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com