Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Nothing to ask, just an announce to make...
Old 01-20-2008, 04:01 PM Nothing to ask, just an announce to make...
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I don't precisely know where to put this, so be it.
Any mod, feel free to move it elsewhere if you think it belong there.

I don't have anything to sell, I just want to inform anyone interested that a php class I wrote to ease the production of web pages with XML and XSL.

I have made it publicly available under a permissive BSD like license.
The class allows you to create a XML document, associate a XSL style sheet and choose a "rendering set" of style sheets in 5 lines of codes.

The detection of the browser, if it have an XSLT engine available, is done by the class and the content is transformed on the server if the browser don't support XSL transformations.

see http://www.quixml.org for the details, if anyone could be interested.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
 
Register now for full access!
Old 01-21-2008, 12:05 PM Re: Nothing to ask, just an announce to make...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Im probably being stupid but do u have any examples of how this could be used?

Ta,
Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 01-21-2008, 01:54 PM Re: Nothing to ask, just an announce to make...
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
It's not being stupid to ask Dan,
Of course I can give you an example.

First a bit of theory...
Rather than outputting HTML to the browser, this class focus of outputting XML, and associate a style sheet to that xml to style it on the browser.
Think CSS, but on steroids, and that applies to the HTML element, and not just the visual formatting.

The XML generation is simple, here is a sample file code:
PHP Code:
$objXml->setRenderingSet('html');  //select the HTML output version of the style sheets
$objXml->setXsl('com.dating.signup'); //set the xsl file to associate to the xml datas
$objXml->start(); //open the xml document
$objXml->general(); //put a <GENERAL> section
$objXml->open('DATAS');  //open an <DATAS> node
    
$objXml->open('countryList');  //open an <countryList> node
        
$GLOBALS['objDb']->q("SELECT iso, printable_name FROM country ORDER BY printable_name ASC");
        while(
$o=$GLOBALS['objDb']->fo()){
            
$objXml->open('country');  //open a <country node>
                
$objXml->data('iso',$o->iso);  //add a <iso>$o->iso</iso> element
                
$objXml->data('name',$o->printable_name); //the name
            
$objXml->close('country');  //close the country node
        
}
    
$objXml->close('countryList');//close the country list
    
$objXml->open('gndrList'); 
        
$GLOBALS['objDb']->q("SELECT * FROM genders");
        while(
$o=$GLOBALS['objDb']->fo()){
            
$objXml->open('gender');
                
$objXml->data('code',$o->gendercode);
                
$objXml->data('trad',$GLOBALS['objTrad']->getTrad($o->gendercode));
                
$objXml->data('order',$o->ordr);
            
$objXml->close();
        }
    
$objXml->close();
$objXml->close('DATAS'); //close the document 
This is what I use to gather the datas needed on signup page on a demo dating site. By the way, the demo site (which is far from being finished) is visible on http://dating.webalis.com. Try to look at the source of the pages, you'll see the XML.

So, this in PHP result in this XML document:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML>
<?xml-stylesheet href="/xsl/com.dating.signup" type="text/xsl"?>
<ROOT>
 <GENERAL>
  <title>XMLDate</title>
  <lng>fr</lng>
  <iso>CH</iso>
  <languages>
   <lang>
    <code>de</code>
    <trad>Allemand</trad>
   </lang>
   <lang>
    <code>en</code>
    <trad>Anglais</trad>
   </lang>
   <lang>
    <code>fr</code>
    <trad>Francais</trad>
   </lang>
   <lang>
    <code>it</code>
    <trad>Italien</trad>
   </lang>
  </languages>
  <user>
   <uid></uid>
   <userName/>
   <email/>
   <gndr/>
   <gndrSearch/>
   <zodiac>CAPRICORN</zodiac>
   <country/>
   <aboutMe/>
  </user>
 </GENERAL>
 <DATAS>
  <countryList>
   <country>
    <iso>AF</iso>
    <name>Afghanistan</name>
   </country>
   <country>
    <iso>AL</iso>
    <name>Albania</name>
   </country>
   <!-- ... cutted out a really long list ... -->
   <country>
    <iso>ZW</iso>
    <name>Zimbabwe</name>
   </country>
  </countryList>
  <gndrList>
   <gender>
    <code>MALE</code>
    <trad>Un homme</trad>
    <order>0</order>
   </gender>
   <gender>
    <code>FEMALE</code>
    <trad>Une femme</trad>
    <order>1</order>
   </gender>
  </gndrList>
 </DATAS>
</ROOT>
<!-- Generation time: 0.479296922684 -->
At the top of the XML document, you can see a
Code:
<?xml-stylesheet
instruction.
It tells the browser where to find the XSL to format those datas on screen.
Here is the XSL sheet:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:js="/js">
<xsl:output method="html" encoding="UTF-8" indent="yes"
            doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
            doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
            standalone="yes" omit-xml-declaration="yes"
            />
<!--com.webalis.open_html
08.11.2007, ts, Init 
            doctype-public="-//W3C//DTD HTML 4.01//EN"
            doctype-system="http://www.w3.org/TR/html4/strict.dtd"

 -->
<xsl:template match="/">
  <html>
    <head>
      <title><xsl:value-of select="/ROOT/GENERAL/title"/></title>
      <link rel="stylesheet" type="text/css" href="/css/base.css"/>
      <link rel="stylesheet" type="text/css" href="/css/profiles.css"/>
      <link rel="stylesheet" type="text/css" href="/css/tabs.css"/>
      <link rel="stylesheet" type="text/css" href="/css/header.css"/>
      <link rel="stylesheet" type="text/css" href="/js/calendar/calendar-win2k-cold-1.css" />
      <script type="text/javascript" src="/js/X.js"/>
      <script type="text/javascript" src="/js/rounded.js"/>
      <script type="text/javascript" src="/js/webJs.js"/>
      <script type="text/javascript" src="/js/global.js"/>
      <script type="text/javascript" src="/js/calendar/calendar.js"/>
      <script type="text/javascript" src="/js/calendar/lang/calendar-{/ROOT/GENERAL/lng}.js"/>
      <script type="text/javascript" src="/js/calendar/calendar-setup.js"/>
      <script type="text/javascript">
        
      </script>
      <xsl:call-template name="SCRIPTS"/>
      <xsl:call-template name="LINKS"/>
    </head>
    <body>
      <xsl:apply-templates select="ROOT"/>
    </body>
  </html>
</xsl:template>

<xsl:template match="ROOT">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="GENERAL"/>

<!-- FROM INCLUDE  com.dating.utils -->
<!-- com.dating.utils
5.12.2007 init
17.12.2007, Added template profile
              Used by => browse profiles

-->
<xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>

<xsl:template name="profile">
  <div class="userCont">
    <xsl:attribute name="class">
      userCont 
      <xsl:choose>
        <xsl:when test="gender='Un homme'">
          userM
        </xsl:when>
        <xsl:otherwise>
          userF
        </xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
      <a href="/user/{uid}"><xsl:value-of select="username"/></a>
      <xsl:choose>
        <xsl:when test="pic!=''">
          <img src="/img/user/{pic}" alt="trad key userPic not existant" title="trad key userPic not existant"/>
        </xsl:when>
      </xsl:choose>
      <p>
        Sexe: <xsl:value-of select="gender"/><br/>
      Cherche: <xsl:value-of select="gendersearch"/>
      </p>
      <p>
        <xsl:value-of select="aboutme" />
      </p>
    </div>
</xsl:template>
<!-- END INCLUDE  com.dating.utils-->

<!-- com.dating.signup
028.11.2007, ts, init

-->
<xsl:template name="SCRIPTS"/>
<xsl:template name="LINKS"/>

<xsl:template match="DATAS">
  <!-- FROM INCLUDE  com.dating.header -->
<!-- com.dating.header
028.11.2007, ts, init

-->
<div id="divHeader">
  <!-- FROM INCLUDE  com.dating.loginBox -->
<!--com.dating.loginBox.xsl
28.11.2007, ts, init
19.12.2007, ts, removed the bottom <br>
-->
<div id="divLogin" class="rounded" style="float:left">
  <xsl:variable name="User" select="/ROOT/GENERAL/user"/>
  <xsl:choose>
      <xsl:when test="$User/uid&gt;0">
      <xsl:variable name="Zodiac"><xsl:value-of select="translate($User/zodiac,$ucletters,$lcletters)"/></xsl:variable>
      
        <p style="padding:0 5px;">
        Bonjour <xsl:value-of select="$User/userName"/>.<br/>
        Bienvenue sur XMLDATE!<br/>
        <img src="/img/zodiac/{$Zodiac}_small.gif" width="32" alt="{$Zodiac}" title="{$Zodiac}"/>
      </p>
        <ul>
          <li>
            <a href="/my/">Votre page perso.</a>
          </li>
          <li>
            <a href="/actions/logout">Vous déconnecter.</a>
          </li>
        </ul>
      </xsl:when>
    <xsl:otherwise>
      <form id="frmLogin" method="post" action="/actions/login" js:ajax="on" onsubmit="return false;">
        <table>
          <tr>
            <th>
              Pseudo:
            </th>
            <td>
              <input type="text" name="inpTxtUserLog" id="inpTxtUserLog" />
            </td>
          </tr>
          <tr>
            <th>
              Mot de passe:
            </th>
            <td>
              <input type="password" name="inpPwdPassLog" id="inpPwdPassLog" />
            </td>
          </tr>
        </table>
        <p>
            <input type="submit" value="GO!" style="float:rigth"/>
            <span style="clear:both"/>
        </p>
          </form>
    </xsl:otherwise>
  </xsl:choose>
    
</div>

<!-- END INCLUDE  com.dating.loginBox-->
  <!-- FROM INCLUDE  com.dating.nav -->
<div class="rounded" id="divNav">
  <ul>
    <li>
      <a href="/">Page d'acceuil</a>
    </li>
    <li>
      <a href="/browse/">Profils d'utilisateurs</a>
    </li>
    <li>
      <a href="/ads/">Annonces</a>
    </li>
  </ul>
</div>
<!-- END INCLUDE  com.dating.nav-->
  <!-- FROM INCLUDE  com.dating.langSwitcher -->
<!--com.dating.langSwitcher
28.11.2007, ts, init

-->
<div id="divLngSwitch" class="rounded">
  <xsl:for-each select="/ROOT/GENERAL/languages/lang">
    <xsl:sort select="code"/>
    <div class="lang">
      <xsl:if test="code=/ROOT/GENERAL/lng">
        <xsl:attribute name="class">lang selected</xsl:attribute>
      </xsl:if>
      <a href="?LNG={code}" title="{trad}"><xsl:value-of select="code"/></a>
     </div>
  </xsl:for-each>
    <br style="clear:both" />
</div>
<span style="clear:both" />

<!-- END INCLUDE  com.dating.langSwitcher-->
  <br style="clear:both"/>
</div>
<br/>

<!-- END INCLUDE  com.dating.header-->
  <form method="post" action="/actions/signup" js:check="on">
  <div js:tab="Main">
    <table cellpadding="0" cellspacing="0" width="50%">
          <tbody>
            <tr>
              <th>
                Ton pseudo:
              </th>
              <td>
                <input type="text" name="inpTxtUser" id="inpTxtUser" js:check="^[a-zA-Z]((1))[a-zA-Z0-9]((5,));Votre nom d'utilisateur doit commencer par une lettre, et avoir une longueur de 6 charactères minimums.;5000" />
              </td>
            </tr>
            <tr>
              <th>
                Ton mot de passe:
              </th>
              <td>
                <input type="password" name="inpPwdPass" id="inpPwdPass" js:check=".((6,));Votre mot de passe doit faire 6 charactères minimums.;5000" />
              </td>
            </tr>
            <tr>
              <th>
                Répéte ton mot de passe stp:
              </th>
              <td>
                <input type="password" name="inpPwdPassRep" id="inpPwdPassRep" js:check=".((6,));Votre mot de passe doit faire 6 charactères minimums.;5000"/>
              </td>
            </tr>
            <tr>
              <th>
                Ton email:
              </th>
              <td>
                <input type="text" name="inpTxtEmail" id="inpTxtEmail" js:check="^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9]+)$;Votre adresse email semble invalide.;5000"/>
              </td>
            </tr>
          </tbody>
        </table>
  </div>
  <div js:tab="Prec">
    <table cellpadding="0" cellspacing="0" width="50%">
          <tbody>
            <tr>
              <th>
                Ta date de naissance:
              </th>
              <td>
                <input type="text" name="inpTxtBirth" id="inpTxtBirth" value="dd.mm.yyyy" js:check="[0-9]((2)).[0-9]((2)).[0-9]((4));Veuillez vérifier que la date entrée soit sous la forme jj.mm.yyyy;5000"/>
            <script type="text/javascript">
              Calendar.setup({
                                inputField     :    "inpTxtBirth",
                                ifFormat       :    "%d.%m.%Y",
                                showsTime      :    false,
                                timeFormat     :    "24",
                  firstDay       :    1
                            });
            </script>
              </td>
            </tr>
            <tr>
              <th>
                Ton pays:
              </th>
              <td>
                <select name="inpSelCntry" id="inpSelCntry">
                  <xsl:for-each select="countryList/country">
                    <option value="{iso}">
                      <xsl:if test="iso=/ROOT/GENERAL/iso">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                      </xsl:if>
                      <xsl:value-of select="name"/>
                    </option>
                  </xsl:for-each>
                </select>
              </td>
            </tr>
            <tr>
              <th>
                Tu es:
              </th>
              <td>
                <select name="inpSelGndr" id="inpSelGndr">
                  <xsl:for-each select="gndrList/gender">
                    <xsl:sort select="order" />
                    <option value="{code}"><xsl:value-of select="trad"/></option>
                  </xsl:for-each>
                </select>
              </td>
            </tr>
            <tr>
              <th>
                Tu cherches:
              </th>
              <td>
                <select name="inpSelGndrSrch" id="inpSelGndrSrch">
                  <xsl:for-each select="gndrList/gender">
                    <xsl:sort select="order" />
                    <option value="{code}"><xsl:value-of select="trad"/></option>
                  </xsl:for-each>
                </select>
              </td>
            </tr>
          </tbody>
        </table>
  </div>
  <div js:tab="About">
    <table cellpadding="0" cellspacing="0" width="50%">
          <tbody>
            <tr>
              <th>
                Descris-toi en quelques lignes
              </th>
            </tr>
            <tr>
              <td>
                <textarea name="inpTaAbout" id="inpTaAbout" cols="50" rows="10" js:check=".((20,));Veuillez donner au moins 20 charactères svp... C'est pas beaucoup...;5000"/>
              </td>
            </tr>
          </tbody>
        </table>
  </div>
  <p>
    <input type="submit" value="GO!"/>
  </p>
  </form>
  
  <!-- FROM INCLUDE  com.dating.footer -->
<!-- com.dating.header
028.11.2007, ts, init

-->
<div id="divFooter">
  <p>
      © webalis.com
      -
      <a href="/signup.php">Inscription</a>
  </p>
</div>

<!-- END INCLUDE  com.dating.footer-->
</xsl:template>

<!--com.webalis.close_html
08.11.2007, ts, Init 
-->
</xsl:stylesheet><!-- CACHED ON 2008-01-21 19:45:18.507501 -->
As you can see, this is almost an HTML file.
In fact, this style sheet is more to be considered like a template.
You can put XSL and XPATH instructions in it, to tell the XSL engine where it should replace datas taken from the XML.

For instance:
Code:
<title><xsl:value-of select="/ROOT/GENERAL/title"/></title>
Tells the engine that it must put the value contained in
/ROOT/GENERAL/title between the <title> tags.

You can define templates too, in the XSL, that you can call upon specific elements in the XML
Code:
<xsl:template name="profile">
  <div class="userCont">
    <xsl:attribute name="class">
      userCont 
      <xsl:choose>
        <xsl:when test="gender='Un homme'">
          userM
        </xsl:when>
        <xsl:otherwise>
          userF
        </xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
      <a href="/user/{uid}"><xsl:value-of select="username"/></a>
      <xsl:choose>
        <xsl:when test="pic!=''">
          <img src="/img/user/{pic}" alt="trad key userPic not existant" title="trad key userPic not existant"/>
        </xsl:when>
      </xsl:choose>
      <p>
        Sexe: <xsl:value-of select="gender"/><br/>
      Cherche: <xsl:value-of select="gendersearch"/>
      </p>
      <p>
        <xsl:value-of select="aboutme" />
      </p>
    </div>
</xsl:template>
This is used in conjunction with an XML block like that one:
Code:
  <profiles>
   <profile>
    <uid>3</uid>
    <username>thierry</username>
    <creadt>2008-01-09 23:55:30.626826</creadt>
    <lastlogin>2008-01-09 23:55:30.636639</lastlogin>
    <prevlogin/>
    <birthday>1975-03-30 00:00:00</birthday>
    <zodiac></zodiac>
    <aboutme>blah blah blah blah blah blah blah blah </aboutme>
    <email>tmo@webalis.com</email>
    <pic/>
    <countryiso>CH</countryiso>
    <gender>Un homme</gender>
    <gendersearch>Une femme</gendersearch>
  </profile>
 </profiles>
To generate a user profile.

This, for instance:
Code:
	            <select name="inpSelCntry" id="inpSelCntry">
	              <xsl:for-each select="countryList/country">
	                <option value="{iso}">
	                  <xsl:if test="iso=/ROOT/GENERAL/iso">
	                    <xsl:attribute name="selected">selected</xsl:attribute>
	                  </xsl:if>
	                  <xsl:value-of select="name"/>
	                </option>
	              </xsl:for-each>
	            </select>
Create a select with every values contained into the <countryList> node, and preselect the drop down onthe detected country.

The main advantage, is that you can delegate a bit of the work to the client.
What is great too, is that with this method, as you have a total separation between datas and visual informations, you can define several sets of SL style sheets, and switching from one to the other changes what is displayed.
Don't think just HTML here, but PDF too, or WAP, and mobile HTML.
The switch can be done via a simple
PHP Code:
$objXml->setRendering('wap'); 
for instance, and an alternate set of xsl file stored in a subdirectory "wap" will be used.
Thus, without touching your logic files, you can adapt a site to another format.

PDF can be generated from XML in a very similar way using an FOP engine. The apache project has released one ( http://xmlgraphics.apache.org/fop/ ), and it works perfectly.
Thrue, it's basedon java, but it does an excellent job nonetheless.

It's already a long post, and I'll stay here.
I hope this answer your question.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 01-21-2008 at 02:03 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-21-2008, 02:47 PM Re: Nothing to ask, just an announce to make...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Unfortunatly i think its just answerd im not quite there yet, took me long enough to figure out how to make a imple Rss feed for a site i was making, for events, i would like to make it styled but could never figure it out, everything seems to be so confusing to me with XML
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 01-21-2008, 03:04 PM Re: Nothing to ask, just an announce to make...
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
The key is that XML are only data.
There is strictly no visual formatting in XML.

If you want to, then you need either to use XSL, either to develop a method through DOM parsing to get the datas and display them yourself.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-21-2008, 03:23 PM Re: Nothing to ask, just an announce to make...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
This could be a solution to:-

http://www.webmaster-talk.com/coding...een-nodes.html
and
http://www.webmaster-talk.com/coding...xml-nodes.html
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-21-2008, 03:49 PM Re: Nothing to ask, just an announce to make...
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Hmmm, I looked at those posts, but they are more geared towards XML processing.
My class is designed to create content, and associate it formatting rules.

But gimme some times, and I'll surely will be able to come with something.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Nothing to ask, just an announce to make...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31059 seconds with 12 queries