473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP code from XSL won't execute

Dormilich
8,658 Expert Mod 8TB
Hi,

I'm running into a problem with the <xsl:processing-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:processing-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 2460
Dormilich
8,658 Expert Mod 8TB
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
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...
8
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...
2
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...
18
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...
11
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...
88
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
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...
9
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...
135
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.