php and xml
Posted: Fri May 25, 2007 5:26 am
feyd | Please use
XML_DOC.xml FILE
XSL_DOC.xsl FILE
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi
How do I get my xsl template to display. I got the xml feed included using php but need to manipulate the data as defined in my xsl template.
Currently the data is just displayed on the screen as:
"MY PROMOTION
XXX Mr Joe Bloggs Marketing Ltd
ADR1 ADR2 ADR3 ADR4 XXX XXX
1 APR 2007apr07351.20 1 MAY 2007may070.00 1 JUN 2007jun0749.50 1 JUL 2007jul070.00 1 AUG 2007aug070.00 1 SEP 2007sep070.00 1 OCT 2007oct070.00 1 NOV 2007nov070.00 1 DEC 2007dec070.00 1 JAN 2008jan080.00 1 FEB 2008feb080.00 1 MAR 2008mar080.00 5000.00 8.01 NO Only £4599.30 required to achieve your Target, validate your points and enable you to start claiming rewards 0 0 0 1010"
I AM USING PHP 4.3
heres the code
INDEX.PHP FILECode: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<table>
<tr>
<td>
<table>
<tr>
<td>MY PROMOTION</td>
</tr>
</table>
<?php
echo('<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="XSL_DOC.xsl"?>');
include("XML_DOC.xml"); ?>
</td>
</tr>
</table>
</body>
</html>
?>XML_DOC.xml FILE
Code: Select all
<data>
<userid>JB88</userid>
<contractor>
<name>Mr Joe Bloggs</name>
<companyname>Marketing Ltd</companyname>
<address><line1>ADR1</line1>
<line2>ADR2</line2>
<line3>ADR3</line3>
<line4>ADR4</line4>
<postcode>XXX XXX</postcode></address>
</contractor>
<cstatement>
<monthlist>
<month><date>1 APR 2007</date><description>apr07</description><amount>351.20</amount></month>
<month><date>1 MAY 2007</date><description>may07</description><amount>0.00</amount></month>
<month><date>1 JUN 2007</date><description>jun07</description><amount>49.50</amount></month>
<month><date>1 JUL 2007</date><description>jul07</description><amount>0.00</amount></month>
<month><date>1 AUG 2007</date><description>aug07</description><amount>0.00</amount></month>
<month><date>1 SEP 2007</date><description>sep07</description><amount>0.00</amount></month>
<month><date>1 OCT 2007</date><description>oct07</description><amount>0.00</amount></month>
<month><date>1 NOV 2007</date><description>nov07</description><amount>0.00</amount></month>
<month><date>1 DEC 2007</date><description>dec07</description><amount>0.00</amount></month>
<month><date>1 JAN 2008</date><description>jan08</description><amount>0.00</amount></month>
<month><date>1 FEB 2008</date><description>feb08</description><amount>0.00</amount></month>
<month><date>1 MAR 2008</date><description>mar08</description><amount>0.00</amount></month>
</monthlist>
<target>5000.00</target>
<percent>8.01</percent>
<validated>NO</validated>
<message>Only £4599.30 required to achieve your Target, validate your points and enable you to start claiming rewards</message>
<points><total>0</total>
<redeemed>0</redeemed>
<remain>0</remain>
<spent>1010</spent></points>
<rewardlist>
</rewardlist></cstatement>
</data>
XSL_DOC.xsl FILE
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
<xsl:template match="/">
<html>
<body>
<h2><xsl:value-of select="data/contractor/name"/> <br/> <xsl:value-of select="data/contractor/companyname"/></h2>
<table>
<tr bgcolor="#ffff00">
<td>
<strong>ADDRESS</strong><br/>
<xsl:value-of select="data/contractor/address"/>,<br/>
<xsl:value-of select="data/contractor/address/line2"/>,<br/>
<xsl:value-of select="data/contractor/address/line3"/>,<br/>
<xsl:value-of select="data/contractor/address/line4"/>,<br/>
<xsl:value-of select="data/contractor/address/postcode"/>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Date</th>
<th align="left">Amount</th>
</tr>
<xsl:for-each select="data/cstatement/monthlist/month">
<tr>
<td><xsl:value-of select="date"/></td>
<td><xsl:value-of select="amount"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]