This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > August 2005 > How to insert scripts into xml or xsl





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to insert scripts into xml or xsl
Ikke

2005-08-16, 7:43 pm

Hi,

I've got the following problem. I?ve made some XML & xslt files that
generate html pages. But now I wanted to add a piece off php-code into
the html files, but that doesn?t work?

When the XML & xslt file are parsed the php-code is immediately
activated and does not appear in the html file or when I use
<![CDATA[<?php include("test.php"); ?>]]> then the PHP code is visible
as text!

So, anyone a bright idea how to put a <?php echo(?test?) ?> piece
directly into a xslt document?

Thanks!
Ikke :-)))


Gale

2005-08-16, 7:43 pm

Ikke wrote:
> Hi,
>
> I've got the following problem. I?ve made some XML & xslt files that
> generate html pages. But now I wanted to add a piece off php-code into
> the html files, but that doesn?t work?
>
> When the XML & xslt file are parsed the php-code is immediately
> activated and does not appear in the html file or when I use
> <![CDATA[<?php include("test.php"); ?>]]> then the PHP code is visible
> as text!
>
> So, anyone a bright idea how to put a <?php echo(?test?) ?> piece
> directly into a xslt document?
>
> Thanks!
> Ikke :-)))
>
>

you don't put PHP code into XML file, you can create XML file with php
Neil Smith [MVP Digital Media]

2005-08-17, 7:21 am

I think you're approaching this the wrong way round. But if you *do*
need to use the output of the xslt processor to add PHP code to the
output stream, you'd need to have :

$xmldata=domxml_dump_mem($xml);
eval($xmldata);

Read http://uk.php.net/eval for information on the eval function, but
*expect* unanticipated side effects and extreme problems in debugging.

IMO you'd be much better passing in the output of the test.php script
as a string parameter to the XSLT, and inserting the value of the
parameter using <xsl:copy-of select="$paramname" /> in the xsl
instead.

HTH
Cheers - Neil

On Tue, 16 Aug 2005 20:05:30 +0200, "Ikke"
<ara.myftp@NietSpammenAUB@zonnet.nl> wrote:

>Hi,
>
>I've got the following problem. I?ve made some XML & xslt files that
>generate html pages. But now I wanted to add a piece off php-code into
>the html files, but that doesn?t work?
>
>When the XML & xslt file are parsed the php-code is immediately
>activated and does not appear in the html file or when I use
><![CDATA[<?php include("test.php"); ?>]]> then the PHP code is visible
>as text!
>
>So, anyone a bright idea how to put a <?php echo(?test?) ?> piece
>directly into a xslt document?
>
>Thanks!
>Ikke :-)))
>


Ikke

2005-08-17, 7:39 pm

Neil Smith [MVP Digital Media] was zeer hard aan het denken :
> I think you're approaching this the wrong way round. But if you *do*
> need to use the output of the xslt processor to add PHP code to the
> output stream, you'd need to have :
>
> $xmldata=domxml_dump_mem($xml);
> eval($xmldata);
>
> Read http://uk.php.net/eval for information on the eval function, but
> *expect* unanticipated side effects and extreme problems in debugging.
>
> IMO you'd be much better passing in the output of the test.php script
> as a string parameter to the XSLT, and inserting the value of the
> parameter using <xsl:copy-of select="$paramname" /> in the xsl
> instead.
>
> HTH
> Cheers - Neil


I know it sounds a bit ridiculous to put PHP code in xslt. But all my
programming is only with XML and xslt. So it?s a massive task to switch
all my programming to work with php, as it should be. The inserted php
code should be a sort of temporarily solution, till I know enough of
all programming languages to put all the pieces in the right order :-)

But I think your xsl:copy-of solution might work. Thanks for your
input!

Thanks!
Ikke :-)))

--


Met vriendelijke groet,

Ikke
~~~~~~~~~~~~~~~~~~~~~~~~~
ftp://upload:upload@ara.myftp.org:21
~~~~~~~~~~~~~~~~~~~~~~~~~

Marvin Smit

2005-08-19, 7:23 am

Hi,

to add to this post;

Remember that the "php" piece in the XML/XSLT is 'plain old text' from
the XML/XSLT perspective. You're generating something (*that by
coincidence ;) is PHP code) to be executed when viewing the results of
the XML/XSLT transformation.

Therefore it makes the most sense to:

- Push this piece of text in a <xsl:text /> block.
- Push this piece in the XSLT processor as parameter.
- Push this piece in the XML and have the XSLT render it to output.

Hope this helps,

Marvin Smit.


On Wed, 17 Aug 2005 19:26:01 +0200, "Ikke"
<ara.myftp@NietSpammenAUB@zonnet.nl> wrote:

>Neil Smith [MVP Digital Media] was zeer hard aan het denken :
>
>I know it sounds a bit ridiculous to put PHP code in xslt. But all my
>programming is only with XML and xslt. So it?s a massive task to switch
>all my programming to work with php, as it should be. The inserted php
>code should be a sort of temporarily solution, till I know enough of
>all programming languages to put all the pieces in the right order :-)
>
>But I think your xsl:copy-of solution might work. Thanks for your
>input!
>
>Thanks!
>Ikke :-)))


Ikke

2005-08-19, 7:34 pm

Marvin Smit stelde de volgende uitleg voor :
> Hi,
>
> to add to this post;
>
> Remember that the "php" piece in the XML/XSLT is 'plain old text' from
> the XML/XSLT perspective. You're generating something (*that by
> coincidence ;) is PHP code) to be executed when viewing the results of
> the XML/XSLT transformation.
>
> Therefore it makes the most sense to:
>
> - Push this piece of text in a <xsl:text /> block.
> - Push this piece in the XSLT processor as parameter.
> - Push this piece in the XML and have the XSLT render it to output.
>
> Hope this helps,
>
> Marvin Smit.



Thanks for your advice. I've got it work now, well... almost as it
should...
Ikke :-)))

--


Met vriendelijke groet,

Ikke
~~~~~~~~~~~~~~~~~~~~~~~~~
ftp://upload:upload@ara.myftp.org:21
~~~~~~~~~~~~~~~~~~~~~~~~~

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews