473,735 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT processing instruction to use PHP

Hi!

I've got me an XSL tranformation stylesheet for my XML file. In the XSL
file I now wish to use PHP to do some scripting. So I thought I'll use
the PIs like this:

<xsl:processi ng-instruction name="php">
echo $hello;
</xsl:processing-instruction>

But this just gets ignored. No error, just not processed. Do I need to
enable something (in PHP, Apache) to use these PIs?

This is on an Apache/2.0.49 (Win32) PHP/4.3.6 Server.

Thank you for any pointers.
hayko
Jul 17 '05 #1
9 4166
Hayko Riemenschneider wrote:
Hi!

I've got me an XSL tranformation stylesheet for my XML file. In the
XSL file I now wish to use PHP to do some scripting. So I thought
I'll use the PIs like this:

<xsl:processi ng-instruction name="php">
echo $hello;
</xsl:processing-instruction>

But this just gets ignored. No error, just not processed. Do I need to
enable something (in PHP, Apache) to use these PIs?

This is on an Apache/2.0.49 (Win32) PHP/4.3.6 Server.


A processing-instruction does not execute the code within. The following
example:

<xsl:template match="/">
<xsl:processi ng-instruction name="foo">
<xsl:text>type= "txt/xml"</xsl:text>
</xsl:processing-instruction>
</xsl:template>

Only generates the following tag in the output:

<?foo type="txt/xml"?>

Which doesn't do anything.

If you want to use PHP functions in your XSLT stylesheet, you can do this
through the document() function.

See the examples in the following manual page:

http://nl2.php.net/manual/en/functio...e-handlers.php

And yes, this requires the parsing of the stylesheet to be done by PHP's
XSLT extension...
JW

Jul 17 '05 #2
Janwillem Borleffs wrote:
And yes, this requires the parsing of the stylesheet to be done by
PHP's XSLT extension...

I have found another way, using the PHP cli and msxsl (an msxml wrapper),
without the need to have the XSLT extension installed:

XSLT (test.xslt):
====
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<?php echo "test"?>
</xsl:template>
</xsl:stylesheet>

XML (test.xml, just to have something to work with):
====
<?xml version="1.0" encoding="iso-8859-1" ?>
<root />

Command line:
========== php test.xslt | msxsl -o test.html test.xml -
When you have the short_open_tag directive enabled in your php.ini file, you
can disable it temporary using the -d option:
php -d short_open_tag= off test.xslt | msxsl -o test.html test.xml -


This way, test.xslt gets parsed by the PHP interpreter first and the output
is catched by msxsl (indicated by the last hyphen). The generated test.html
will contain the following:

<?xml version="1.0" encoding="UTF-16"?>
test

Needless to mention that this example only works on Windows platforms.

Perhaps this is useful to you...
JW

Jul 17 '05 #3
On 06.09.2004 00:31, Janwillem Borleffs wrote:
A processing-instruction does not execute the code within. The
following example: [..] <?foo type="txt/xml"?>
Thanks for clearing that up. I was under illusion PHP code would be
magically executed. ;-)
If you want to use PHP functions in your XSLT stylesheet, you can do
this through the document() function.
I started on the examples. But it seems awefully complicated. Isn't
there an another way to PHP parse the XML or XSL file before it gets
XML/XSLT parsed?
And yes, this requires the parsing of the stylesheet to be done by
PHP's XSLT extension...


Yup, I've got them installed. The 'normal' parsing works now, just not
with the extra PHP code inside.

Thanks for the help
hayko
Jul 17 '05 #4
On 06.09.2004 01:06, Janwillem Borleffs wrote:
I have found another way, using the PHP cli and msxsl (an msxml
wrapper), without the need to have the XSLT extension installed:
[.. example of what I was looking for..]
Needless to mention that this example only works on Windows
platforms.


Thank you for looking into that. It is actually exactly what I was
looking for, just without the extra command line piping.

I'm eventually going to run this on a different machine, with just PHP
and hopefully browsers able of XSLT processing.

I wish to grab session specific variables and use them whilst processing
my XML file.

hayko
Jul 17 '05 #5
lets say you have the resultant transformation produced by
http://localhost/transform.php
which produces
<?xml version="1.0"?>
<test><?php echo "test" ?></test>
then to reprocess it, just call it from another PHP script like so
include_once "http://localhost/transform.php";
Of course this requires short open tags to be off. But it is simpler
than anything else. You can use this rechnique for any sort of
processing pipeline but be careful when getting a script to recursively
call itself :)
I haven't tried this myself but I think I read somehwere that protocol
identifiers (like "http://") are supported by include statements. It
should work.
Jul 17 '05 #6
I have not yet come across a legitimate need to re-process with
PHP/XSLT. Issues like this can usually be resolved by superior design.

I assume you are well aware that you can pass strings to the XSLT
processor when you call the xslt_process() function (see last argument).

so, $a = array("msg" => "this is a test");

could be passed to XSLT via

xslt_process(,, ,,$a); // insert other params as required (can use NULLs)

and would be used in the XSLT like

<xsl:param name="msg" select="''" />

You MUST include the above line! The value will be overwritten with the
one supplied from PHP.

Jul 17 '05 #7
On 06.09.2004 04:00, Terence wrote:
I have not yet come across a legitimate need to re-process with
PHP/XSLT. Issues like this can usually be resolved by superior
design.
I'm working on the design... =)
I assume you are well aware that you can pass strings to the XSLT
processor when you call the xslt_process() function (see last
argument).


I understand, yet I wish to leave out the PHP processing of the XML.
Ideally, I'd only use the XSLT with the XML file and that's it. But I
wish to add some dynamics and with this I wanted to use the session
variables.

Is there no way - other than PHP processing the XML file or using the
windows pipeline example from Janwillem's post - to use a bit of PHP?

I experimented with adding .xml or .xsl files to the preprocessed file list
by my Apache PHP module. As this works fine with .html files, it kills
the browser with .xml or .xls files.

hayko
Jul 17 '05 #8
Hayko Riemenschneider wrote:
On 06.09.2004 00:31, Janwillem Borleffs wrote:
If you want to use PHP functions in your XSLT stylesheet, you can do
this through the document() function.


I started on the examples. But it seems awefully complicated. Isn't
there an another way to PHP parse the XML or XSL file before it gets
XML/XSLT parsed?


Sure, just give them an .php extension.

If you do your transformations client-side, chance is that some browsers,
like IE, won't recognize the files as XML -- in that case, and if you're
running the scripts off Apache with MultiView enabled, add the .php
extension to their normal extensions (i.e. file.xml.php and file.xslt.php)
and call them without the .php (e.g. file.xml).

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #9
On 06.09.2004 14:09, Berislav Lopac wrote:
Hayko Riemenschneider wrote:
Isn't there an another way to PHP parse the XML or XSL file before
it gets XML/XSLT parsed?
Sure, just give them an .php extension. If you do your
transformations client-side, chance is that some browsers, like IE,
won't recognize the files as XML


This is the case, and I was hoping to do all the XSLT client-side. But
that won't work along with the PHP. Especially since the browser won't
make that callback to ask for the PHP evaluation.
-- in that case, and if you're running the scripts off Apache with
MultiView enabled, add the .php extension to their normal extensions
(i.e. file.xml.php and file.xslt.php) and call them without the .php
(e.g. file.xml).


That's actually quite nifty. I could use a dummy PHP script to process
the .xml file and then spit it out as output to the browser for the
client-side transformation.

Thanks for the hint!
hayko
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1579
by: Bernd Fuhrmann | last post by:
Hi! I have two (or more) templates for one certain tag: The first one: tobeimported.xsl: <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"
8
2164
by: Maciej Wegorkiewicz | last post by:
Hi, I have small experience in XSLT processing and I have a problem which I cannot solve. Can you look at it? I have an input file containing info about bank accounts like this: (...) <acc id="1"> <balance>100</balance>
4
5242
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); } if (x) {
3
9922
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ========================= <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"
3
4828
by: Gordon Moore | last post by:
Hi, I'm new to using xml/xslt and although I can create an xml document using the dataset.WriteXml statement, and I have created an xslt to transform the xml into the output I want, I have to manually add the xsl reference statement to the xml file. i.e. <?xml version="1.0" standalone="yes"?> <?xml:stylesheet type="text/xsl" href="Questions.xsl"?> --> I have to
1
2066
by: daniele74 | last post by:
Hy, I want ask you this question. I have two schema file schema1.xsd and schema2.xsd. then I have a stylesheet transformation style2.xsl that show in a browser an xml file that has schema2.xml as schema. moreover I have an xslt tranformation that map schema1.xsd in schema2.xsd (schema1TOschema2.xslt). so the question is: it is possible to use style2.xsl to view xml file that has schema1 as schema?? with instractions similar to this...
5
2181
by: Dennis Benzinger | last post by:
How can I copy the xml declaration from one document to another document using XSLT? (Use case: I have a xml document where I just want to add a processing instruction without modifing the rest of the document) Thanks, Dennis
2
5442
by: RccH | last post by:
Beginner using xslt... So. I have an XML file which has a link into xslt file like following... <?xml version='1.0' encoding='utf-8' ?> <?xml-stylesheet type="text/xsl" href="transform.xsl"?> <customersrest of the xml.... So How, using C# or VB.NET do I apply that xsl file into this same xmlfile and write the transformed file into disk? Any help would be appreciated...
0
8959
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
8784
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
9326
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8199
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
6747
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
4558
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3270
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
2738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.