Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
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 June 7th, 2006, 10:51 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to create Dynamic Text in xsl

Hi,

I have the following XML:

<sm>
    <MaxLevel>3</MaxLevel>
</sm>

I want to be able to use this and create column headings for a table. So How can I create the following:

Level1 Level2 Level3

Please Help. I am really struggling with this xsl and I am totally new to xsl, even though I have learned so much during the past two days, nothing is helping me with what I have to implement :( Thanks.

NewToXSL

Reply With Quote
  #2 (permalink)  
Old June 8th, 2006, 09:06 AM
Registered User
 
Join Date: Mar 2006
Location: , , Canada.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
you could solve your problem as follows (I added the html tags, but you can remove them to add your table headers)
<xsl:template match="/">
<table>
<tbody>
<xsl:variable name="counter" select="//MaxLevel"/>

<xsl:for-each select="1 to $counter">
<th>
<xsl:text>Level</xsl:text>
<xsl:value-of select="."/>
</th>
</xsl:for-each>
</tbody>
</table>
</xsl:template>

Reply With Quote
  #3 (permalink)  
Old June 8th, 2006, 10:09 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks kapy_kal, I really appreciate it.



Reply With Quote
  #4 (permalink)  
Old June 8th, 2006, 05:26 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

In XSLT 2.0,

<xsl:for-each select="1 to /sm/MaxLevel">
  <th>Level<xsl:value-of select="."/></th>
</xsl:for-each>

In 1.0 this is ridiculously difficult. Either (a) write a template that outputs Level1 and then calls itself to output the remaining levels, passing two parameters: the current level and the level at which to stop; or (b), if there are sufficient nodes in the input document, do


<xsl:for-each select="//node()[position() &lt; /sm/MaxLevel]">
  <th>Level<xsl:value-of select="position()"/></th>
</xsl:for-each>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference 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
Dynamic xsl:include? rushman XSLT 7 October 16th, 2012 05:26 AM
Create generic XSL Template to create table Venkatachalapathy XSLT 5 March 11th, 2008 07:49 AM
Can't set text property of dynamic text box sreerajrs ASP.NET 1.0 and 1.1 Professional 1 May 31st, 2006 09:39 PM
Re: Dynamic html tables with xsl? purple XSLT 0 November 2nd, 2005 12:01 PM
XSL dynamic columns in a table Himansu Behera XSLT 1 July 1st, 2004 08:14 AM



All times are GMT -4. The time now is 10:34 AM.


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