How can I include a user defined php function in xsl?

I have a menu function in config.php file that I want to include in an xsl file.  The xsl file is transforming an xml file to html.  I have include the files below. How can I include the menu function in the xsl file?  I can't just do   <?php menu(); ?> in the xsl where I want the menu.
config.php
chart.xml
chart.xsl
dmalovichAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information ArchitectCommented:
<?php menu(); ?>
can be added like this

   <xsl:processing-instruction name="php">
      <xsl:text>menu(); ?</xsl:text>
   </xsl:processing-instruction>
if you serialize as html
or
   <xsl:processing-instruction name="php">
      <xsl:text>menu(); </xsl:text>
   </xsl:processing-instruction>
if you serialise as xml
0
dmalovichAuthor Commented:
Thanks.   I've added your code and the menu still doesn't show up.  Is there anything else that needs to be added?  How does it know to get the menu function from config.php file?
chart.xsl
0
Gertone (Geert Bormans)Information ArchitectCommented:
I am not a php programmer... at all,
if you tell me how the resulting html should look like, I can make that happen,
but I have no clue how to point to the config.php
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

dmalovichAuthor Commented:
OK.  Thanks very much for trying.
0
Gertone (Geert Bormans)Information ArchitectCommented:
mmh, can you just take the resulting html now,
add what you normally would add for making the php work in the result file
and send it, so I can make it
Note that you need to serve up the html with a webserver that knows about php,
the php will not be activated on a standalone file
0
dmalovichAuthor Commented:
OK. Here is the html file called chart.php.  It has the include file for config and then it calls the menu function.
chart.php
0
Gertone (Geert Bormans)Information ArchitectCommented:
This is the start of the XSLT,
it is somewhat tricky, sincve you need to add the process instruction for the config prior to the doctype
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   
   <xsl:output method="html" indent="yes" />
   <xsl:template match="/">
      <xsl:processing-instruction name="php">
         <xsl:text>&#13;&#10;require_once('config.php');&#13;&#10;?</xsl:text>
      </xsl:processing-instruction>
      <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">]]>
      </xsl:text>
      
      <html>
         <head> 
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />  
            
            <title></title>
         </head>
         <body>  
            <xsl:processing-instruction name="php">
               <xsl:text>menu(); ?</xsl:text>
            </xsl:processing-instruction>
            <div id="chart">
               
               <xsl:apply-templates select="stocks/stock">
               </xsl:apply-templates>
               
            </div>
         </body>
      </html>
   </xsl:template>
...

Open in new window

0
dmalovichAuthor Commented:
I tried your code and the menu is still not showing up.  
0
Gertone (Geert Bormans)Information ArchitectCommented:
have you checked the result from the transform?

Note that I expect that you run the XSLT server side.
I don't think you can make this work if you run the XSLT cleint side.
It will definitely not work on FireFox, since FF does not support disable-output-escaping

Try to serve up the static page you sent me.
Does the menu work with that?
If it does, try to find out what gets served up as the transform result.
 I have tested on various XSLT1 processors and it gave me exactly what you sent
0
dmalovichAuthor Commented:
How do I run this on the server side?
0
Gertone (Geert Bormans)Information ArchitectCommented:
http://www.tonymarston.net/php-mysql/xsl.html
check the part on
"Invoking the XSLT process and displaying the result"
0
dmalovichAuthor Commented:
I have found out that it can't be done.
0
Gertone (Geert Bormans)Information ArchitectCommented:
please show us the references then, I am not convinced that it can't be done
0
Gertone (Geert Bormans)Information ArchitectCommented:
please show us the references then, I am not convinced that it can't be done
0
Gertone (Geert Bormans)Information ArchitectCommented:
> I have a menu function in config.php file that I want to include in an xsl file.

was your original question, and in answering this question we have gone  a long way doing exactly that.

It could be that in your execution of the XSLT, the PHP processor no longer gets hold of the resulting html, so it can't process the menu.
If that is the case, you will have to process the XSLT in advance (some earlier stage you could add,
and let the PHP processor import the html resulting from the XSLT, so it can execute stuff on finding the PHP menu.

please bear in mind that originally you were looking for a way to add <?php menu(); ?> to an html, through XSLT,
and that question has been answered
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dmalovichAuthor Commented:
it isn't what I was looking for
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.