Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Push + variable argument

by himanshu.padmanabhi (Acolyte)
on Feb 10, 2009 at 12:02 UTC ( [id://742742]=perlquestion: print w/replies, xml ) Need Help??

himanshu.padmanabhi has asked for the wisdom of the Perl Monks concerning the following question:

Case 1 push @arr, ('val', '1');

=> $val=1.

Case 2 push @arr, ('val', '$str');

But '$val=$arr' is not working. I want to assign variable values to 'val'.

How to do it?

Replies are listed 'Best First'.
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?

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);

Re: Push + variable argument
by andye (Curate) on Feb 10, 2009 at 12:12 UTC
    Your case1 push @arr, ('val', '1'); definitely does not assign 1 to a variable called $val.

    I suggest taking another look at the docs on push.

    hth!

      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..
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.

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?

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?

      I think you're mixing up syntax. From the documentation (modified):

      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.

        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?
        <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>"
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'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://742742]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found