1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Unable to style xml

Discussion in 'XML & RSS' started by macaela, Nov 30, 2010.

  1. #1
    Hi i have a while loop which displaying data frm the database but i am trying to style but it doesnt seem to be workin now help please


    this the xml
    <?php
    // PHP file that renders perfect Dynamic XML for MySQL Database result sets
    // Script written by Adam Khoury @ www.developphp.com - April 05, 2010
    // View the video that is tied to this script for maximum understanding
    // -------------------------------------------------------------------
    header("Content-Type: text/xml"); //set the content type to xml
    // Initialize the xmlOutput variable
    $xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
    $xmlBody .= "<XML>";
    // Connect to your MySQL database whatever way you like to here
    mysql_connect("localhost","root","") or die (mysql_error());
    mysql_select_db("admin") or die ("no database");
    // Execute the Query on the database to select items(20 in this example)
    $sql = mysql_query("SELECT * FROM news ORDER BY news_date DESC LIMIT 0, 20");
    while($row = mysql_fetch_array($sql)){
        // Set DB variables into local variables for easier use 
        $news_id = $row["news_id"]; 
        $subject = $row["subject"];  
        $news_date = strftime("%b %d, %Y", strtotime($row["news_date"])); 
        $news_artical = $row["news_artical"];  
        // Start filling the $xmlBody variable with looping content here inside the while loop 
        // It will loop through 20 items from the database and render into XML format
    	
        $xmlBody .= '
    	<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
    <catalog>
    	<cd>
    
        <title>' . $news_id . '</title>
        <artist>' . $subject . '</artist>
       <country>' . $news_date . '</country>
       <company>' . $description . '</company>
       
    	</cd>
    
    </catalog>';
    } // End while loop
    mysql_close(); // close the mysql database connection
    $xmlBody .= "</XML>";
    echo $xmlBody; // output the gallery data as XML file for flash
    ?>
    PHP:
    this is the style sheet
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!-- Edited with XML Spy v4.2 -->
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
    
    <xsl:template match="/">
      <html>
      <body>
      <h2>My CD Collection</h2>
        <table border="1">
          <tr bgcolor="#9acd32">
    
            <th align="left">Title</th>
            <th align="left">Artist</th>
          </tr>
          <xsl:for-each select="catalog/cd">
          <tr>
            <td><xsl:value-of select="title"/></td>
            <td><xsl:value-of select="artist"/></td>
          </tr>
    
          </xsl:for-each>
        </table>
      </body>
      </html>
    </xsl:template>
    </xsl:stylesheet>
    PHP:

     
    macaela, Nov 30, 2010 IP
  2. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    hi has anyone know why this code not wrking still cant find a solution for it anyone help please
     
    macaela, Jan 16, 2011 IP