phrame web development platform
download  | documentation  | resources  | credits 


 


Phrame Example: Xml class

This is a short example of how to use the Xml class.


<?php
//create Test2 class
class Test2
{
    var 
$_test2var;
    var 
$_test2num;
    var 
$_test2array;

    function 
Test2()
    {
        
$this->_test2var 'test2';
        
$this->_test2num 101;
        
$this->_test2array = array('food' => 'pizza''color' => 'red');
    }
}
//create Test class
class Test extends Xml
{
    var 
$_testvar;
    var 
$_testnum;
    var 
$_testarray;
    var 
$_testobject;

    function 
Test()
    {
        
$this->_testvar 'test';
        
$this->_testnum 100;
        
$this->_testarray = array('one' => 1'two' => 2'three' => 3);
        
//hold copy of Test2
        
$this->_testobject = new Test2();
    }
}

//create instance of Test
$test = new Test();
//marshal Test class into xml
//**if Test class did not subclass Xml, use "$xml = Xml::marshal($test);"
$xml $test->marshal();
//display marshalled Test class
echo '<b>Test class</b><br/><pre>'.Xml::xmlentities($xml).'</pre><hr/>';
$first Xml::transform($xml, array('first.xsl'));
//display transform with only first.xsl
echo '<b>first.xsl</b><br/><pre>'.Xml::xmlentities($first).'</pre><hr/>';
$second Xml::transform($xml, array('first.xsl''second.xsl'));
//display transform pipeline with first.xsl and second.xsl
echo '<b>second.xsl</b><br/><pre>'.Xml::xmlentities($second).'</pre>';
?>

first.xsl

This stylesheet does the first part of the pipeline transform: xml->xml->html

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="test">
    <favorites>
    <xsl:for-each select="_testobject/_test2array/value">
        <favorite>
            <xsl:attribute name="type">
                <xsl:value-of select="@key"/>
            </xsl:attribute>
            <xsl:value-of select="."/>
        </favorite>
    </xsl:for-each>
    </favorites>
</xsl:template>
</xsl:stylesheet>

second.xsl

This stylesheet does the second part of the pipeline transform: xml->xml->html

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="favorites">
    <html>
    <body>
    <p>favorites</p>
    <ul>
    <xsl:for-each select="favorite">
        <li><xsl:value-of select="@type"/>: <xsl:value-of select="."/></li>
    </xsl:for-each>
    </ul>
    </body>
    </html>
</xsl:template>
</xsl:stylesheet>

That completes the short example of how to use the Xml class.


 

software development Software Development
Copyright © 2002 Texas Tech University
All rights reserved.
Last modified: November 19 2002 16:47:22

SourceForge Logo