in reply to Push + variable argument

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?

Replies are listed 'Best First'.
Re^2: Push + variable argument
by dHarry (Abbot) on Feb 10, 2009 at 14:19 UTC

    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?

        Do the separating in Perl (for example with the split statement) and pass the individual arguments/parameters to the XSLT. So something like:

        In the xslt:

        <xsl:param name="param_1"/> <xsl:param name="param_2"/>

        In the Perl script:

        my ($par1, $par2) = split (/ /,$str); my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string(param_1 => $par1), XML::LibXSLT::xpath_to_string(param_2 => $par2) );

        NB The utility function xpath_to_string takes care of the quoting. This is probably the better/easier way of doing things. See the documentation for details. See playing with XSLT for a bigger example.

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