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 30th, 2007, 07:47 AM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 3D Array Looping - Formatting in table

I have the following data and code to loop thru the node.
I want this data in a table. I would like to add a new row for every new D3. So I would loop thru and in the first row I would have 4 columns, then add a new row, 4 columns, etc. I cannot figure out the syntax and where to put the conditionals. I would appreciate any help. Thanks.

    <Array1>
    <Value D1="1" D2="1" D3="1">12</Value>
        <Value D1="1" D2="2" D3="1">23</Value>
        <Value D1="1" D2="3" D3="1">11</Value>
        <Value D1="1" D2="4" D3="1">11</Value>
        <Value D1="1" D2="1" D3="2">23</Value>
        <Value D1="1" D2="2" D3="2">32</Value>
        <Value D1="1" D2="3" D3="2">11</Value>
        <Value D1="1" D2="4" D3="2">3</Value>
        <Value D1="1" D2="1" D3="1">242</Value>
        <Value D1="1" D2="2" D3="1">13</Value>
        <Value D1="1" D2="3" D3="1">76</Value>
        <Value D1="1" D2="4" D3="1">49</Value>
    </Array1>





    <xsl:for-each select =".">
        <xsl:variable name ="Rank">
            <xsl:value-of select ="position()"/>
        </xsl:variable>
        <xsl:for-each select =".">
            <Value D1="1" D2="1" D3="1">
                <xsl:attribute name ="D1" >
                    <xsl:value-of select ="1"/>
                </xsl:attribute >
                <xsl:attribute name ="D2" >
                    <xsl:value-of select ="$Rank"/>
                </xsl:attribute >
                <xsl:attribute name ="D2" >
                    <xsl:value-of select ="position()"/>
                </xsl:attribute >
                <xsl:value-of select ="12"/>
            </Value>
        </xsl:for-each>
    </xsl:for-each>
Reply With Quote
  #2 (permalink)  
Old April 30th, 2007, 08:21 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure from your description exactly what output you want.

Don't think in terms of looping and conditionals. That's procedural thinking.

This is a grouping problem. In XSLT 2.0 it's something like

<xsl:template match="Array1">
  <xsl:for-each-group select="Value" group-adjacent="@D3">
    <tr>
    <xsl:for-each select="current-group()">
      <td>... output an item in this group

In 1.0 you use the same kind of logic but you have to identify the group boundaries by hand:

<xsl:template match="Array1">
  <xsl:for-each select="Value[not(@D3 = preceding-sibling::Value[1]/@D3">
    <tr>
      <xsl:for-each select=". | following-sibling::Value[position() &lt; 4">
      <td>
      ... output an item in this group

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old April 30th, 2007, 09:17 AM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there not a way to format the way I want using the logic I am using now to loop thru?

Reply With Quote
  #4 (permalink)  
Old April 30th, 2007, 11:57 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

> Is there not a way to format the way I want using the logic I am using now to loop thru?

Your current logic is clearly wrong, so the answer is no.

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
looping through static array mister_mister XSLT 9 March 21st, 2008 01:30 PM
3D Array - Looping jordan23 XSLT 5 April 27th, 2007 07:08 AM
Looping through Array Values in T-SQL trufla SQL Server ASP 4 April 13th, 2007 06:14 AM
looping through a table John Parker Access VBA 7 December 11th, 2006 07:30 PM
Looping controls and array redim mega Excel VBA 2 April 19th, 2005 11:57 AM



All times are GMT -4. The time now is 09:18 PM.


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