473,657 Members | 2,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP code from XSL won't execute

Dormilich
8,658 Recognized Expert Moderator Expert
Hi,

I'm running into a problem with the <xsl:processi ng-instruction> element (Sablotron).

purpose:
I generate a xhtml fragment from a xml file via xslt. This is printed (echo) to the output (i.e. all xml/xsl processing is done on the server). This is fine, as long as the output contains only xhtml.

problem:
one special page uses AJAX, where the result is taken from a MySQL database. To make it easier writing copy, I (sucessfully) use php code to paste the link (and the content, if Javascript is not activated):
Expand|Select|Wrap|Line Numbers
  1. # top of included file
  2. # lib.db.php is used for MySQL processing
  3.     include_once(SYS_DIR . "lib.db.php");
  4.     $artikel =& new AjaxRequest;
  5.  
  6. # for each link
  7.     $artikel->getArticle("__DB-entry-ID__");
  8.  
this will result in:
Expand|Select|Wrap|Line Numbers
  1. # for each link
  2.   <div id="__DB-entry-ID__" class="einzug">
  3.     <a id="a__DB-entry-ID__" class="cfa" href="main.php?AOD=__DB-entry-ID__#a__DB-entry-ID__">Artikeltext anschauen</a>
  4.   </div>
  5.  
so far no problem when I include it from a file–but now the same as output from a xsl transformation:

It will readily transform the <xsl:processi ng-instruction> into php code, but the code is not parsed afterwards (even though the DOM recognizes it later as a processing instruction) it looks more like a CDATA section. I find the PHP code afterwards in the xhtml file, just like that:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     include_once(SYS_DIR . "lib.db.php");
  3.     $artikel =& new AjaxRequest;
  4. ?>
  5.   <h4><a class="hook" id="h6">__Title-of-Item__</a></h4>
  6.   <p>__Publication-Date__, __Newspaper-Name__</p>
  7.   <div class="mitte">
  8.     <img src="bilder/presse/__IMG-source__" title="__IMG-title__" width="__IMG-width__" height="__IMG-height__" />
  9.   </div>
  10. <?php
  11.     $artikel->getArticle("__DB-entry-ID__");
  12. ?>
  13.  
does anyone have an idea, how I can get PHP to parse the output from the xsl transformation?

thanks in advance

file listings:

xml file (presse.xml) (representative entry):
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE presse [ ... ]]>
  2. <presse
  3.     xmlns="http://www.kulturbeutel-leipzig.net/XML/presse"
  4.     xmlns:link="http://www.kulturbeutel-leipzig.net/XML/link"
  5.     xmlns:dcterms="http://purl.org/dc/terms/">
  6.  
  7. <collection title="__Title-of-Item__">
  8.   <item db="__DB-entry-ID__">
  9.     <zeitung>__Newspaper-Name__</zeitung>
  10.     <datum>__Publication-Date__</datum>
  11.     <thumbnail src="__IMG-source__" wdt="__IMG-width__" hgt="__IMG-height__">
  12.        <title>__IMG-Title__</title>
  13.     </thumbnail>
  14.   </item>
  15. </collection>
  16.  
  17. </presse>
  18.  
xsl file (sys.presse.xsl )
(I skip the further templates here, because they don't provide more information):
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1" ?>
  2. <xsl:stylesheet version="1.0"
  3.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4.     xmlns:html="http://www.w3.org/1999/xhtml"
  5.     xmlns:presse="http://www.kulturbeutel-leipzig.net/XML/presse">
  6.  
  7. <xsl:output
  8.     method="xml"
  9.     encoding="iso-8859-1"
  10.     omit-xml-declaration="yes"
  11.     indent="yes" />
  12.  
  13. <xsl:template match="/">
  14.   <xsl:element name="div">
  15.     <xsl:attribute name="id">
  16.       <xsl:text>zeitung</xsl:text>
  17.     </xsl:attribute>
  18.  
  19.     <xsl:text>
  20.   </xsl:text>
  21.     <xsl:element name="h1">
  22.       <xsl:text>Zeitungsausschnitte</xsl:text>
  23.     </xsl:element>
  24.  
  25.     <xsl:text>
  26.   </xsl:text>
  27.     <xsl:element name="p">
  28.       <xsl:attribute name="class">
  29.         <xsl:text>mitte</xsl:text>
  30.       </xsl:attribute>
  31.       <xsl:text>oder was man so in den Zeitungen so über uns findet …</xsl:text>
  32.     </xsl:element>
  33.  
  34. # here comes the php code, if I don't escape & and > I'll get a parser error
  35.     <xsl:processing-instruction name="php">
  36.     include_once(SYS_DIR . "lib.db.php");
  37.     $artikel =&amp;amp; new AjaxRequest;
  38.     </xsl:processing-instruction>
  39.  
  40.     <xsl:apply-templates />
  41.  
  42.   </xsl:element>
  43. </xsl:template>
  44.  
  45. <xsl:template match="//presse:collection">
  46.   <xsl:call-template name="heading" />
  47.   <xsl:for-each select="child::presse:item">
  48.     <xsl:call-template name="titel" />
  49.     <xsl:if test="attribute::db">
  50.         <xsl:call-template name="text" />
  51.     </xsl:if>
  52.     <xsl:if test="child::presse:thumbnail">
  53.        <xsl:call-template name="bild" />
  54.     </xsl:if>
  55.     <xsl:if test="child::presse:file">
  56.        <xsl:call-template name="download" />
  57.     </xsl:if>
  58.     <xsl:if test="child::presse:url">
  59.        <xsl:call-template name="verweis" />
  60.     </xsl:if>
  61.   </xsl:for-each>
  62. </xsl:template>
  63. </xsl:stylesheet>
  64.  
php calling hierarchy:

top level script: main.php
creates an object and calls the output function
Expand|Select|Wrap|Line Numbers
  1.     require_once("system/lib.main.php");
  2.     $inhalt =& new ContentOutput($_GET["__page-ID__"]);
  3.     $inhalt->DataInhalt();
  4.  
php library: lib.main.php
does the part of putting it all together
Expand|Select|Wrap|Line Numbers
  1. # the xslt parser (in a nutshell) (SYS_DIR is where all the files are)
  2.  
  3.     function parseXSLT($xml, $xsl, $par = NULL, $args = array()) {
  4.         $xml = SYS_DIR . $xml;
  5.         $xsl = SYS_DIR . $xsl;
  6.         $handle = xslt_create();
  7.         $parsedfile = xslt_process($handle, $xml, $xsl, NULL, $args, $par);
  8.         xslt_free($handle);
  9.         return $parsedfile;
  10.     }
  11.  
  12. # $this->ID is set when calling the object in the first place
  13. # $this->Data is an array of objects containing the information for every web page like: include file or files and parameters for xslt (either of them)
  14.  
  15.     function DataInhalt() {
  16. # set of parameters for xsl processing
  17.         $parameter = NULL;
  18.         $xmlfile = 'Struktur.xml';
  19.         $xslfile = $this->Data[$this->ID]->datei["xsl"];
  20.         $tempxml = $this->Data[$this->ID]->datei["xml"];
  21.         $temppar = $this->Data[$this->ID]->datei["para"];
  22.         $tempfile = $this->Data[$this->ID]->datei["file"];
  23.         if (!empty($tempxml)) {
  24.             $xmlfile = $tempxml;
  25.         }
  26.         if (!empty($temppar)) {
  27.             $parameter = array($temppar => $this->ID);
  28.         }
  29. # if there's a file, include it an quit function
  30.         if (!empty($tempfile)) {
  31.             include(BASE_DIR . $tempfile);
  32.             return;    
  33.         }
  34. # do xsl processing
  35.         if (!$KBL_inhalt = $this->parseXSLT($xmlfile, $xslfile, $parameter)) {
  36.             echo '<p class="mitte b">Parser Error</p>';
  37.             return;
  38.         }
  39.         else {
  40. # print result
  41.              print $KBL_inhalt;
  42.         }
  43.     }
  44.  
System: Apache 1.3.4 / Mac OS X 10.4.11 / PHP 4.3.1 (from entropy.ch)
Aug 12 '08 #1
1 2479
Dormilich
8,658 Recognized Expert Moderator Expert
problem solved

I now write the result string to file (at the first page load after the xml was updated) and load that file via include().
Sep 5 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
29806
by: Mark Anderson | last post by:
Problem in short: user is moving (clicking a link) from my page before some JS code is run (to write a cookie). The code does not run (in Body's onLoad event) until the page loads as there are a number of images which can take a while to load on a slow connection. Using fewer/different graphics is not an option! The code writing a cookie the is called in the Body's onLoad event: <body onLoad="setLast();">
8
3032
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to what I really should do. I've had a look through Programming Python and the Python Cookbook, which have given me ideas, but nothing has gelled yet, so I thought I'd put the question to the community. But first, let me be a little more detailed...
2
2457
by: Greg Strong | last post by:
Hello All, I've written code in a test database with test data. Everything seems to be working except compact database in VB code per http://www.mvps.org/access/general/gen0041.htm. The reason I say this is the auto number fields are NOT being reset to zero. I delete the data from tables with action delete queries, then call the compact DB code which is followed by importing data to tables and subsequent append queries to other tables....
18
2880
by: Simon | last post by:
I was of the impression that code placed after a Try...Catch block was only executed if there was no exception thrown. I've got some VB.net code as part of a Windows form that executes even when an exception is thrown - it behaves as if the code is part of a finally block. Looking through all the documentation and MSDN articles, it seems that none of the examples contain code placed
11
15403
by: Max | last post by:
I'm writing a program that needs to be able to create custom .job files and add them to the scheduled tasks folder. What I'd like to know is, what is the format of a .job file and how do I go about adding in all the data so that the task could run correctly? If that is something not so easy to do, then say I need a certain part of my program to execute on a schedule... How do I go about writing some internal scheduling routine that won't...
88
8037
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
10
1676
by: Jeff | last post by:
Hey gang. i have a code that i will list. when varM = 8 or 16, the script works fine, and pulls the top 8 or top 16, but if it =32 or 64, it is only pulling the top 17 records from the DB. db is access and this is MS server. here is the code <% if varm = 8 then set admin6 = conn.execute("select top 8 username, iCHECK from
9
1688
by: Martijn Mulder | last post by:
Hi group, It is tempting to jump into .NET programming, especially C# in my case. But I have no idea what the realm is of code based on the CLR. Please inform me of the following: -what versions of Windows can execute .NET code? -can I deliver dll-files to older Windows versions? (ME, 2000, 98) so as to run .NET code? -what percentage of today's software is written using the .NET architecture?
135
7445
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the situation behind it, and which is proper.
5
2017
by: r_ahimsa_m | last post by:
Hello, I am learning PHP5. I would like to ask experienced programmers if you use PHP5 code obfuscation? I am writing website in Linux and I consider using some code obfuscator because I don't trust hosting firms, I wouldn't like to have my code stolen because it contains some good idea. Thanks in advance for your answers. /RAM/
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.