XSL for-each loop but..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tjerk Wolterink

    XSL for-each loop but..

    Hello all,

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

    <xsl:for-each select="xc:agen dapunt[xc:datum/xc:year &gt; $time_year or (xc:datum/xc:year=$time_y ear and xc:datum/xc:month &gt; $time_month) or (xc:datum/xc:year=$time_y ear and xc:datum/xc:month=$time_ month and xc:datum/xc:day &gt; $time_day)]">
    <xsl:sort select="xc:datu m/xc:year" data-type="number"/>
    <xsl:sort select="xc:datu m/xc:month" data-type="number"/>
    <xsl:sort select="xc:datu m/xc:day" data-type="number"/>
    <xsl:if test="position( .) &lt; 10">
    <li><xsl:valu e-of select="xc:datu m/xc:display"/>: <xsl:value-of select="xc:tite l"/>
    <page:button-edit-delete module="agenda" id="{./xc:id}" multiple="agend apunt"/>
    </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
  • Martin Honnen

    #2
    Re: XSL for-each loop but..



    Tjerk Wolterink wrote:

    [color=blue]
    > i have a xsl:for-each loop like this:
    >
    > <xsl:for-each select="xc:agen dapunt[xc:datum/xc:year &gt; $time_year or
    > (xc:datum/xc:year=$time_y ear and xc:datum/xc:month &gt; $time_month) or
    > (xc:datum/xc:year=$time_y ear and xc:datum/xc:month=$time_ month and
    > xc:datum/xc:day &gt; $time_day)]">
    > <xsl:sort select="xc:datu m/xc:year" data-type="number"/>
    > <xsl:sort select="xc:datu m/xc:month" data-type="number"/>
    > <xsl:sort select="xc:datu m/xc:day" data-type="number"/>
    > <xsl:if test="position( .) &lt; 10">[/color]

    The position function doesn't take an argument.
    [color=blue]
    > <li><xsl:valu e-of select="xc:datu m/xc:display"/>: <xsl:value-of
    > select="xc:tite l"/>
    > <page:button-edit-delete module="agenda" id="{./xc:id}"
    > multiple="agend apunt"/>
    > </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??[/color]

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




    --

    Martin Honnen

    Comment

    • Tjerk Wolterink

      #3
      Re: XSL for-each loop but..

      Martin Honnen wrote:
      [color=blue]
      >
      >
      > Tjerk Wolterink wrote:
      >
      >[color=green]
      >> i have a xsl:for-each loop like this:
      >>
      >> <xsl:for-each select="xc:agen dapunt[xc:datum/xc:year &gt; $time_year
      >> or (xc:datum/xc:year=$time_y ear and xc:datum/xc:month &gt;
      >> $time_month) or (xc:datum/xc:year=$time_y ear and
      >> xc:datum/xc:month=$time_ month and xc:datum/xc:day &gt; $time_day)]">
      >> <xsl:sort select="xc:datu m/xc:year" data-type="number"/>
      >> <xsl:sort select="xc:datu m/xc:month" data-type="number"/>
      >> <xsl:sort select="xc:datu m/xc:day" data-type="number"/>
      >> <xsl:if test="position( .) &lt; 10">[/color]
      >
      >
      > The position function doesn't take an argument.
      >[color=green]
      >> <li><xsl:valu e-of select="xc:datu m/xc:display"/>:
      >> <xsl:value-of select="xc:tite l"/>
      >> <page:button-edit-delete module="agenda" id="{./xc:id}"
      >> multiple="agend apunt"/>
      >> </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??[/color]
      >
      >
      > Can't you simply make sure the for-each only enumerates over 10 elements
      > e.g.
      > <xsl:for-each select="xc:agen dapunt[...][positon() &lt; 11]">
      >
      >
      >
      >[/color]

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

      Comment

      • Martin Honnen

        #4
        Re: XSL for-each loop but..



        Tjerk Wolterink wrote:

        [color=blue]
        > but position() is that the current position in the loop or the
        > position of the xc:agendapunt element in the source document?[/color]

        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.

        --

        Martin Honnen

        Comment

        • David Carlisle

          #5
          Re: XSL for-each loop but..


          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

          Comment

          Working...