Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
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 October 29th, 2006, 10:29 PM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using XSLT to convert XML to a table ?

Hi all,
Suppose we have a XML file describe products as follow:
<?xml version="1.0" encoding="utf-8" ?>
<store>
    <product>
        <ImageUrl>product1.gif</ImageUrl>
        <Name>Screen</Name>
        <Price>12</Price>
    </product>
    <product>
        <ImageUrl>product2.gif</ImageUrl>
        <Name>Printer</Name>
        <Price>15</Price>
    </product>
    <product>
        <ImageUrl>product3.gif</ImageUrl>
        <Name>Printer</Name>
        <Price>20</Price>
    </product>
</store>
If we want to show 3 products per a line (and suppose we have many lines) as follow:
<table>
    <tr>
        <td>
            ...//product i info
        </td>
        <td>
            ...//product i+1 info
        </td>
        <td>
            ..//product i+2 info
        </td>
    </tr>
    <tr>
        <td>
            ...//product i+3 info
        </td>
        <td>
            ...//product i+4 info
        </td>
        <td>
            ..//product i+5 info
        </td>
    </tr>
..... //product i+n info
</table>

How can we obtain this by using XSLT ?
Thanks a lot !:)
Reply With Quote
  #2 (permalink)  
Old October 30th, 2006, 04:20 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: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please see http://www.dpawson.co.uk/xsl/sect2/N7450.html#d9914e13

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old October 30th, 2006, 10:06 AM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks you very much !
But all products are showed three times .
I wonder if I made any mistakes ?.
Here is my code :
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="store">
<table bgcolor="#DDEEF7" WIDTH="100%" >
<xsl:for-each select="product">
<tr>
<xsl:for-each select=". | following-sibling :: product[position() < 3]">
<td>
....some code displaying product info here...
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Reply With Quote
  #4 (permalink)  
Old October 30th, 2006, 11:03 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: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, you made a mistake. The example I pointed you to starts

<xsl:for-each select="item[position() mod 5 = 1]">


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
Subject: Convert XML using XSLT manoj1984 XSLT 6 May 30th, 2008 04:27 PM
Convert 1 big XML to multiple smaller XML victorcorey XSLT 1 March 20th, 2008 05:59 AM
Convert XML to XML template question bonekrusher XSLT 3 July 12th, 2007 07:47 AM
how to populate a table with xml data in xslt miccipynewbie XSLT 6 May 28th, 2007 07:29 AM
constructing a HTML table from xml data using xslt rameshnarayan XSLT 0 September 19th, 2005 06:53 AM



All times are GMT -4. The time now is 01:27 PM.


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