Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Easy Question

From: Martin Honnen <mahotrash@-----.-->
To: 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/



transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent