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 February 19th, 2009, 04:35 PM
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default looping in XSL

Hi Guys,

I have an XML like this
Code:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="foreach.xsl" ?>
<customers>
   <customer>
      <name>John Smith</name>
      <address>123 Oak St.</address>
      <state>WA</state>
      <phone>(206) 123-4567</phone>
   </customer>
   <customer>
      <name>Zack Zwyker</name>
      <address>368 Elm St.</address>
      <state>WA</state>
      <phone>(206) 423-4537</phone>
   </customer>
.....
.....
....
.... like this there are so many records..
</customers>
Now I need an XSL which will display 3 customers name in a HTML table like this....

Code:
<table>
<tr>
    <td>John Smith</td>
    <td>Zack Zwyker</td>
    <td>Some other customer name</td>
</tr>
<tr>
... like this the for loop goes to display only the customer names..
</tr>
</table>
 
Old February 23rd, 2009, 02:32 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:template match="/">
        <table>
            <xsl:for-each select="customers/customer[position() mod 3 = 1]">
                <tr>
                    
                    <td><xsl:value-of select="name"/></td>
                    <td><xsl:value-of select="following-sibling::customer[1]/name"/></td>
                    <td><xsl:value-of select="following-sibling::customer[2]/name"/></td>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
</xsl:stylesheet>
Cheers, John Bampton
 
Old February 24th, 2009, 10:41 AM
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply.

since i also need to display the images with each name, i would end up with only images showing in the last row if there are < 3 items.

any clue how we can do this..?

Regards,
Mahesh
 
Old February 24th, 2009, 10:47 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You didn't show any images in your source document, and I have no idea how you have tried to extend the code you were given to display images. If youv'e extended it incorrectly, you'd better show us what your code (and source document) look like so we can help you find your mistakes.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
Plz help: looping variable in xsl priyatowin XSLT 1 September 11th, 2006 05:38 AM
xsl advise needed - Replacing UID through XSL Billyl XSLT 6 February 28th, 2006 05:46 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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