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 April 30th, 2007, 07:47 AM
Registered User
 
Join Date: Apr 2007
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>
 
Old April 30th, 2007, 08:21 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old April 30th, 2007, 09:17 AM
Registered User
 
Join Date: Apr 2007
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?

 
Old April 30th, 2007, 11:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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





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





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