This is my xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="movies.xsl"?>
<root>
<Diary>
<Event EventName="J.Edgar" Classification="2011 Movies" EventStart="2012-03-19T07:00:00+00:00" EventEnd="2012-03-19T08:00:00+00:00" />
<Event EventName="Titanic" Classification="1997 Movies" EventStart="2012-03-19T09:00:00+00:00" EventEnd="2012-03-19T10:00:00+00:00" />
</Diary>
</root>
I have this two options for creating what I need:
-
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:template match="Event"> <html> <body> <h2>Best movies</h2> <p>Here you can find the top movies ever.</p> <table border="1"> <tr bgcolor="#9acd32"> <th>Movie</th> <th>Year</th> <th>Start Time</th> <th>End Time</th> </tr> <tr> <td><xsl:value-of select="@EventName"/></td> <td><xsl:value-of select="@Classification"/></td> <td><xsl:value-of select="@EventStart"/></td> <td><xsl:value-of select="@EventEnd"/></td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet>
2.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
function loadXMLDoc(fName){
if (window.XMLHttpRequest){
xhttp=new XMLHttpRequest();
} else {
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",fName,false);
xhttp.send("");
return xhttp.responseXML;
}
xmlDoc=loadXMLDoc("movies.xml");
function displayEvents(){
var eventsO = xmlDoc.getElementsByTagName("Event");
var tableO = document.createElement('table'), newRow, newCell;
for(i=0; i<eventsO.length; i++){
newRow = tableO.insertRow(-1);
newCell = newRow.insertCell(-1);
newCell.appendChild(document.createTextNode(eventsO[i].getAttribute('EventName')));
newCell = newRow.insertCell(-1);
newCell.appendChild(document.createTextNode(eventsO[i].getAttribute('Classification')));
}
document.body.appendChild(tableO);
}
window.onload=displayEvents;
</script>
</head>
<body>
</body>
</html>
Can you please try to correct me in these codes?
I would like to do the following features:
-
load an external xml from another site anl not local.
-
Have the list of movies and that when you press on a movie, a popup or a new page comes up and you have more info about the movie. But how do I create it dynamically so the information in that pop up will stay the same but the name of the movie will change, based on the movie you clicked..?
-
the match “Event” is working but maybe it’s wrong.. (?)
There should be an xsl:for-each to display the movies in a loop, as follows: