|
 |
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 .
|
 |
|
|
 |

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

May 14th, 2007, 11:41 AM
|
 |
Wrox Author
Points: 18,487, Level: 59 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|

May 14th, 2007, 11:49 AM
|
Registered User
|
|
Join Date: May 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

May 14th, 2007, 12:02 PM
|
 |
Wrox Author
Points: 18,487, Level: 59 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|

May 15th, 2007, 03:58 AM
|
Registered User
|
|
Join Date: May 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

May 15th, 2007, 04:36 AM
|
 |
Wrox Author
Points: 18,487, Level: 59 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|

May 15th, 2007, 06:33 AM
|
Registered User
|
|
Join Date: May 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks, works like a charm!
you the man!
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |