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:processing-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 9 4140
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:processing-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:processing-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
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:stylesheet 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
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
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
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.
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.
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
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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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"
|
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...
|
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 =...
|
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
...
|
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...
|
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...
|
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...
|
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"?>...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
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...
|
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...
|
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: 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...
| |