XSL

Author Thread:how to iterate xsl:for-loop
chiru123
how to iterate xsl:for-loop
Posted:Friday, July 15, 2005 8:51 AM (UMST)

Hi,

 

Can we find any function similar to "for(x;y;z) loop" in xsl or xpath.

 

Thanks


Average Rating:


Comments:


Author Thread:
asktech
how to iterate xsl:for-loop
Posted: Friday, July 15, 2005 9:39 AM (UMST)

Hi,

Once a variable is defined, you cannot change its value so if you just want to iterate over the integers, for example below code extract the first ten:

 

<xsl:for-each select="//*[position() &lt;= 10]">
    ...
</xsl:for-each>

 

where position() will go from 1 to 10

 

Hope it helps!!

Average Rating:
timsmith
how to iterate xsl:for-loop
Posted: Friday, July 15, 2005 10:03 AM (UMST)

Hi,
To loop it you can use something like this

 

<xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
</xsl:for-each>

 

Thanks
Tim

Average Rating:
chiru123
how to iterate xsl:for-loop
Posted: Monday, July 18, 2005 8:13 AM (UMST)

Hi timsmith,

 

Thankyou for your reply. I was doing something similar to what you have mentioned. But I have some problem and please see my code below

 

Assume that all the parameters are declared and this is the code which i am trying to use for displaying the data

 

xsl file:

 

<table>

<tr>

<td class="label">Name</td>
<xsl:for-each select="Data/Info">
<xsl:if test="position() >= $nodeno2 and position() &lt; $nodeno3">
<td><xsl:value-of select= "Common/Size"/></td>
</xsl:if>
</xsl:for-each>

</tr>

</table>

 

results:

---------------------------------

Name  |  value  | value |  value |

---------------------------------

Name  |  value  | value |  value |

---------------------------------

 

This looks fine if I have all the two row value data in my xml file. But I want to display only one row i have only one row value data in my xml file. With the above code I was able to do that but the end result is something like below.

 

---------------------------------

Name  |  value  | value |  value |

---------------------------------

Name  |

---------------------------------

but I don't want to display the "Name" in the second row if don't have the data in my xml. Can you help in getting me in some solution to this problem. Please post me if you have some questions or if you don't understand my question.

 

 

Average Rating:
asktech
how to iterate xsl:for-loop
Posted: Monday, July 18, 2005 10:07 AM (UMST)

Hi,

You need to check before you write a column for name if there is any data  for that row, below is the code which do the check first and then print 'Name' column

 

<table>
<tr>
<xsl:choose>
  <xsl:when test="value &gt; 10">  <!-- Do your check here if you have any data or not -->
    <td class="label">Name</td>
    <xsl:for-each select="Data/Info">
   
     <xsl:if test="position() >= $nodeno2 and position() &lt; $nodeno3">
   
      <td><xsl:value-of select= "Common/Size"/></td>
   
     </xsl:if>
    </xsl:for-each>
  </xsl:when>
  <xsl:otherwise>
   
  </xsl:otherwise>
</xsl:choose>
</tr>
</table>

 

Hope it helps!!

Average Rating:
chiru123
how to iterate xsl:for-loop
Posted: Tuesday, July 19, 2005 7:58 AM (UMST)

Hi Asktech,

 

Thankyou for your reply. I just saw your code and feel that it will work. I will let you what is my end result.

 

Thanks.

 

Ferotech Solution Services Inc.