www.webdeveloper.com
Results 1 to 2 of 2

Thread: A loop based on specified count

  1. #1
    Join Date
    Nov 2008
    Posts
    4

    A loop based on specified count

    I have this structure:

    Code:
    <data>
       <tot_num_in_list>1</tot_num_in_list>
       <person_info>
          <name/>
          <address/>
          <phone/>
       </person_info>
    </data>
    Inside the data-element there is 100 person_info-elements (I just wrote one for making it shorter to write). The tot_num_in_list-element contains the number of person_info-elements that is returned from the database with content. So, in this case I get in return from the database one person_info-element that contains a name, address and a phonenumber, and I also get 99 empty.

    How do I exctract these data's based on the tot_num_in_list-element? Instead of looping through a 100 elements, I just want to go through the first 'n' elements based on the tot_num_in_list-element.

    How can I achieve this?

  2. #2
    Join Date
    Mar 2008
    Location
    Bordeaux, France
    Posts
    57
    If you want to use an xsl:for-each loop :
    Code:
    <xsl:template match="data">
      <xsl:variable name="tot" select="tot_num_in_list"/>
      <xsl:for-each select="person-info[position() &lt;= $tot]">
         ...
      </xsl:for-each>
    </xsl:template>
    If you want to use templates :
    Code:
    <xsl:template match="data">
      <xsl:variable name="tot" select="tot_num_in_list"/>
      <xsl:apply-templates select="person-info[position() &lt;= $tot]"/>
    </xsl:template>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles