Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 20th, 2015, 10:35 AM
Authorized User
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default for loop and use the value

I've the below line in XML.

<tb class="3">
        <b>English words </b>
        <b>Arabic </b>
      <td al="r">
      <td>bear </td>
      <td al="r">new</td>
Here is my xslt.

<xsl:template name="table" match="tb">
    <table class="frame-all">
        <xsl:call-template name="cols"/>
<xsl:template name="cols">
    <xsl:variable name="numbr" select="number(./@class)"/>
    <xsl:variable name="colcnt" select="format-number(100 div $numbr,'##.#')"/>
        <!-- I want the condition here-->
This gives me output of 33.3. And I want to create 3 cols(the class attribute value). And for each col the name should be increment value. as below.

<col name="1" width="33.3"/>
<col name="2" width="33.3"/>
<col name="3" width="33.3"/>
please let me know, how can i get the above result.

Old April 23rd, 2015, 06:32 AM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

In XSLT 2.0 use

<xsl:for-each select="1 to $umbr">
  <col name="{.}" width="{$colcnt}"/>
In XSLT 1.0 use

<xsl:for-each select="(//node())[position() &lt;= $colcnt]">
  <col name="{position()}" width="{$colcnt}"/>
Michael Kay
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference

Similar Threads
Thread Thread Starter Forum Replies Last Post
For loop with Floating Point Loop Counter - pp. 150 shivesh BOOK: Ivor Horton's Beginning Visual C++ 2010 1 March 28th, 2012 09:31 AM
Array Loop skipping loop in VBA jeskit Access VBA 5 March 20th, 2012 10:03 AM
Loop twice, then inside loop select nodes?? JohnBampton XSLT 2 March 9th, 2009 05:21 AM
while loop mikedeepak Classic ASP Professional 3 October 11th, 2005 03:34 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.