|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
evaluating php expressions using Sablotron
Hi,
I am using php >4.1, with Sablotron. I have both an xml and xsl file, and use sablotron to output html. But the php expressions inside these files are not evaluated (i.e. left out in the html-file) How can they be evaluated for sure? Richard (most examples use sablotron with php4.0 and are therefore not of much use...) |
|
#2
|
|||
|
|||
|
Where are the PHP expressions? Inside the XML file or the XSL?
I had a similar issue where I wanted processing instructions inside the XSL to be executed during XSL transformation. Look at the xslt_set_sax_handlers() function. I believe if you set a processing instruction handler, you can execute the PHP code. xslt_set_sax_hanlders() takes an array of the handlers. You can see an example at the doc page for xslt_set_sax_handler(), but that function is discontinued as of PHP 4.0.6+. PHP Code:
This should execute the code() function in that XML document when it's parsed. I'll try this out when I get home to see if I get any errors. Also, I believe it will execute before the transformation. I don't know how to return a string from the processing instruction handler to be inserted into the resulting document at the point that the instruction is received at. |
|
#3
|
|||
|
|||
|
php-expressions are in both, xml-file and xsl-file...
|
|
#4
|
|||
|
|||
|
Ok, it was kind of odd to execute a PI in an XSL file. I had to use the syntax to create a PI in the resulting transformed document:
PHP Code:
This would create the code PHP Code:
Now, if you wanted that to output something in the template, I don't really know how to insert that in the spot where the PI is located at. I didn't get this crap working the way I liked, so I think I'm moving over to Smarty Templates. I don't know if there's some way to assign the output of the PI to an XSL variable and use it in your stylesheet, or what. If someone could figure that out, I'd be very interested. Last edited by spaceMonkey : May 22nd, 2002 at 08:02 AM. |
|
#5
|
|||
|
|||
|
I am this far, and really stuck, right now...
Here is what I have: index.php: PHP Code:
processing instruction handler isn't working... $target contains 'php' when found an pi. But the $data does contains 'blah blah' (no data). Further it does process the code inside the pihandler, but I still can't pass php code to it. (in php4.0 the arguments were like in: function PIHandler($parser, $target, $data), I changed the order, so that $target contains 'php' when an pi is encountered) ---------------- The xml file contains sometimes pieces of php code like: PHP Code:
------ The xsl-file contains a piece like: PHP Code:
But nothing seems to work... ------ It's really frustrating: I mean, I just want to evaluate some php code inside the xml and xsl files. What's the big deal? Why should this be so complicated? Please help. Thanks, Richard Last edited by Lionheart : May 23rd, 2002 at 04:26 PM. |
|
#6
|
|||
|
|||
|
What's really frustrating is the little help you can get online. I haven't had a chance to play around with your examples...
|
|
#7
|
|||
|
|||
|
Well, I am stuck, still am.
Hope you or someone else can shed light on it... Richie ![]() |
|
#8
|
|||
|
|||
|
I can't get the XML PIs to even execute when transforming. As for the XSL ones, I got it to execute the PHP code, but it just echoes "hello" or whatever at the top of the resulting document.
I can't figure out how to store a return value of a function into the resulting document. Have you checked out Krysalis? It's an XML/XSL engine inspired by Cocoon, but it's completely written in PHP... |
|
#9
|
|||
|
|||
|
I had the same problem (maybe because the data model places xml and PI's at the same level, and starts with PI's?). I made some changes / progress. I will post it later. It is still not complete, but a lot better...
I will at Krysalis. Thanks for the wink. Richie |
|
#10
|
|||
|
|||
|
It is working!
(I use Sablotron and php4.1+) Here is what I have at this moment: index.php: PHP Code:
----- ABOUT PI-HANDLER: $target contains 'php' when found an pi. But the $data does contains 'blah blah' (no data). The 'hello' and 'other 'blahblah' came from the previous PI-handler (the line: echo $data; // not working...) Fact is, it is still not working as expected... But when given a value to a variable, it will be passed to the html output... --------- file.xml: PHP Code:
This file contains php-code, that needs to be evaluated! Also a piece $datum that got a value from the index.php. Wow! --------- file.xsl: PHP Code:
______________________ QUESTIONs xsl_file: PHP Code:
QUESTION 1.: My footer include-file contains <?php ... ?>. This results in a parser error... Who can bring in a solution on this? --------- xsl_file: PHP Code:
QUESTION 2.: My xsl_file contains also <?php ... ?>. This is simply left out in the output. Who can bring in a solution on this? ______________________ Hope this helps you! Hopefully can you give me some help as well! Richard L. Last edited by Lionheart : June 1st, 2002 at 06:25 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > evaluating php expressions using Sablotron |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|