Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 20th, 2015, 10:35 AM
Authorized User
Points: 151, Level: 3
Points: 151, Level: 3 Points: 151, Level: 3 Points: 151, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.

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

Code:
<xsl:template name="table" match="tb">
    <table class="frame-all">
        <xsl:call-template name="cols"/>
        <xsl:apply-templates/>
    </table>
</xsl:template>
<xsl:template name="cols">
    <xsl:variable name="numbr" select="number(./@class)"/>
    <xsl:variable name="colcnt" select="format-number(100 div $numbr,'##.#')"/>
    <colgroup>
        <!-- I want the condition here-->
    </colgroup>
</xsl:template>
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.

Code:
<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.

Thanks
Reply With Quote
  #2 (permalink)  
Old April 23rd, 2015, 06:32 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 2.0 use

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

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:07 PM.


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