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 June 7th, 2006, 10:51 AM
Authorized User
Join Date: Jun 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to create Dynamic Text in xsl


I have the following XML:


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.


Old June 8th, 2006, 09:06 AM
Registered User
Join Date: Mar 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts

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="/">
<xsl:variable name="counter" select="//MaxLevel"/>

<xsl:for-each select="1 to $counter">
<xsl:value-of select="."/>

Old June 8th, 2006, 10:09 AM
Authorized User
Join Date: Jun 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks kapy_kal, I really appreciate it.

Old June 8th, 2006, 05:26 PM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

In XSLT 2.0,

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

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>

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

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

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