#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    3
    Rep 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
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,185
    Rep Power
    9398
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    3
    Rep 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.. (?)

IMN logo majestic logo threadwatch logo seochat tools logo