Hi All,

I am new to XML,XSLT. I have been assigned to task of Generating HTML pages based on the XML file & the condition is No Hardcoding of Nodes and other details.

My XML file is of the below struct:

Node inside Nodes , and those nodes would contain any number of attribuites or elements.


Now i need to knw , is there any Generic XSLT Algorithm to can do the above job and render the HTML page in the form of Navigation Tabs?

Please advice...

Recommended Answers

All 7 Replies

Y none has replied to my post?

xml and xsl, it is possible
to generate the data from a table or even whole html pages

each XML document has a rootnode

<?xml version="1.0" encoding="utf-8"?>
<!-- xml direkt with css 
<?xml-stylesheet type="text/css" href="style1.css"?>
-->
<!-- hmtl code is descript -->
<?xml-stylesheet type="text/xsl" href="display.xsl"?>

<root>
	<title>Mathematics for computing</title>
	<author>This module should help us understand:</author>
	<contents>
		<chapter>Understand concept of Mathematics</chapter>
		<chapter>Be able to use Mathematics in programming</chapter>
		<chapter>Improve our logical thinking that will also help us when solving programming problem</chapter>
	</contents>
	<title>Web technology</title>
	<author>This module should help us understand and be able to do</author>
	<contents>
		<chapter>Write basic java scripts</chapter>
		<chapter>Understand the way internet (internet programming works)</chapter>
		<chapter>Teach us doing basic web sites (HTML, XML)</chapter>
	</contents>
	<title>Communication and Learning Skills</title>
	<author>This module should help us in the following:</author>
	<contents>
		<chapter>Improve our writing skills</chapter>
		<chapter>Improve our thinking skills</chapter>
		<chapter>Improve our oral skills</chapter>
	</contents>
	<title>Information and Data Modelling</title>
	<author>This module should help us to understand and be able to do:</author>
	<contents>
		<chapter>We should be able to create Data modells by applying formal data model descriptions using data modeling techniques</chapter>
		<chapter>We should understand the concept of objec oriented programming/design</chapter>
		<chapter>Be able to produce Diagrams such as: Use case diagram, sequence diagram etc:</chapter>
	</contents>
	<title>Programming Methodology (Java)</title>
	<author>This module should help us to understand and be able to do:</author>
	<contents>
		<chapter>Understand the way programming works</chapter>
		<chapter>Understand what is mean by sequence which is the most important bit in programming</chapter>
		<chapter>Be able to do simple programs</chapter>
		<chapter>Learn basic commands in Java</chapter>
	</contents>
	<title>Computer Systems Fundamentals</title>
	<author>This module should help us to understand and be able to do</author>
	<contents>
		<chapter>Understand how computers works</chapter>
		<chapter>Understand how internet works</chapter>
		<chapter>Be able to do simple calculation regarding computing</chapter>
		<chapter>Learn PEP programming language(Machine code)</chapter>
	</contents>
	<title>Software Development Principles (Java)</title>
	<author>This module is continuation of "programming methodology" at more advanced level</author>
	<contents>
		<chapter>In this module we are improving our knowledge that we gained in "programming methodology module"</chapter>
		<chapter>We take all concepts of programming even further</chapter>
		<chapter>Programming it self is getting more advanced</chapter>
	</contents>
	<title>Software Engineering Principles</title>
	<author>Ths module should help us to understand following</author>
	<contents>
		<chapter>How software is developped</chapter>
		<chapter>Give us an idea of what possibilities are there to make such a system</chapter>
		<chapter>in fact i dont know what this module is for ...</chapter>
	</contents>

	<moduleList>
		<module>
			<moduleName>Web technology</moduleName>
			<moduledescription>Understanding and learning everything regarding internet/internet programming</moduledescription>
			<moduleCode>ECSC407.2</moduleCode>
			<moduleLeader>Wendy Purdy</moduleLeader>
			<timetableSlot>Wednesday 14pm-16pm</timetableSlot>
		</module>
		<module>
			<moduleName>Mathematics for computing</moduleName>
			<moduledescription>Understand concept of Mathematics</moduledescription>
			<moduleCode>ECSC408.Y</moduleCode>
			<moduleLeader>Daphne Economou</moduleLeader>
			<timetableSlot>Tuesday 12pm-13pm</timetableSlot>
		</module>
		<module>
			<moduleName>Communication and Learning Skills</moduleName>
			<moduledescription>Improve our communication skills</moduledescription>
			<moduleCode>EBSY400.Y</moduleCode>
			<moduleLeader>Maria Chondrogianni</moduleLeader>
			<timetableSlot>Monday 14pm-16pm</timetableSlot>
		</module>
		<module>
			<moduleName>Information and Data Modelling</moduleName>
			<moduledescription>Module should teach us all basics about data and information modelling</moduledescription>
			<moduleCode>EBSY401.1</moduleCode>
			<moduleLeader>Anush Begoyan</moduleLeader>
			<timetableSlot>Monday 11am-13pm</timetableSlot>
		</module>
		<module>
			<moduleName>Programming Methodology (Java)</moduleName>
			<moduledescription>Module should teach us basic programming in java</moduledescription>
			<moduleCode>ECSC401.1</moduleCode>
			<moduleLeader>David Hearnshaw</moduleLeader>
			<timetableSlot>Wednesday 09am-11am</timetableSlot>
		</module>
		<module>
			<moduleName>Computer Systems Fundamentals</moduleName>
			<moduledescription>Module should help us to understand how computers and internet works</moduledescription>
			<moduleCode>ECSC404.1</moduleCode>
			<moduleLeader>Cheng Lee</moduleLeader>
			<timetableSlot>Monday 09am-11pm</timetableSlot>
		</module>
		<module>
			<moduleName>Software Development Principles (Java)</moduleName>
			<moduledescription>Continuation of Programming methodology</moduledescription>
			<moduleCode>ECSC405.2</moduleCode>
			<moduleLeader>David Hearnshaw</moduleLeader>
			<timetableSlot>Thursday	11am-13pm</timetableSlot>
		</module>
		<module>
			<moduleName>Software Engineering Principles</moduleName>
			<moduledescription>Module should help us to understand principles of software engineering</moduledescription>
			<moduleCode>ECSC409.2</moduleCode>
			<moduleLeader>Epaminondas Kapetanios</moduleLeader>
			<timetableSlot>Thursday	14pm-16pm</timetableSlot>
		</module>
	</moduleList>
</root>

it follows the match in the first one xsl / is the root node is addressed to

this should then also be described basic html code

<xsl:template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
				<title>Untitled Document</title>
			</head>
			<style>
table {
border: 2px solid black;
}
th,td{
border: 2px solid black;
}
tr{
text-align: center;
}
tr.head{
text-align: left;
background-color:#ff0000;
}
tr.odd{
background-color:#ff9900;
}
tr.even{
background-color:#ff0099;

}</style>
			<body>
				<h2>Module list</h2>
				<table>
					<tr class="head">
						<th>Module Name</th>
						<th>Description</th>
						<th>Module Code</th>
						<th>Module Leader</th>
						<th>Timetable Slot</th>
					</tr>
					<xsl:apply-templates select="root/moduleList"/>
				</table>
			</body>
		</html>
	</xsl:template>

now it is possible to apply template to jump-in nodes further

to further define and transform Teplate as html code to let

there are no nodes where generated html
Braving the node should be executed

<xsl:template match="moduleList">
		<xsl:apply-templates select="module"/>
	</xsl:template>
<xsl:template match="module">
		<tr>
			<xsl:choose>
				<xsl:when test="position() mod 2 = 1">
					<xsl:attribute name="class">odd</xsl:attribute>
				</xsl:when>
				<xsl:when test="position() mod 2 = 0">
					<xsl:attribute name="class">even</xsl:attribute>
				</xsl:when>
			</xsl:choose>
			<td>
				<xsl:value-of select="moduleName"/>
			</td>
			<td>
				<xsl:value-of select="moduledescription"/>
			</td>
			<td>
				<xsl:value-of select="moduleCode"/>
			</td>
			<td>
				<xsl:value-of select="moduleLeader"/>
			</td>
			<td>
				<xsl:value-of select="timetableSlot"/>
			</td>
		</tr>
	</xsl:template>

as it is to be used in html code can be assembled with a xsl
see above


there is no general prescription for xml in [x]html convert

I discuss with each template should happen if the node is found which is generated for a conversion

Thanks xml_looser.

But you had hardocded ..

Cant we make it generic?

Hi anandunics ,

Have you got any solution for your question. I am also searching for the same.
Thanks in advance.

The answer is "no". The entire purpose of XSLT is to transform a SPECIFIC XML format to a SPECIFIC output. There is no magic code to transform any XML to pretty HTML. Sorry. You have to match templates. Think about what that implies: to do a "match", you have to specify what it is you are matching.

That said, the generic node common to all XML is the root node, and XSLT has built-in templates. Do a web search for "XSLT Identity" and you'll see generic ways to output XML to XML, but as soon as you want to do something specific (turn THIS XML node into THAT HTML tag) then you must (by definition) be specific.

The answer is "no". The entire purpose of XSLT is to transform a SPECIFIC XML format to a SPECIFIC output. There is no magic code to transform any XML to pretty HTML. Sorry. You have to match templates. Think about what that implies: to do a "match", you have to specify what it is you are matching.

That said, the generic node common to all XML is the root node, and XSLT has built-in templates. Do a web search for "XSLT Identity" and you'll see generic ways to output XML to XML, but as soon as you want to do something specific (turn THIS XML node into THAT HTML tag) then you must (by definition) be specific.

Yes i was unable to transform using normal transformation...so i made use of identity transformation...though i havent got the complete result ..its still achievable... One thing for xml schema plays major when u need it on the form of tabs

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.