This is a problem involving xml schema: I am supposed to print the details in tabular format!
xsl file code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="product">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">, </xsl:if>
</xsl:template>
<xsl:template match="/">
<html>
<head>
<title>Supplier Details</title>
</head>
<body>
<h1>SUPPLIER DETAILS AT CYBERSHOP</h1>
<table border="3" cellspacing="2" cellpadding="6">
<thead align="center" bgcolor="silver">
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>Phone</th>
<th>Product(s)</th>
</thead>
<tbody>
<xsl:for-each select="supplier.details/supplier">
<tr>
<xsl:choose>
<xsl:when test="position() mod 2 =0">
<td><font color="red"><xsl:value-of select="@sid"/></font></td>
<td><font color="red"><xsl:value-of select="@fname"/><xsl:text> </xsl:text><xsl:value-of select="@lname"/></font></td>
<td><font color="red"><xsl:value-of select="address"/></font></td>
<td><font color="red"><xsl:value-of select="phone"/></font></td>
<td><font color="red"><xsl:apply-templates select="product"/></font></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="@sid"/></td>
<td><xsl:value-of select="@fname"/><xsl:text> </xsl:text><xsl:value-of select="@lname"/></td>
<td><xsl:value-of select="address"/></td>
<td><xsl:value-of select="phone"/></td>
<td><xsl:apply-templates select="product"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Here is the xml file:
<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="6p3.xsl"?>
<supplier.details>
<supplier sid="S001" fname="Jason" lname="Smith">
<address>10 Lafair Sr, NY 12034</address>
<phone>123-456-7894</phone>
<product>Office Stationary</product>
<product>Furniture</product>
</supplier>
<supplier sid="S002" fname="Nathan" lname="Jessop">
<address>10 Wellington St, MA 12034</address>
<phone>348-279-8799</phone>
<product>Water Dispenser</product>
<product>Air Conditioning</product>
</supplier>
<supplier sid="S003" fname="Sam" lname="Hendrich">
<address>45 1/2 Long BEach, CA 90210</address>
<phone>478-939-2092</phone>
<product>Intercom</product>
<product>Telephone</product>
</supplier>
</supplier.details>
I got proper output but did not understand how the xsl:apply-template element worked. I am supposed to get all the text in the product element into one field. Even if there are more than two or more product elements (in supplier) it prints the proper output (without no looping). How is this possible?