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/@crea开发者_StackOverflow社区teDate))">
<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
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?
精彩评论