Results 1 to 4 of 4

Thread: How to read xml file and apply css to it using php

Threaded View

  1. #1

    Thread Starter
    Lively Member rasana's Avatar
    Join Date
    Jan 2007
    Location
    Mumbai, (India)
    Posts
    94

    Resolved How to read xml file and apply css to it using php

    Hi all,

    I have 'abc.xml' file and 'abc.xsl' file

    my work is to read abc.xml file and display such a way that css of abc.xsl should apply to abc.xml

    i.e. data of xml file should display in <table><tr><td> format of abc.xsl

    I'm giving those 2 files

    abc.xml
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    	<xmlticker>
    <pause>6000</pause>
    		<message> :: DIAMONDS OFFER :: MQ G VVS1 | 1.50 CTS |  |  | 4000 USD</message>
    		<message> :: BUY COLOUR STONES :: AMETHYST | 4.78 CTS | MARQUISE GREEN | STONE | 19 USD</message>
    		<message> :: JEWELLERY OFFERS :: BANGLES | 18K | YELLOW GOLD | DIAMONDS STUDDED | 2215 USD</message>
    		<message> :: DIAMOND DEMANDS :: HEART | 2.00-2.50 | G-I VS1-VS2 | CERTIFIED ONLY</message>
    		<message> :: COLOUR STONES DEMANDS :: TOURMALINE OVAL | 1.70-1.75</message>
    		<message> :: BLUE COLOUR STONES DEMANDS :: TWILIGHT TOPAZ ROUND | 10 CTS  | ANY COLOR | PAIR</message>
    		<message> :: JEWELLERY DEMANDS :: REVIERA NECKLACE | 0.35 CTS | YELLOW GOLD | DIAMONDS</message>
    		<message> :: JEWELLERY DEMANDS :: BRACELET | 5MM | SILVER | PEARL</message>
    	</xmlticker>
    abc.xls

    Code:
    <?xml version='1.0'?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        version="1.0">
      
    <xsl:template match="/">
      <link href="polygon_offers.css" rel="stylesheet" type="text/css" />
    <html>
    <body bgcolor="A2A2A2">
      <table width="750" border="0" align="left" cellpadding="0" cellspacing="0" padding="0" class="table_border">
        <tr>
          <td>
              <table width="750" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="table_border">
              <tr>
                <td height="80" colspan="2" align="left" valign="top">
                 <table width="750" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="123" height="80" align="center" valign="middle" class="header_bg"><img src="images/Jckindia.jpg" width="61" height="65" /></td>
                  <td width="450" height="80" align="right" valign="middle" class="header_bg"><span class="header_title">Offers by</span><span class="net_title"></span></td>
                  <td width="152" align="left" valign="middle" class="header_bg"><img src="images/polygon-logo.gif" width="187" height="50" /></td>
                  <td width="25" align="right" valign="middle" class="header_bg"></td>
                </tr>
            </table>
                </td>
              </tr>
              <tr>
                <td height="2" colspan="2" class="horizontal_sep_yellow"></td>
              </tr>
              <tr>
                <td height="25" colspan="2"></td>
              </tr>
              <tr>
                <td width="590"></td>
                <td width="160">
                  <a target="_blank" href="http://www.abc.net"  ><img src="images/btn_getmore.gif" width="132" height="31"  border="0"/></a>
                </td>
              </tr>
              <tr>
                <td height="25" colspan="2"></td>
              </tr>
              <tr>
                <td colspan="2" align="center" valign="middle">
    <table width="695" height="157" border="0" cellpadding="0" cellspacing="0" class="table_border">
      <tr>
        <td width="1" rowspan="3" align="left" valign="top" bgcolor="#EBEBEB"></td>
        <td height="1" align="left" valign="top" bgcolor="#EBEBEB"></td>
        <td width="1" rowspan="3" align="left" valign="top" bgcolor="#EBEBEB"></td>
      </tr>
      <tr>
        <td align="left" valign="top">
          <table width="693" border="0" cellpadding="0" cellspacing="1">
            <tr >
              <td height="25" class="table_head">Offer</td>
              <td height="25" class="table_head">Type</td>
              <td height="25" class="table_head">Specifications</td>
              <td height="25" class="table_head">Color</td>
              <td height="25" class="table_head">Stone</td>
              <td height="25" class="table_head">Price</td>
            </tr>
            <xsl:for-each select="/xmlticker/message">
              <xsl:variable name="text" select="child::node()" />
              <tr >
                <td height="25" class="table_detail" >
                  <xsl:variable name='Offer' select='substring-after($text,"::")'/>
                  <xsl:variable name='Offers' select='substring-before($Offer,"::")'/>
                  <xsl:value-of select="$Offers"/>
                </td>
                <td height="25" class="table_detail" >
                  <xsl:variable name='Type2' select='substring-after($text,"::")'/>
                  <xsl:variable name='Type1' select='substring-after($Type2,"::")'/>
                  <xsl:variable name='Type' select='substring-before($Type1,"|")'/>
                  <xsl:value-of select="$Type"/>
                </td>
                <td height="25" class="table_detail" >
                  <xsl:variable name='Type' select='substring-after($text,"|")'/>
                  <xsl:variable name='Type1' select='substring-before($Type,"|")'/>
                  <xsl:value-of select="$Type1"/>
                </td>
                <td height="25" class="table_detail" >
                  <xsl:variable name='Type' select='substring-after($text,"|")'/>
                  <xsl:variable name='Type1' select='substring-after($Type,"|")'/>
                  <xsl:variable name='Type2' select='substring-before($Type1,"|")'/>
                  <xsl:value-of select="$Type2"/>
                </td>
                <td height="25" class="table_detail" >
                  <xsl:variable name='Type' select='substring-after($text,"|")'/>
                  <xsl:variable name='Type1' select='substring-after($Type,"|")'/>
                  <xsl:variable name='Type2' select='substring-after($Type1,"|")'/>
                  <xsl:variable name='Type3' select='substring-before($Type2,"|")'/>
                  <xsl:value-of select="$Type3"/>
                </td>
                <td height="25" class="table_detail_price" >
                  <xsl:variable name='Type'  select='substring-after($text,"|")'/>
                  <xsl:variable name='Type1' select='substring-after($Type,"|")'/>
                  <xsl:variable name='Type2' select='substring-after($Type1,"|")'/>
                  <xsl:variable name='Type3' select='substring-after($Type2,"|")'/>
                  <xsl:value-of select="$Type3"/>
                </td>
              </tr>
              </xsl:for-each>
    </table>
        </td>
      </tr>
      <tr>
        <td height="1" align="left" valign="top" bgcolor="#EBEBEB"></td>
       </tr>
    </table>
    <br/>
    </td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr>
    <td></td>
    <td>
    <a target="_blank" href="http://www.abc.net"  ><img src="images/btn_getmore.gif" width="132" height="31" border="0" /></a>
    </td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    Last edited by rasana; Feb 7th, 2008 at 11:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width