XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 19th, 2012, 06:08 AM
tomystein tomystein is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 3 tomystein User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 40 sec
Reputation Power: 0
XML to HTML or XLS, problems

I have this XML file:
PHP Code:
<?xml version="1.0" encoding="UTF-8"?>
<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>


How can I create an automatic table (with HTML and CSS)? these details of EventName, etc.. are automatic and I need something Dynamic for it.

I tried using W3 tutorials but didn't manage to get anything out of it. This XML file looks different than regular ones as well.

Please let me know if you have an idea.
Many thanks!

EDIT:

I tried to do something like this but it's not getting the data out of the XML file. I am not calling to the elements properly..

PHP Code:
....
<
xsl:template match="/">
  <
html>
  <
body>
  <
h2>Best Movies</h2>
  <
table border="1">
    <
tr bgcolor="#9acd32">
      <
th>Movie</th>
      <
th>Year</th>
    </
tr>
    <
xsl:for-each select="Event">
    <
tr>
      <
td><xsl:value-of select="EventName"/></td>
      <
td><xsl:value-of select="Classification"/></td>
    </
tr>
    </
xsl:for-each>
  </
table>
  </
body>
  </
html>
</
xsl:template>

</
xsl:stylesheet

Reply With Quote
  #2  
Old March 19th, 2012, 11:16 AM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,711 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 6 h 45 m 48 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Two things:
1. Absolute paths need to include the root element. So the template should be matching on /Diary, not just /.
2. Attributes are specified with @s like @EventName. Without them you're just talking about child elements.

Reply With Quote
  #3  
Old March 21st, 2012, 03:22 AM
tomystein tomystein is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 3 tomystein User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 40 sec
Reputation Power: 0
So this is where I got to: still not solved :(

This is my xml:

PHP Code:
<?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:

1.
PHP Code:
<?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.
PHP Code:
<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'), newRownewCell;
                for(
i=0i<eventsO.lengthi++){
                    
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:
1. load an external xml from another site anl not local.
2. 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..?
3. the match "Event" is working but maybe it's wrong.. (?)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XML to HTML or XLS, problems

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap