不使用循环按位置获取节点
无论如何,xslt 中是否有直接从列表中获取节点而不使用 for-each 循环的方法:
尝试过此操作,但似乎不起作用:
<xsl:variable name="currentNode" select="$currentPage/ * [position() = 4]" />
任何帮助将不胜感激。
只是补充一点:
<xsl:template name="checkmonth">
<xsl:param name="stringOfMonths" />
<xsl:param name="n" />
<xsl:param name="currentCount" />
<!--get node in list -->
<xsl:variable name="currentNode" select="$currentPage/ * [position() = $currentCount]" />
<xsl:variable name="dateOfNode" select="$currentNode" />
<xsl:choose>
<xsl:when test="not(contains($stringOfMonths,dateOfNode/@createDate))">
<xsl:value-of select="$dateOfNode/@createDate" />
<xsl:if test="$currentCount < $n">
<xsl:call-template name="checkmonth">
<xsl:with-param name="stringOfMonths" select="concat($stringOfMonths," ",$dateOfNode/@createDate />
<xsl:with-param name="n" select="$n" />
<xsl:with-param name="currentCount" select="$currentCount + 1" />
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$currentCount < $n">
<xsl:call-template name="checkmonth">
<xsl:with-param name="stringOfMonths" select="$stringOfMonths" />
<xsl:with-param name="n" select="$n" />
<xsl:with-param name="currentCount" select="$currentCount + 1" />
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
我有一个在不同日期创建的节点列表,我想生成一个仅包含这些节点创建月份的列表。 'n' 是列表中的节点总数
is there anyway in xslt to get a node from a list directly without using a for-each loop:
tried this but it didnt seem to work:
<xsl:variable name="currentNode" select="$currentPage/ * [position() = 4]" />
any help will be appreciated.
just to add to this:
<xsl:template name="checkmonth">
<xsl:param name="stringOfMonths" />
<xsl:param name="n" />
<xsl:param name="currentCount" />
<!--get node in list -->
<xsl:variable name="currentNode" select="$currentPage/ * [position() = $currentCount]" />
<xsl:variable name="dateOfNode" select="$currentNode" />
<xsl:choose>
<xsl:when test="not(contains($stringOfMonths,dateOfNode/@createDate))">
<xsl:value-of select="$dateOfNode/@createDate" />
<xsl:if test="$currentCount < $n">
<xsl:call-template name="checkmonth">
<xsl:with-param name="stringOfMonths" select="concat($stringOfMonths," ",$dateOfNode/@createDate />
<xsl:with-param name="n" select="$n" />
<xsl:with-param name="currentCount" select="$currentCount + 1" />
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$currentCount < $n">
<xsl:call-template name="checkmonth">
<xsl:with-param name="stringOfMonths" select="$stringOfMonths" />
<xsl:with-param name="n" select="$n" />
<xsl:with-param name="currentCount" select="$currentCount + 1" />
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
i have a list of nodes created on different dates, i want to generate a list of just the months these nodes were created. 'n' is the total number of nodes in the list
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的台词:
很好。您应该询问(并检查自己)
$currentPage/*
是否包含位置$currentCount
处的节点。此外,您正在写“尝试过这个,但似乎不起作用:”。您如何检查变量值?在模板中,您只是定义变量,没有显示其值的指令。您可以尝试使用:
或
仍然“尝试过这个,但它似乎不起作用:”,这只是一个“也许”或者转换给您带来了错误?属于哪一类错误?
Your line:
is fine. You should ask (and check yourself) if
$currentPage/*
contains a node at position$currentCount
.Moreover, you are writing "tried this but it didnt seem to work:". How did you check the variable value? Inside your template you are just defining the variable and there is no instruction to display its value. Can you try with:
or
Still "tried this but it didnt seem to work:", it's just a "maybe" or the transformation is throwing you an error? Which kind of error?