Pradeep wrote:
> I have a following XML file
> <ITEMLIST>
> <ITEM>
> <NAME> Item1 </ITEM>
^^^^^
That is not even well-formed.
> <PRICE> 500 </PRICE>
> </ITEM>
> <ITEM>
> <NAME> Item2 </ITEM>
> and want to display in HTML like following
>
> -------------------------------------------
> | | PRICE | LOCATION | QTY |
> -------------------------------------------
> Item1 | 500 | | |
> -------------------------------------------
> Item1 | 600 | XYZ | |
> -------------------------------------------
> Item1 | 700 | | 25 |
> -------------------------------------------
> Item1 | 900 | | 90 |
> -------------------------------------------
Why always "Item1"? Assuming you want the NAME element output then the
following XSLT 1.0 stylesheet should help:
<xsl:stylesheet
xmlns

sl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl

utput method="html" indent="yes"/>
<xsl:template match="/">
<html lang="en">
<head>
<title>Example</title>
</head>
<body>
<xsl:apply-templates select="ITEMLIST"/>
</body>
</html>
</xsl:template>
<xsl:template match="ITEMLIST">
<table border="1">
<thead>
<tr>
<th> </th>
<th>PRICE</th>
<th>LOCATION</th>
<th>QTY</th>
</tr>
</thead>
<xsl:apply-templates select="ITEM"/>
</table>
</xsl:template>
<xsl:template match="ITEM">
<tr>
<td><xsl:value-of select="NAME"/></td>
<td><xsl:value-of select="PRICE"/></td>
<td>
<xsl:choose>
<xsl:when test="LOCATION">
<xsl:value-of select="LOCATION"/>
</xsl:when>
<xsl

therwise> </xsl

therwise>
</xsl:choose>
</td>
<td>
<xsl:choose>
<xsl:when test="QTY">
<xsl:value-of select="QTY"/>
</xsl:when>
<xsl

therwise> </xsl

therwise>
</xsl:choose>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
--
Martin Honnen
http://JavaScript.FAQTs.com/