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): -
# top of included file
-
# lib.db.php is used for MySQL processing
-
include_once(SYS_DIR . "lib.db.php");
-
$artikel =& new AjaxRequest;
-
-
# for each link
-
$artikel->getArticle("__DB-entry-ID__");
-
this will result in: -
# for each link
-
<div id="__DB-entry-ID__" class="einzug">
-
<a id="a__DB-entry-ID__" class="cfa" href="main.php?AOD=__DB-entry-ID__#a__DB-entry-ID__">Artikeltext anschauen</a>
-
</div>
-
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: -
<?php
-
include_once(SYS_DIR . "lib.db.php");
-
$artikel =& new AjaxRequest;
-
?>
-
<h4><a class="hook" id="h6">__Title-of-Item__</a></h4>
-
<p>__Publication-Date__, __Newspaper-Name__</p>
-
<div class="mitte">
-
<img src="bilder/presse/__IMG-source__" title="__IMG-title__" width="__IMG-width__" height="__IMG-height__" />
-
</div>
-
<?php
-
$artikel->getArticle("__DB-entry-ID__");
-
?>
-
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): -
<!DOCTYPE presse [ ... ]]>
-
<presse
-
xmlns="http://www.kulturbeutel-leipzig.net/XML/presse"
-
xmlns:link="http://www.kulturbeutel-leipzig.net/XML/link"
-
xmlns:dcterms="http://purl.org/dc/terms/">
-
-
<collection title="__Title-of-Item__">
-
<item db="__DB-entry-ID__">
-
<zeitung>__Newspaper-Name__</zeitung>
-
<datum>__Publication-Date__</datum>
-
<thumbnail src="__IMG-source__" wdt="__IMG-width__" hgt="__IMG-height__">
-
<title>__IMG-Title__</title>
-
</thumbnail>
-
</item>
-
</collection>
-
-
</presse>
-
xsl file (sys.presse.xsl )
(I skip the further templates here, because they don't provide more information): -
<?xml version="1.0" encoding="iso-8859-1" ?>
-
<xsl:stylesheet version="1.0"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-
xmlns:html="http://www.w3.org/1999/xhtml"
-
xmlns:presse="http://www.kulturbeutel-leipzig.net/XML/presse">
-
-
<xsl:output
-
method="xml"
-
encoding="iso-8859-1"
-
omit-xml-declaration="yes"
-
indent="yes" />
-
-
<xsl:template match="/">
-
<xsl:element name="div">
-
<xsl:attribute name="id">
-
<xsl:text>zeitung</xsl:text>
-
</xsl:attribute>
-
-
<xsl:text>
-
</xsl:text>
-
<xsl:element name="h1">
-
<xsl:text>Zeitungsausschnitte</xsl:text>
-
</xsl:element>
-
-
<xsl:text>
-
</xsl:text>
-
<xsl:element name="p">
-
<xsl:attribute name="class">
-
<xsl:text>mitte</xsl:text>
-
</xsl:attribute>
-
<xsl:text>oder was man so in den Zeitungen so über uns findet …</xsl:text>
-
</xsl:element>
-
-
# here comes the php code, if I don't escape & and > I'll get a parser error
-
<xsl:processing-instruction name="php">
-
include_once(SYS_DIR . "lib.db.php");
-
$artikel =&amp; new AjaxRequest;
-
</xsl:processing-instruction>
-
-
<xsl:apply-templates />
-
-
</xsl:element>
-
</xsl:template>
-
-
<xsl:template match="//presse:collection">
-
<xsl:call-template name="heading" />
-
<xsl:for-each select="child::presse:item">
-
<xsl:call-template name="titel" />
-
<xsl:if test="attribute::db">
-
<xsl:call-template name="text" />
-
</xsl:if>
-
<xsl:if test="child::presse:thumbnail">
-
<xsl:call-template name="bild" />
-
</xsl:if>
-
<xsl:if test="child::presse:file">
-
<xsl:call-template name="download" />
-
</xsl:if>
-
<xsl:if test="child::presse:url">
-
<xsl:call-template name="verweis" />
-
</xsl:if>
-
</xsl:for-each>
-
</xsl:template>
-
</xsl:stylesheet>
-
php calling hierarchy:
top level script: main.php
creates an object and calls the output function -
require_once("system/lib.main.php");
-
$inhalt =& new ContentOutput($_GET["__page-ID__"]);
-
$inhalt->DataInhalt();
-
php library: lib.main.php
does the part of putting it all together -
# the xslt parser (in a nutshell) (SYS_DIR is where all the files are)
-
-
function parseXSLT($xml, $xsl, $par = NULL, $args = array()) {
-
$xml = SYS_DIR . $xml;
-
$xsl = SYS_DIR . $xsl;
-
$handle = xslt_create();
-
$parsedfile = xslt_process($handle, $xml, $xsl, NULL, $args, $par);
-
xslt_free($handle);
-
return $parsedfile;
-
}
-
-
# $this->ID is set when calling the object in the first place
-
# $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)
-
-
function DataInhalt() {
-
# set of parameters for xsl processing
-
$parameter = NULL;
-
$xmlfile = 'Struktur.xml';
-
$xslfile = $this->Data[$this->ID]->datei["xsl"];
-
$tempxml = $this->Data[$this->ID]->datei["xml"];
-
$temppar = $this->Data[$this->ID]->datei["para"];
-
$tempfile = $this->Data[$this->ID]->datei["file"];
-
if (!empty($tempxml)) {
-
$xmlfile = $tempxml;
-
}
-
if (!empty($temppar)) {
-
$parameter = array($temppar => $this->ID);
-
}
-
# if there's a file, include it an quit function
-
if (!empty($tempfile)) {
-
include(BASE_DIR . $tempfile);
-
return;
-
}
-
# do xsl processing
-
if (!$KBL_inhalt = $this->parseXSLT($xmlfile, $xslfile, $parameter)) {
-
echo '<p class="mitte b">Parser Error</p>';
-
return;
-
}
-
else {
-
# print result
-
print $KBL_inhalt;
-
}
-
}
-
System: Apache 1.3.4 / Mac OS X 10.4.11 / PHP 4.3.1 (from entropy.ch)
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().
Sign in to post your reply or Sign up for a free account.
Similar topics |
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();">
|
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...
|
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....
|
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
|
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...
| |
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.
|
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
|
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?
|
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.
|
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/
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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();...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |