![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Easy Question [Thread Next] Re: Easy QuestionTo: NULL Date: 5/7/2004 2:00:00 PM
Alex wrote:
> I am new to XSL and having problems trying to display a table made up of 2
> columns. The 1st column needs to display a Customer name and the 2nd column
> displays any orders they have.
>
> I know I need to do something similar to setting the rowspan of the 1st
> column to equal the total number of entries in the 2nd column, but cant
> quite work it out ? any help would be great.
You would have better posted your XML data as otherwise we have to guess
what it looks like.
Thus assuming the example XML to look like
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test20040507Xsl.xml"?>
<data>
<customers>
<customer id="c1">Lance Armstrong</customer>
<customer id="c2">Jan Ullrich</customer>
<customer id="c3">Alexander Winokurow</customer>
</customers>
<orders>
<order customer="c1">power drink</order>
<order customer="c2">donuts</order>
<order customer="c2">more donuts</order>
<order customer="c1">power food</order>
<order customer="c1">power bike</order>
<order customer="c3">vodka</order>
</orders>
</data>
the stylesheet could look like
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>customer orders</title>
</head>
<body>
<div>
<table border="1">
<tbody>
<xsl:for-each select="data/customers/customer">
<xsl:variable name="orders"
select="/data/orders/order[@customer = current()/@id]" />
<tr>
<td rowspan="{count($orders)}"><xsl:value-of select="."
/></td>
<td><xsl:value-of select="$orders[1]" /></td>
</tr>
<xsl:for-each select="$orders[position() > 1]">
<tr>
<td><xsl:value-of select="." /></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</tbody>
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
and then the result looks like
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>customer orders</title>
</head>
<body>
<div>
<table border="1">
<tbody>
<tr>
<td rowspan="3">Lance Armstrong</td><td>power drink</td>
</tr>
<tr>
<td>power food</td>
</tr>
<tr>
<td>power bike</td>
</tr>
<tr>
<td rowspan="2">Jan Ullrich</td><td>donuts</td>
</tr>
<tr>
<td>more donuts</td>
</tr>
<tr>
<td rowspan="1">Alexander Winokurow</td><td>vodka</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
--
Martin Honnen
http://JavaScript.FAQTs.com/
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
