[xsl] XML output in HTML

Subject: [xsl] XML output in HTML
From: "Senthilkumaravelan K" <skumaravelan@xxxxxxxxxxxxxx>
Date: Tue, 11 Mar 2008 11:00:24 -0700
Hi All,
I would like to select all the nodes of req element as it is in XML
form in my HTML.
Please help me ,what am doing wrong in here?

Thanks,
Senthil


Input XML
<report>
<result>
<req bid="32"  ><header><attr><name>FirstName</name><val>senthil</val></attr></header></req>
<resp><code>OK</code><message>test1</message><fault></fault></resp>
</result>
<result>
<req bid="32"  ><header><attr><name>FirstName</name><val>senthil</val></attr></header></req>
<resp><code>OK</code><message>test2</message><fault></fault></resp>
</result>
<result>
<req bid="32"  ><header><attr><name>FirstName</name><val>senthil</val></attr></header></req>
<resp><code>ERROR</code><message>test3</message><fault>Error
messge</fault></resp>
</result>
</report>

XSLT Have written

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method="xml" omit-xml-declaration="no" indent="yes" />
	<xsl:variable name="WHITESPACE" select="' '" />
	<xsl:preserve-space elements="fault" />
	<xsl:template match="/">
		<html>
			<body>
				<h2>
					Report
				</h2>
				<table border="1">
					<tr bgcolor="#9acd32">
						<th>
							Request
						</th>
						<th>
							Response code
						</th>
						<th>
							Message
						</th>
						<th>
							Status
						</th>
					</tr>
					<xsl:for-each select="report/result">
						<tr>
							<td>
										<xsl:apply-templates select="req" />
							</td>
							<td>
								<xsl:value-of select="resp/code" />
							</td>
							<td>
								<xsl:value-of select="resp/message" />
							</td>
							<td>
								<xsl:choose>
									<xsl:when test="normalize-space(resp/fault)=''">
										<xsl:call-template name="STATUS_DETECTION">
											<xsl:with-param name="my-param" select="'S'" />
										</xsl:call-template>
									</xsl:when>
									<xsl:otherwise>
										<xsl:call-template name="STATUS_DETECTION">
											<xsl:with-param name="my-param" select="'F'" />
										</xsl:call-template>
									</xsl:otherwise>
								</xsl:choose>
							</td>
						</tr>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
	<xsl:template name="STATUS_DETECTION">
		<xsl:param name="my-param" />
		<xsl:choose>
			<xsl:when test="$my-param='S'">
				Success
			</xsl:when>
			<xsl:otherwise>
				Failure
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="req">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()" />
		</xsl:copy>
	</xsl:template>
	
	<xsl:template match="@*">
	<xsl:text> </xsl:text>
	<span>
		<xsl:value-of select="concat(name(), '=')"/>
		<span>
			<xsl:value-of select="concat('&quot;', ., '&quot;')"
disable-output-escaping="yes"/><br/>
		</span>
	</span>
</xsl:template>
</xsl:stylesheet>

Expected output
<?xml version="1.0" encoding="UTF-8"?>
<html>
<body>
<h2>
					Report
				</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>
							Request
						</th>
<th>
							Response code
						</th>
<th>
							Message
						</th>
<th>
							Status
						</th>
</tr>
<tr>
<td>
<req bid="32"  ><header><attr><name>FirstName</name><val>senthil</val></attr></header></req>
</td>
<td>OK</td>
<td>test1</td>
<td>
				Success
			</td>
</tr>
<tr>
<td>
<req bid="32"  ><header><attr><name>FirstName</name><val>senthil</val></attr></header></req>
</td>
<td>OK</td>
<td>test2</td>
<td>
				Success
			</td>
</tr>
<tr>
<td>
<req bid="32"  ><header><attr><name>FirstName</name><val>senthil</val></attr></header></req>
</td>
<td>ERROR</td>
<td>test3</td>
<td>
				Failure
			</td>
</tr>
</table>
</body>
</html>

Current Thread