in reply to passing variable arguments to XSL from perl

#Defining objects for XML,XSLT. my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); #Parsing both files my $source = $parser->parse_file($xmlfile); # '$style_doc' represents 'XML::LibXML::Document' object representing +an XSLT file. my $style_doc = $parser->parse_file($xslfile); my $stylesheet = $xslt->parse_stylesheet($style_doc); # 'Transform' returns a scalar that is the XSLT rendering of the 'XML: +:LibXML::Document' object using the desired output format(specified i +n the xsl:output tag in the stylesheet) my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to +_string(args1=> "$in{'args1'}",args2=> "$in{'args2'}",args3=> "$in{'a +rgs3'}",idx => "$in{'idx'}",newperiod => "$in{'newperiod'}")); # IN ABOVE CASE,I DN'T WANT TO HARDCODE 'ARGS' LIKE 3 ABOVE.I AM GETTI +NG TOTAL NUMBER OF PARAMETERS IN VARIABLE.SO IF ARGS CAN BE 5 IN SOME + CASE,ABOVE LINE SHOULD BE LIKE THIS.. # my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to +_string(args1=> "$in{'args1'}",args2=> "$in{'args2'}",args3=> "$in{'a +rgs3'}",args4=> "$in{'args4'}",args5=> "$in{'args5'}",idx => "$in{'id +x'}",newperiod => "$in{'newperiod'}")); print $stylesheet->output_string($results);
Actually I want that it should check '$in' hash.It contains '$in{args<number>}'.It should pass these '$in{args<number>}' variables to XSL file.

Replies are listed 'Best First'.
Re: passing variable arguments to XSLT
by jethro (Monsignor) on Apr 07, 2009 at 10:06 UTC
    my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string(%in);

    this does the same as listing all the keys and values in %in by hand because the parameters of a function are evaluated in list context. In list context a hash is transformed into a list of key,value pairs. The same thing that happens when you do @a= %b