Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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 November 2nd, 2006, 07:09 PM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic Columns XHTML Table

First, the data:

<docroot>

<columns>
 <column heading="User ID" attributename="usrid" />
 <column heading="User" attributename="username" />
</columns>

<users>
    <user usrid="1243" firstname="John" lastname="Smith" username="coolKat1" lastlogged="3.12.2005" />
    <user usrid="5274" firstname="Sarah" lastname="Collins" username="collSar" lastlogged="6.22.2006" />
</users>

</docroot>


What I want to do is a match on user nodes and then make a pass through the column nodes to produce the resulting table:



<table><thead><th>User ID</th><th>User</th></thead>

 <tbody>

<tr><td>1243</td><td>coolKat1</td></tr>

<tr><td>5274</td><td>collSar</td></tr>

</tbody>

</table>



This allows me to change the order of the columns and which columns to display quite readily.

If the column headers and the resulting data in each column is based on the columns nodes, how can I process through the user nodes and then pass the element to a template to process the column nodes. I have looked through several approaches to this problem which would run very slowly, due to the use of Javascripting within the XSLT. Has anyone out there encountered this issue?



Thanks in advance



Paul
 
Old November 2nd, 2006, 08:09 PM
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

Try something like this:

<xsl:for-each select="/docroot/users"/>
  <xsl:variable name="u" select="."/>
  <tr>
  <xsl:for-each select="/docroot/columns/column">
    <td>
      <xsl:value-of select="$u/@*[name()=current()/@attributename]"/>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference




Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Columns tray99 XSLT 2 July 29th, 2008 01:25 PM
Dynamic Columns & Dynamic Grouping ??? nileshgambhava BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 1 March 24th, 2008 07:58 AM
Dynamic Columns & Dynamic Grouping ??? nileshgambhava SQL Server 2005 0 December 12th, 2006 12:45 AM
table height in xhtml gabrieldcr2 ASP.NET 1.x and 2.0 Application Design 1 August 23rd, 2006 10:46 AM
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.