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 May 14th, 2007, 11:22 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT For Each - Field Names

Hi,

I have some data being returned like this :

[u]Column1 | Column2 | Column 3 | Column 4</u>
 ABC | DEF | GHI | JKL
 123 | 456 | 789 | 101

When i write out the information i want to loop through each column and write out the column name. Is this possible ?

Thanks
Reply With Quote
  #2 (permalink)  
Old May 14th, 2007, 11:41 AM
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: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

What does your input look like (in XML) and what do you want the output to look like?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old May 14th, 2007, 11:49 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It looks like this :
<row>
  <PartnerCode>Partner1</PartnerCode>
  <Column1>50%</Column1>
  <Column2>20%</Column2>
  <Column3>30%</Column3>
</row>
<row>
  <PartnerCode>Partner2</PartnerCode>
  <Column1>25%</Column1>
  <Column2>30%</Column2>
  <Column3>45%</Column3>
</row>

and i want write it out like this :

        Partner1 Partner2
Column1 50% 25%
Column2 20% 30%
Column3 30% 45%

Thanks

Reply With Quote
  #4 (permalink)  
Old May 14th, 2007, 12:02 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: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm assuming you want HTML output though you still haven't actually said...

Something like this:

<table>
  <tr>
    <td/>
    <xsl:for-each select="row">
     <td><xsl:value-of select="PartnerCode"/></td>
    </xsl:for-each>
  </tr>

  <xsl:for-each select="row[1]/*[not(self::PartnerCode)]">
  <tr>
    <xsl:variable name="p" select="position()"/>
    <td><xsl:value-of select="name()"/></td>
    <xsl:for-each select="../../row/*[position()=$p]">
      <td><xsl:value-of select="."/></td>
    </xsl:for-each>
  </tr>
  </xsl:for-each>
</table>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old May 15th, 2007, 03:58 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much Micheal!

That work 99% perfectly :)

The only question i have is I see the code at the top which skips PartnerCode when writing out the first column, but it still writes out the data for partner code so it appears like this

        Partner1 Partner2
Column1 Partner1 Partner1
Column2 50% 25%
Column3 20% 30%

I presume I need to exclude that field from this for each ;

    <xsl:for-each select="../../row/*[position()=$p]">
      <td><xsl:value-of select="."/></td>
    </xsl:for-each>

can you help me out with the syntax ?

thanks

Reply With Quote
  #6 (permalink)  
Old May 15th, 2007, 04:36 AM
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: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry about that. Change to

<xsl:variable name="p" select="position()+1"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #7 (permalink)  
Old May 15th, 2007, 06:33 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks, works like a charm!

you the man!

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
Error getting field names from query vbark Access VBA 1 January 23rd, 2007 09:04 PM
Replacing field names in datasheet philiprodley Access VBA 1 August 10th, 2006 12:47 PM
Get Field Names fizzerchris Classic ASP Databases 1 February 25th, 2006 05:06 AM
Retrieving Field Names RayRedSox Classic ASP Basics 0 October 12th, 2005 02:16 PM
Retrieving Dynamic Field Names tdaustin Classic ASP Basics 4 January 12th, 2004 11:10 AM



All times are GMT -4. The time now is 03:56 PM.


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