473,399 Members | 3,038 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,399 software developers and data experts.

passing arguments to xsl

HI,

i am trying to use the following code to do an xslt transform using
php 4/sablotron with additional optional arguments. can anybody tell
me what i am doing wrong ? i was expecting the output "one two" from
the sample.xsl transform but it seems to treat the variable as a
literal (see below)...

trans.php
--------

<?
echo xslt_process(xslt_create(), 'sample.xml', 'sample.xsl', NULL,
array(), array("pat"=>"out"));
?>

sample.xml
--------

<?xml version="1.0" encoding="UTF-8"?>
<out>
<in>one</in>
<in>two</in>
</out>

sample.xsl
----------

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="pat"/>
<xsl:template match="/">
<xsl:value-of select="$pat"/>
</xsl:template>
</xsl:stylesheet>

OUTPUT

out

alternative.xsl
----------

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="pat"/>
<xsl:template match="/">
<xsl:value-of select="out"/>
</xsl:template>
</xsl:stylesheet>

OUTPUT (substituting alternative.xsl for sample.xslin trans.php)

one two
php / sablot config info
------------------------

PHP Version 4.3.5

XSLT support enabled
Backend Sablotron
Sablotron Version 1.0.1
Sablotron Information Cflags: -g -O2 -I/usr/local/include
-I/usr/local/include Libs: -L/usr/local//lib -lexpat Prefix:
/usr/local/
Jul 17 '05 #1
1 2573
That behaviour is correct. The statement <xsl:value-of select="$pat"/> will
select the contents of variable/parameter $pat and will treat it as a
string.

If you want to turn a string into a node set then you need the following:
<xsl:value-of select="//*[name()=$pat]"/>

Visit my site at http://www.tonymarston.co.uk/xml-xsl/index.html for more
XML/XSL tips.

Visit my site at http://www.tonymarston.co.uk/php-mysql/index.html for
PHP/MySQL tips.

--
Tony Marston
http://www.tonymarston.net

"Mitch Cunningham" <mc******@bigpond.net.au> wrote in message
news:f4**************************@posting.google.c om...
HI,

i am trying to use the following code to do an xslt transform using
php 4/sablotron with additional optional arguments. can anybody tell
me what i am doing wrong ? i was expecting the output "one two" from
the sample.xsl transform but it seems to treat the variable as a
literal (see below)...

trans.php
--------

<?
echo xslt_process(xslt_create(), 'sample.xml', 'sample.xsl', NULL,
array(), array("pat"=>"out"));
?>

sample.xml
--------

<?xml version="1.0" encoding="UTF-8"?>
<out>
<in>one</in>
<in>two</in>
</out>

sample.xsl
----------

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="pat"/>
<xsl:template match="/">
<xsl:value-of select="$pat"/>
</xsl:template>
</xsl:stylesheet>

OUTPUT

out

alternative.xsl
----------

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="pat"/>
<xsl:template match="/">
<xsl:value-of select="out"/>
</xsl:template>
</xsl:stylesheet>

OUTPUT (substituting alternative.xsl for sample.xslin trans.php)

one two
php / sablot config info
------------------------

PHP Version 4.3.5

XSLT support enabled
Backend Sablotron
Sablotron Version 1.0.1
Sablotron Information Cflags: -g -O2 -I/usr/local/include
-I/usr/local/include Libs: -L/usr/local//lib -lexpat Prefix:
/usr/local/

Jul 17 '05 #2

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

Similar topics

7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
5
by: Michael | last post by:
Hi, once I read here that it is not 'a good idea' to pass variables that are not initialized to a function. I have void something ( double *vector ); ....
3
by: Mantorok | last post by:
Hi all I'm pretty new to ASP.Net, is it possible to pass arguments (maybe objects too) to web forms without using a querystring in the URL? Thanks Kev
4
by: Justine | last post by:
Can anyone help? e.g. when you open a vb project property page, in "Configuration Properties" You will see "Command line arguments" in "Start Options". Does anyone knows how to find a way to do...
7
by: Bonzo | last post by:
>From within a function, I want to pass a/some parameters to another function, AND all arguments, passed into this function. e.g. function firstFunction(){ //this function may have been...
2
by: william.w.oneill | last post by:
I have an application that takes a few command line parameters. As recommended by others in this group, I'm using a named mutex to ensure that only one instance of the application is running. My...
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?
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
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,...
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,...
0
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...
0
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,...
0
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...

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.