SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    create xsl when php loads?

    hello all

    small headache here, i,mm trying to create xsl stylesheet when the page.php is accessed so as soon as you click page 2 it will create an xsl stylesheet in xslstyle.xsl.

    i have tried it using the fwrite but its a pain and doesnt do brackets or anythine like that errors everywhere.

    this is just to create the first line:

    <?php

    $handle=fopen("files/2.xml","w");
    fwrite($handle,"<?xml version=");
    fwrite($handle,"1.0");
    fwrite($handle,"encoding= ");
    fwrite($handle,"ISO-8859-1");
    fwrite($handle,"?>\n");
    fflush($handle);
    fclose($handle);
    ?>

    it produces:

    <?xml version=1.0encoding= ISO-8859-1?>

    not <?xml version="1.0" encoding="ISO-8859-1"?>

    i had a similar problem with creating the xml file but i found this in which creates the xml decleration

    code
    $newxml = '<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="files/wes_ica.xsl"?>';

    any ideas would be great on how to create this would be great

    thanks


  2. #2
    SitePoint Enthusiast Anne Thrax's Avatar
    Join Date
    Oct 2005
    Location
    Sydney, Australia
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    PHP Code:
    <?php

    $handle
    =fopen("files/2.xml","w");
    fwrite($handle,"<?xml version=");
    fwrite($handle,"\"1.0\" ");
    fwrite($handle,"encoding=");
    fwrite($handle,"\"ISO-8859-1\"");
    fwrite($handle,"?>\n");
    fflush($handle);
    fclose($handle);
    ?>

  3. #3
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    thanks for your help

    well try , while i,m doing that is that the only way of doing something like this

  4. #4
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Anne Thrax
    Try this:
    PHP Code:
    <?php

    $handle
    =fopen("files/2.xml","w");
    fwrite($handle,"<?xml version=");
    fwrite($handle,"\"1.0\" ");
    fwrite($handle,"encoding=");
    fwrite($handle,"\"ISO-8859-1\"");
    fwrite($handle,"?>\n");
    fflush($handle);
    fclose($handle);
    ?>

    hi anne thrax

    works treat thanks

    tell me i have to do this for basicaly this xsl (small sample), but do i have to do it using the fwrite statement through out?

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="2.0" xmlnssl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
    <head>
    <link rel="stylesheet" type="text/css" href="stylesheets/second.css" />
    </head>
    <body>
    <h2>wseica 2</h2>
    <table border="1">
    <tr bgcolor="#9acd32">
    <th align="left">id</th>
    <th align="left">county_UA</th>
    </tr>
    <xsl:for-each select="id">
    <tr>
    <td><xsl:value-of select="id/></td>
    <td><xsl:value-of select="favourite_instrument"/></td>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

  5. #5
    SitePoint Enthusiast Anne Thrax's Avatar
    Join Date
    Oct 2005
    Location
    Sydney, Australia
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do something like this (untested but should work):
    PHP Code:
    <?php
    $xmlcontent 
    ="
    <?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n
    <xsl:stylesheet version=\"2.0\" xmlnssl=\"http://www.w3.org/1999/XSL/Transform\">\n
    <xsl:template match=\"/\">\n
    <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" >\n
    <head>\n
    <link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheets/second.css\" />\n
    </head>\n
    <body>\n
    <h2>wseica 2</h2>\n
    <table border=\"1\">\n
    <tr bgcolor=\"#9acd32\">\n
    <th align=\"left\">id</th>\n
    <th align=\"left\">county_UA</th>\n
    </tr>\n
    <xsl:for-each select=\"id\">\n
    <tr>\n
    <td><xsl:value-of select=\"id/></td>\n
    <td><xsl:value-of select=\"favourite_instrument\"/></td>\n
    </tr>\n
    </xsl:for-each>\n
    </table>\n
    </body>\n
    </html>\n
    </xsl:template>\n
    </xsl:stylesheet>\n"
    ;
    $handle=fopen("files/2.xml","w");
    fwrite($handle,"$xmlcontent");
    fflush($handle);
    fclose($handle); 
    ?>

  6. #6
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Anne Thrax
    Do something like this (untested but should work):
    PHP Code:
    <?php
    $xmlcontent 
    ="
    <?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n
    <xsl:stylesheet version=\"2.0\" xmlnssl=\"http://www.w3.org/1999/XSL/Transform\">\n
    <xsl:template match=\"/\">\n
    <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" >\n
    <head>\n
    <link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheets/second.css\" />\n
    </head>\n
    <body>\n
    <h2>wseica 2</h2>\n
    <table border=\"1\">\n
    <tr bgcolor=\"#9acd32\">\n
    <th align=\"left\">id</th>\n
    <th align=\"left\">county_UA</th>\n
    </tr>\n
    <xsl:for-each select=\"id\">\n
    <tr>\n
    <td><xsl:value-of select=\"id/></td>\n
    <td><xsl:value-of select=\"favourite_instrument\"/></td>\n
    </tr>\n
    </xsl:for-each>\n
    </table>\n
    </body>\n
    </html>\n
    </xsl:template>\n
    </xsl:stylesheet>\n"
    ;
    $handle=fopen("files/2.xml","w");
    fwrite($handle,"$xmlcontent");
    fflush($handle);
    fclose($handle); 
    ?>

    hiya

    i just did this, i'll try your method as well

    <?php
    //create 1st line
    $handle=fopen("files/2.xsl","w");
    fwrite($handle,"<?xml version=");
    fwrite($handle,"\"1.0\" ");
    fwrite($handle,"encoding=");
    fwrite($handle,"\"ISO-8859-1\"");
    fwrite($handle,"?>\n");
    //create 2nd line
    fwrite($handle,"<xsl:stylesheet version=");
    fwrite($handle,"\"2.0\" ");
    fwrite($handle,"xmlnssl=");
    fwrite($handle,"\"http://www.w3.org/1999/XSL/Transform\"");
    fwrite($handle,">\n");
    //create 3rd line
    fwrite($handle,"<xsl:template match=");
    fwrite($handle,"\"/\"");
    fwrite($handle,">\n");
    //create 4th line
    fwrite($handle,"<html xmlns=");
    fwrite($handle,"\"http://www.w3.org/1999/xhtml\"");
    fwrite($handle,"xml:lang=");
    fwrite($handle,"\"en\"");
    fwrite($handle,">\n");
    //create 5th line
    fwrite($handle,"<head>");
    fwrite($handle,"\n");
    //create 6 line
    fwrite($handle,"<link rel=");
    fwrite($handle,"\"stylesheet\" ");
    fwrite($handle,"type=");
    fwrite($handle,"\"text/css\"");
    fwrite($handle,"href=");
    fwrite($handle,"\"files/second.css\"");
    fwrite($handle,"/>\n");
    //create 7 line
    fwrite($handle,"</head>");
    fwrite($handle,"\n");
    //create 8th line
    fwrite($handle,"<body>");
    fwrite($handle,"\n");


    thanks for ur help

  7. #7
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi Anne

    it hink your method is much better as i can see everything that i,m doing, many thanks i hope you dont mind me asking u all these questions.

    thanks



Bookmarks

Posting Permissions

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