By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

passing arguments to xsl

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.