WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Using PHP for XSLT transformations
Categories : PHP, XSLT, XSL Click here to Update Your Picture
Vinod Mohan
Date : Dec 17th 2008
Grade : 1 of 5 (graded 1 times)
Viewed : 6388
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Vinod Mohan
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Templating using XSL Transformation is a technique that is becoming more and more popular. PHP 5 has support for XSLT. But the best thing about using XSLT in PHP is that, php supports calling native functions in PHP from the XSL template. This increases the power of XSL transformation by several folds. Here is an example on how to transform xml to xhtml using php and use native php functions.

<?php
// Set default time zone
date_default_timezone_set('Asia/Calcutta');
$xmlStr = <<<STR
<Profiles>
<Profile>
  <id>1</id>
  <name>john doe</name>
  <dob>188677800</dob>
</Profile>
<Profile>
  <id>2</id>
  <name>mark antony</name>
  <dob>79900200</dob>
</Profile>
<Profile>
  <id>3</id>
  <name>neo anderson</name>
  <dob>240431400</dob>
</Profile>
<Profile>
  <id>4</id>
  <name>mark twain</name>
  <dob>340431400</dob>
</Profile>
<Profile>
  <id>5</id>
  <name>frank hardy</name>
  <dob>390431400</dob>
</Profile>
</Profiles>
STR;
$xslStr = <<<EOB
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" exclude-result-prefixes="php">
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="yes" standalone="no" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<xsl:template match="/">
  <html>
    <head>
      <title>User Profiles</title>
    </head>
    <body>
      <h1>Using PHP Functions in XSLT</h1>
      <table cellspacing="1" cellpadding="5" border="1">
         <caption>User Profiles</caption>
         <tr><th>ID</th><th>Name</th><th>Date of Birth</th></tr>
         <xsl:for-each select="/Profiles/Profile">
         <tr>
            <td><xsl:value-of select="id"/></td>
            <td><xsl:value-of select="php:function('ucwords', string(name))"/></td>
            <td><xsl:value-of select="php:function('date', 'jS M, Y', number(dob))"/></td>
         </tr>
         </xsl:for-each>
      </table>
    </body>
  </html>
</xsl:template>
</xsl:stylesheet>
EOB;

$xmlDoc = new DOMDocument();
$xmlDoc->loadXML($xmlStr);

$xslDoc = new DOMDocument();
$xslDoc->loadXML($xslStr);

$xsltProcessor = new XSLTProcessor();
$xsltProcessor->registerPHPFunctions();
$xsltProcessor->importStyleSheet($xslDoc);
echo
$xsltProcessor->transformToXML($xmlDoc);
?>



Trivia Quiz program using XML, XSLT and PHP
Categories : PHP, XML, XSLT
XPath for PHP without the DOM XML extension
Categories : DOM XML, XML, XSLT, PHP Classes, PHP
XML Menu
Categories : PHP, PHP Classes, Navigation, XML, XSL
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
xslt_closelog -- Clear the logfile for a given instance of Sablotron
Categories : PHP, PHP Functions, XSLT
Calendar using Date function
Categories : HTML and PHP, PHP, Date Time, Calendar
Invision Forums Latest Threads list
Categories : PHP, Miscellaneous, Databases, MySQL
Using PHP im HTML image tags
Categories : PHP, HTML and PHP, Graphics, Beginner Guides
IP Blocking
Categories : PHP, Security, HTTP
Pseudo Non Parsed Header. Output to the the browser as the script runs.
Categories : PHP, HTTP, HTML and PHP
UDMSearch - a free search engine, indexing system.
Categories : Search Engines, Linux, PHP, MySQL, ODBC
how to check if a string contains a letter from a different language?
Categories : PHP, Regexps, Languages
Unix Disk Information with graphs
Categories : PHP, Shell Scripting, Filesystem
fforum fumanchi forum MySQL treestructure
Categories : Complete Programs, PHP, MySQL
ibase_close -- Close a connection to an InterBase database
Categories : PHP, PHP Functions, InterBase