XSL for-each loop but..

T

Tjerk Wolterink

Hello all,

i have a xsl:for-each loop like this:

<xsl:for-each select="xc:agendapunt[xc:datum/xc:year &gt; $time_year or (xc:datum/xc:year=$time_year and xc:datum/xc:month &gt; $time_month) or (xc:datum/xc:year=$time_year and xc:datum/xc:month=$time_month and xc:datum/xc:day &gt; $time_day)]">
<xsl:sort select="xc:datum/xc:year" data-type="number"/>
<xsl:sort select="xc:datum/xc:month" data-type="number"/>
<xsl:sort select="xc:datum/xc:day" data-type="number"/>
<xsl:if test="position(.) &lt; 10">
<li><xsl:value-of select="xc:datum/xc:display"/>: <xsl:value-of select="xc:titel"/>
<page:button-edit-delete module="agenda" id="{./xc:id}" multiple="agendapunt"/>
</li>
</xsl:if>
</xsl:for-each>


But this does not work. What i want to is that if there are more than 10 xc:agendapunt items
in the loop the loop should stop. How is this possible?? In someway is must count
the number of loops alreadty taken and only if that number is less than 10 is hould show
the output between the xsl:if
 
M

Martin Honnen

Tjerk Wolterink wrote:

i have a xsl:for-each loop like this:

<xsl:for-each select="xc:agendapunt[xc:datum/xc:year &gt; $time_year or
(xc:datum/xc:year=$time_year and xc:datum/xc:month &gt; $time_month) or
(xc:datum/xc:year=$time_year and xc:datum/xc:month=$time_month and
xc:datum/xc:day &gt; $time_day)]">
<xsl:sort select="xc:datum/xc:year" data-type="number"/>
<xsl:sort select="xc:datum/xc:month" data-type="number"/>
<xsl:sort select="xc:datum/xc:day" data-type="number"/>
<xsl:if test="position(.) &lt; 10">

The position function doesn't take an argument.
<li><xsl:value-of select="xc:datum/xc:display"/>: <xsl:value-of
select="xc:titel"/>
<page:button-edit-delete module="agenda" id="{./xc:id}"
multiple="agendapunt"/>
</li>
</xsl:if>
</xsl:for-each>


But this does not work. What i want to is that if there are more than 10
xc:agendapunt items
in the loop the loop should stop. How is this possible??

Can't you simply make sure the for-each only enumerates over 10 elements
e.g.
<xsl:for-each select="xc:agendapunt[...][positon() &lt; 11]">
 
T

Tjerk Wolterink

Martin said:
Tjerk Wolterink wrote:

i have a xsl:for-each loop like this:

<xsl:for-each select="xc:agendapunt[xc:datum/xc:year &gt; $time_year
or (xc:datum/xc:year=$time_year and xc:datum/xc:month &gt;
$time_month) or (xc:datum/xc:year=$time_year and
xc:datum/xc:month=$time_month and xc:datum/xc:day &gt; $time_day)]">
<xsl:sort select="xc:datum/xc:year" data-type="number"/>
<xsl:sort select="xc:datum/xc:month" data-type="number"/>
<xsl:sort select="xc:datum/xc:day" data-type="number"/>
<xsl:if test="position(.) &lt; 10">


The position function doesn't take an argument.
<li><xsl:value-of select="xc:datum/xc:display"/>:
<xsl:value-of select="xc:titel"/>
<page:button-edit-delete module="agenda" id="{./xc:id}"
multiple="agendapunt"/>
</li>
</xsl:if>
</xsl:for-each>


But this does not work. What i want to is that if there are more than
10 xc:agendapunt items
in the loop the loop should stop. How is this possible??


Can't you simply make sure the for-each only enumerates over 10 elements
e.g.
<xsl:for-each select="xc:agendapunt[...][positon() &lt; 11]">

ok but position() is that the current position in the loop or the position of the xc:agendapunt element in the source document?
 
M

Martin Honnen

Tjerk Wolterink wrote:

but position() is that the current position in the loop or the
position of the xc:agendapunt element in the source document?

position is defined here:
<http://www.w3.org/TR/xpath#function-position>
and says "returns a number equal to the context position from the
expression evaluation context."
Each XPath expression is evaluated within a context, a predicate like I
used e.g. [position() < 11] makes sure that the position refers to each
node in the nodeset selected before the predicate.
 
D

David Carlisle

position() does not take an argument so position(.) is a syntax error
(your xslt processor should have reported that, and stopped)

remove the . and you should be fine.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top