#16
  1. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    :(


    and so? what shall we study??
  2. #17
  3. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: :(


    Study the new XSLT extention. I don't know if anyone has written any articles on it but php.net has updated the manual.

    Cheers Sam
  4. #18
  5. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: pdf transformation


    these are actually two files: one generates an xml document from a database, the other a PDF from the same. i had a session object in memory so i did it that way, but the functions are almost exactly the same, so you should be able to go from XML to PDF relatively easy.

    XML
    ======
    $doc = new_xmldoc("1.0");
    $root = $doc->add_root("quote");
    $root->set_attribute("id",$_SESSION["quote"]->qotid);
    $cust = $root->new_child("customer","");
    $cust->set_attribute("id",$_SESSION["quote"]->cusid);
    $cfg = $root->new_child("config", "");

    $result = mysql_query("select * from engines");
    $chars_rev = preg_split('//', $_SESSION["compare"]->engine, -1, PREG_SPLIT_NO_EMPTY);
    $chars = array_reverse($chars_rev);
    $thread = bindec($_SESSION["compare"]->thread);
    $thread == -1 ? $thread = "st1" : $thread = "mt".$thread;

    while($row = mysql_fetch_array($result))
    {

    if (isset($chars[$row["engid"]]) && $chars[$row["engid"]] == 1)
    {
    $engine = $cfg->new_child("engine",$row["descr"]);
    $engine->set_attribute("thread",$thread);
    $engine->set_attribute("price",$row[$thread]);
    }

    }

    var2xmlchild($_SESSION["compare"],$cfg,"subscription","subid","subscription");
    var2xmlchild($_SESSION["compare"],$cfg,"support","supid","support");
    $adapts = $cfg->new_child("adaptors", "");
    array2xmlchild($_SESSION["compare"],$adapts,"adaptors","adpid","adaptor");
    $maps = $cfg->new_child("maps", "");
    array2xmlchild($_SESSION["compare"],$maps,"maps","mapid","map");



    echo $doc->dumpmem();
    ?>

    <?php
    function array2xmlchild(&$compare,&$child,$dbtablename,$dbcolname,$childname)
    {

    $chars_rev = preg_split('//', $compare->$dbtablename, -1, PREG_SPLIT_NO_EMPTY);
    $chars = array_reverse($chars_rev);
    $result = mysql_query("select * from $dbtablename");
    while($row = mysql_fetch_array($result))
    {
    if (isset($chars[$row[$dbcolname]]) && $chars[$row[$dbcolname]] == 1)
    {

    $childchild = $child->new_child("$childname", $row["descr"]);
    $childchild->set_attribute("price",$row["price"]);
    }
    }
    }
    function var2xmlchild(&$compare,&$child,$dbtablename,$dbcolname,$childname)
    {

    $chars_rev = preg_split('//', $compare->$dbtablename, -1, PREG_SPLIT_NO_EMPTY);
    $chars = array_reverse($chars_rev);
    $result = mysql_query("select * from $dbtablename");
    while($row = mysql_fetch_array($result))
    {
    if (isset($chars[$row[$dbcolname]]) && $chars[$row[$dbcolname]] == 1)
    {

    $childchild = $child->new_child("$childname", $row["descr"]);
    //$childchild->set_attribute("price",$row["price"]);
    }
    }
    }

    PDF file
    =========
    $result = mysql_query("select * from engines");
    $chars_rev = preg_split('//', $_SESSION["compare"]->engine, -1, PREG_SPLIT_NO_EMPTY);
    $chars = array_reverse($chars_rev);
    $thread = bindec($_SESSION["compare"]->thread);
    $thread == -1 ? $thread = "st1" : $thread = "mt".$thread;

    while($row = mysql_fetch_array($result))
    {

    if (isset($chars[$row["engid"]]) && $chars[$row["engid"]] == 1)
    {
    pdf_set_font($pdf, "Verdana", 12, "host");
    pdf_set_value($pdf, "textrendering", 2);
    pdf_show_xy($pdf, "Engine: $row[descr], $thread", 50, 700);
    pdf_set_font($pdf, "Verdana", 12, "host");
    pdf_set_value($pdf, "textrendering", 2);
    pdf_show_xy($pdf, "$row[$thread]", 400, 700);

    }

    }
    pdf_set_font($pdf, "Verdana", 12, "host");
    pdf_set_value($pdf, "textrendering", 2);
    pdf_show_xy($pdf, "Subscription", 50, 680);
    var2pdf($_SESSION["compare"],"subscription","subid",$col,660);
    pdf_show_xy($pdf, "Support", 50, 640);
    var2pdf($_SESSION["compare"],"support","supid",$col,620);

    pdf_show_xy($pdf, "Adaptors", 50, 600);
    pdf_set_font($pdf, "Verdana", 10, "host");
    pdf_set_value($pdf, "textrendering", 2);
    pdf_show_xy($pdf, "Maps", 50, 320);
    array2pdf($_SESSION["compare"],"adaptors","adpid",$col,580);
    array2pdf($_SESSION["compare"],"maps","mapid",$col,300);
    pdf_end_page($pdf);
    pdf_close($pdf);

    //$data = pdf_get_buffer($pdf);

    //header("Content-type: application/pdf");
    //header("Content-disposition: inline; filename=test.pdf");
    //header("Content-length: " . strlen($data));

    if i could get the XSLT support working like it is supposed to, i could show you a code snippet that uses XSL to do the same thing. wih a little luck, maybe soon.

    HTH-
    grant
  6. #19
  7. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: Re: pdf transformation


    BLEAH!

    the formatting is UNREADABLE!

    if you need this code email me privately at gbabb@datajunction.com.

    :).
    grant.
  8. #20
  9. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)
  10. #21
  11. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)
  12. #22
  13. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)
  14. #23
  15. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)
  16. #24
  17. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)
  18. #25
  19. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)
  20. #26
  21. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)
  22. #27
  23. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)
  24. #28
  25. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)
  26. #29
  27. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    AxKit: Better way to do XSLT (without php)


    There is an open-source package called AxKit that essentially is an apache mod that handles the XML/XSL transformations on the fly without the use of a scripting language. http://axkit.org/
  28. #30
  29. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    xslt_process changed


    Nice article! but somewhat out of date ...
    the function xslt_process changed and is now the main function you use for xslt transformations.

    http://www.php.net/manual/en/function.xslt-process.php

IMN logo majestic logo threadwatch logo seochat tools logo