here is my xml file i need help in creating an XSLT file to display it as HTML i a browser, the resulting output should deal with as many jobs as are returned and be simpla and clear to view in a table structure

<?xml version="1.0" encoding="UTF-8"?>
<!--XML for XSLT-->
<suitablejobs xsi:noNamespaceSchemaLocation="SuitableJobsfinal.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<company>
		<companyname>
			<companyname>ericsson</companyname>
		</companyname>
		<jobdescription>
			<jobtitle>IP engineer</jobtitle>
			<salaryammount>2000</salaryammount>
			<details>data packet routing</details>
		</jobdescription>
		<jobdescription>
			<jobtitle>Core engineer</jobtitle>
			<salaryammount>3000</salaryammount>
			<details>MGW switching</details>
		</jobdescription>
		<jobdescription>
			<jobtitle>BSS engineer</jobtitle>
			<salaryammount>2000</salaryammount>
			<details>radio frequency </details>
		</jobdescription>
	</company>
	<company>
		<companyname>
			<companyname>siemens</companyname>
		</companyname>
		<jobdescription>
			<jobtitle>Rollout engineer</jobtitle>
			<salaryammount>4000</salaryammount>
			<details>project management</details>
		</jobdescription>
		<jobdescription>
			<jobtitle>cook</jobtitle>
			<salaryammount>1000</salaryammount>
			<details>tea maker</details>
		</jobdescription>
		<jobdescription>
			<jobtitle>loader</jobtitle>
			<salaryammount>500</salaryammount>
			<details>loading</details>
		</jobdescription>
	</company>
</suitablejobs>

Recommended Answers

All 2 Replies

i am realy stuck and dont know what to do any code that am putting is not working please somebody help

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="html"/>
	<xsl:template match="/">
		<html>
			<style type="text/css">
table
{
width:100%;
border-collapse:collapse;
}
tr
{
background-color:#9acd32;
}
.even
{
background-color:#9a9a9a;
}
.odd
{
background-color:#009a00;
}
table,th,td
{
border: 2px solid black;
margin:2px;
}
td
{
padding:5px;
text-align:center;
}</style>
			<body>
				<xsl:apply-templates select="suitablejobs"/>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="suitablejobs">
		<table>
			<tr>
				<th>companyname</th>
				<td>Pos</td>
				<th>jobtitle</th>
				<th>salaryammount</th>
				<th>details</th>
			</tr>
			<xsl:apply-templates select="company"/>
		</table>
	</xsl:template>
	<xsl:template match="company">
		<xsl:apply-templates select="jobdescription">
			<xsl:with-param name="many" select="count(jobdescription)"/>
			<xsl:with-param name="before" select="count(preceding-sibling::company/jobdescription)"/>
			<xsl:with-param name="cbefore" select="count(preceding-sibling::company)"/>
		</xsl:apply-templates>
	</xsl:template>
	<xsl:template match="jobdescription">
		<xsl:param name="many"/>
		<xsl:param name="before"/>
		<xsl:param name="cbefore"/>
		<tr>
			<xsl:choose>
				<xsl:when test="($before + position()) mod 2 = 1">
					<xsl:attribute name="class">odd</xsl:attribute>
				</xsl:when>
				<xsl:otherwise>
					<xsl:attribute name="class">even</xsl:attribute>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:if test="position()=1">
				<td rowspan="{$many}">
				<xsl:choose>
				<xsl:when test="$cbefore mod 2 = 1">
					<xsl:attribute name="class">odd</xsl:attribute>
				</xsl:when>
				<xsl:otherwise>
					<xsl:attribute name="class">even</xsl:attribute>
				</xsl:otherwise>
			</xsl:choose>
					<xsl:value-of select="../companyname/companyname"/>
				</td>
			</xsl:if>
			<!--
                        Number 1 cbefore count preceding-sibling::company		
			Number 2 position
			Number 3 before count preceding-sibling::company/jobdescription
			Number 4 addition Number 1 Number 2
			Numerb 5 count all in company			
			 -->
			<td>
				<xsl:value-of select="concat($cbefore,' ',position(),' ',$before,' ',$before+position(),' ',$many)"/>
			</td>
			<xsl:apply-templates/>
		</tr>
	</xsl:template>
	<xsl:template match="jobtitle|salaryammount|details">
		<td>
			<xsl:value-of select="."/>
		</td>
	</xsl:template>
</xsl:stylesheet>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.