Sorry for the long post from a newbee! I’m in the process of moving the sites I have running on a windows ASP web server to a Linux PHP web server. A lot of my pages have variable data that is stored in XML files. I have XSL files that will convert the data into web page format, but I’m having trouble getting the Linux server to do the translate. Here is the ASP code that I use to do the translate in-line:
The page.asp file would use a server side include to place the xml data where desired:
The ShowXml.inc file contains the ASP code to display the XML data:Code:<TR> <TD><!--#include file="ShowXml.inc"--> </TD> <TD><IMG HEIGHT="238" WIDTH="277" SRC="image.jpg"></TD> </TR>
OK, since I’m asking for some help with the PHP coding, let me give a little demo of the XML / XSL coding in return.Code:<% ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' Function to display the XML with XSL translation '' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function ShowCatalog Dim xml Dim xsl Dim xslname xslname = "xdb/MyFormat.xsl" 'Load XML set xml = Server.CreateObject("Microsoft.XMLDOM") xml.async = false xml.load(Server.MapPath("xdb/MyData.xml")) 'Load XSL set xsl = Server.CreateObject("Microsoft.XMLDOM") xsl.async = false xsl.load(Server.MapPath(xslname)) 'Transform file Response.Write(xml.transformNode(xsl)) set xml = Nothing set xsl = Nothing End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' Main Process '' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Do not break on an error. On Error Resume Next ShowCatalog End If %>
The XML file might look like this:
The XML file contains a stylesheet reference to the XSL file that I will be using. That way when I bring it up on my local browser it will do the translate so I can see the results. The top-level events item contains multiple event items. Each event has an “id” so it can be referenced by an administration function (that one might be my next question, but first things first). The “date” which will be displayed relates to the “index” which is used for sorting the events in each “column” of the final table. The “link” is used as the navigation point that surrounds the multiple “lines” of display.Code:<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="MyFormat.xsl"?> <events> <event> <id>1</id> <column>1</column> <index>080409</index> <date>April 9, 2008</date> <link>http://www.yahoo.com</link> <line1>Yahoo</line1> <line2>A search Engine</line2> </event> <event> <id>2</id> <column>2</column> <index>080405</index> <date>April 5, 2008</date> <link>http://www.google.com</link> <line1>Google</line1> <line2>Another search engine</line2> </event> </events>
Here is the XSL file that converts the events into a two-column table of data:
MyFormat.xsl
Note how the html coding is interspersed with xsl commands. The data is selected by event, it is then sorted by the “index” YYMMDD, then tested for column 1 and column 2 of the table. The xsl:value-of is used to insert the xml data into the html stream. Note the use of curly braces instead of the value-of syntax to insert the link inside an html command.Code:<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <table class="Events" border="0"> <tr> <td class="EventCol" valign="top"> <xsl:for-each select="/Events/event"> <xsl:sort select="index" order="ascending"/> <xsl:if test="column = '1'"> <div class="EventDate"><xsl:value-of select="date"/></div> <xsl:if test="string-length(link)"> <a HREF="{link}" TARGET=""> <xsl:if test="string-length(line1)"> <xsl:value-of select="line1"/> </xsl:if> <xsl:if test="string-length(line2)"> <br/><xsl:value-of select="line2"/> </xsl:if> <xsl:if test="string-length(line3)"> <br/><xsl:value-of select="line3"/> </xsl:if> </a><br/><br/> </xsl:if> </xsl:if> </xsl:for-each> </td> <td class="EventGut"/> <td class="EventCol" valign="top"> <xsl:for-each select="/Events/event"> <xsl:sort select="index" order="ascending"/> <xsl:if test="column = '2'"> <div class="EventDate"><xsl:value-of select="date"/></div> <xsl:if test="string-length(link)"> <a HREF="{link}" TARGET=""> <xsl:if test="string-length(line1)"> <xsl:value-of select="line1"/> </xsl:if> <xsl:if test="string-length(line2)"> <br/><xsl:value-of select="line2"/> </xsl:if> <xsl:if test="string-length(line3)"> <br/><xsl:value-of select="line3"/> </xsl:if> </a><br/><br/> </xsl:if> </xsl:if> </xsl:for-each> </td> </tr> </table> </xsl:template> </xsl:stylesheet>
I would be interested in exchanging e-mail addresses with anyone who would like to know more about css, xml and xsl in return for more help with php.
Thanks in advance for the assistance,
PapaGeek


Reply With Quote
Bookmarks