不使用循环按位置获取节点

发布于 2024-11-15 09:27:24 字数 1793 浏览 0 评论 0原文

无论如何,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 &lt; $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 &lt; $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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃不饱 2024-11-22 09:27:24

你的台词:

<xsl:variable name="currentNode" select="$currentPage/*[position() = $currentCount]" />

很好。您应该询问(并检查自己)$currentPage/* 是否包含位置 $currentCount 处的节点。

此外,您正在写“尝试过这个,但似乎不起作用:”。您如何检查变量值?在模板中,您只是定义变量,没有显示其值的指令。您可以尝试使用:

<xsl:copy-of select="$currentNode"/>

<xsl:value-of select="$currentNode"/>

仍然“尝试过这个,但它似乎不起作用:”,这只是一个“也许”或者转换给您带来了错误?属于哪一类错误?

Your line:

<xsl:variable name="currentNode" select="$currentPage/*[position() = $currentCount]" />

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:

<xsl:copy-of select="$currentNode"/>

or

<xsl:value-of select="$currentNode"/>

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文