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
  #1 (permalink)  
Old December 20th, 2005, 11:12 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Putting dynamic data into columns

Greetings. I'm fairly new to XSLT and I have a problem.

I have a page that includes the following nodes:

  <xsl:template name="deptIndex">
    <xsl:variable name="colCount" select="3"/>
    <xsl:element name="p">
      Department Index
    </xsl:element>
    <xsl:element name="table">
    <xsl:for-each select="pcr_report/info/department[position() mod $colCount = 1]">
      <xsl:element name="tr">
        <xsl:apply-templates select=". | following-sibling::pcr_report/info/department[position() &lt; $colCount]"
            mode="deptIndexTD"/>
      </xsl:element>
    </xsl:for-each>
    </xsl:element>
  </xsl:template>

  <xsl:template match="department" mode="deptIndexTD">
    <xsl:element name="td">
      <xsl:element name="a">
        <xsl:attribute name="href">
          <xsl:value-of select="concat('#', .)"/>
        </xsl:attribute>
        <xsl:value-of select="."/>
      </xsl:element>
    </xsl:element>
  </xsl:template>

These nodes display an index of departments at the top of a larger page.

Currently they display simply as a very long vertical list.

I need them to display in 5 columns like this:

Dept1 Dept5 Dept9 Dept13 Dept17
Dept2 Dept6 Dept10 Dept14 Dept18
Dept3 Dept7 Dept11 Dept15 Dept19
Dept4 Dept8 Dept12 Dept16 Dept20

I saw this thread: http://p2p.wrox.com/topic.asp?TOPIC_...hTerms=columns which I think addresses the issue, but I must admit that I wasn't able to follow it.

Any help would be appreciated.

  #2 (permalink)  
Old December 20th, 2005, 08:23 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

You've got a context problem with this code:

<xsl:for-each select="pcr_report/info/department[position() mod $colCount = 1]">
      <xsl:element name="tr">
        <xsl:apply-templates select=". | following-sibling::pcr_report/info/department[position() &lt; $colCount]"

You haven't shown your source document, but I suspect that a department doesn't have a following-sibling::pcr_report. You probably want to go up two levels first: ../../following-sibling::pcr_report.

You've got some awfully long-winded code here. Instead of

   <xsl:element name="td">
      <xsl:element name="a">
        <xsl:attribute name="href">
          <xsl:value-of select="concat('#', .)"/>
        </xsl:attribute>
        <xsl:value-of select="."/>
      </xsl:element>
    </xsl:element>

why not write:

<td>
  <a href="#{.}">
    <xsl:value-of select="."/>
  </a>
</td>

XSLT has a reputation for being verbose but you don't need to make it that bad!

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old December 21st, 2005, 12:03 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I agree with you on the long-windedness.

For the record, I didn't write those nodes, I was just assigned to alter them.

:)



Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Columns tray99 XSLT 2 July 29th, 2008 01:25 PM
Dynamic columns in data controls p330418 ASP.NET 2.0 Professional 0 April 10th, 2008 11:10 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
putting data into a template Aaronwv VB How-To 3 September 10th, 2003 08:28 AM





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