Re: Push + variable argument
by moritz (Cardinal) on Feb 10, 2009 at 12:07 UTC
|
Sorry, I can't really make any sense of your post.
When you push something onto @arr, how should $val be affected?
What do you want to achieve, and how does it not work in your second case? Maybe you shouldn't use single quotes around $str? | [reply] [d/l] [select] |
Re: Push + variable argument
by apl (Monsignor) on Feb 10, 2009 at 12:39 UTC
|
I'm not quite certain what you're asking, but I think you want to replace (in your Case 2)
push @arr, ('val', '$str');
with
push @arr, ('val', $str); | [reply] [d/l] [select] |
Re: Push + variable argument
by andye (Curate) on Feb 10, 2009 at 12:12 UTC
|
| [reply] [d/l] [select] |
|
This is the full code.
push @xsltParams, ('arg', $str);
my $result = $stylesheet->transform_file('abc.xml', @xsltParams);
Without quotes doesn't give error,but $arg not got filled.
In 'abc.xsl',I am supposed to access like this,
<xsl:value-of select="$arg"/>
where $str contains space separated values which I need to separate and print..
| [reply] |
Re: Push + variable argument
by dHarry (Abbot) on Feb 10, 2009 at 13:45 UTC
|
This is the full code...
I don't believe you.
It seems you use XML::LibXSLT (guessing), please note that Libxslt expects parameters in XPath format. What you do makes no sense?! Please post a more complete code fragment. | [reply] |
Re: Push + variable argument
by jethro (Monsignor) on Feb 10, 2009 at 13:17 UTC
|
Please use <code> or shorter <c> tags around your code examples
Please provide essential information like what CPAN module you are using
Do you expect that the call to transform_file of the (to us) unknown module would fill $arg ? Or do you yourself want to fill $arg in your program?
| [reply] |
Re: Push + variable argument
by himanshu.padmanabhi (Acolyte) on Feb 10, 2009 at 13:55 UTC
|
MY.cgi
my $xslt = XML::LibXSLT->new();
my $stylesheet = $xslt->parse_stylesheet_file('abc.xsl');
push @xsltParams, ('arg', $str);
push @xsltParams, ('val', '1');
my $result = $stylesheet->transform_file('abc.xml', @xsltParams);
print $stylesheet->output_string($result);
This is how I access in XSL file.
MY.xsl
<xsl:value-of select="$arg"/>
Can you please tell more about XPath and how can I access parameters in XSL file passed from cgi file? | [reply] [d/l] [select] |
|
my $results = $stylesheet->transform_file('abc.xml', arg => "$str");
Or more general:
transform_file(filename, %params);
The usage of the Xpath syntax is also explained in the documentation:
$stylesheet->transform($doc, param => "'string'");
Note the "' and '" !
And where does $str come from and what does it contain? Please put use strict; and use warnings; in your script.
| [reply] [d/l] [select] |
|
Thank you very much all especially dHarry.Now it is working.
$str comes from another cgi script and contains values separated by spaces.
$str=$in{'values_separated_by_spaces'};
I am getting values in $str and they are passed to XSL script using XPath mechanism as you told.
I want to separate these space values in XSL script so to display individual ones.Can you tell how to do this? | [reply] [d/l] |
|
|
<xsl:value-of select="substring-before($arg,' ')"/>
I got this way of separating the values.Now looking for displaying them individually in COMBO box using "<xsl:for each>" | [reply] [d/l] |
Re: Push + variable argument
by himanshu.padmanabhi (Acolyte) on Feb 10, 2009 at 13:46 UTC
|
CPAN Module: XML::LibXSLT
my $result = $stylesheet->transform_file('AVA-Snapshotsize.xml', @xsltParams);
If I do push @xsltParams, ('val', '1'); because of "transform_file",I can access $arg in xsl file as <xsl:value-of select="$arg"/>.Here it comes out to be 1(XSL file prints that).
Only having problems if I have to pass variable value to this 'val'.
| [reply] [d/l] [select] |