XSLTGeneral 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
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 !:)
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>