[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: passing parameters to XSL,what if no value in some

Subject: Re: passing parameters to XSL,what if no value in some cases
From: himanshu padmanabhi <himanshu.padmanabhi@xxxxxxxxx>
Date: Sat, 7 Mar 2009 14:03:49 +0530
Re:  passing parameters to XSL
Thank you all.If I passed arguments using hash %params.How to access
them in XSL file,
I tried this,but got error.
   <xsl:param name="args" select="$params{$args}" />
   <xsl:param name="val" select="$params{$val}" />
   <xsl:param name="newl" select="$params{$new}" />

What are the advantages of passing it using hash?

On Fri, Mar 6, 2009 at 7:10 PM, Nic Gibson <nicg@xxxxxxxxxx> wrote:
>
> 2009/3/6 himanshu padmanabhi <himanshu.padmanabhi@xxxxxxxxx>:
> > First time,code will go to 'else' part,it again returns to this form
> > and 'if' part executes.
> >
> > <CODE>
> >         my $parser = XML::LibXML->new();
> >         my $xslt = XML::LibXSLT->new();
> >
> >         my $source = $parser->parse_file($xmlfile);
> >         my $style_doc = $parser->parse_file($xslfile);
> >
> >         my $stylesheet = $xslt->parse_stylesheet($style_doc);
> >         if($in{'flag'} eq "2") {
> >             my $results = $stylesheet->transform($source,
> > XML::LibXSLT::xpath_to_string(args => "$in{'args'}",val => "1",new =>
> > "$in{'new'}"));
> >             print $stylesheet->output_string($results);
> >         }else{
> >             my $results = $stylesheet->transform($source,
> > XML::LibXSLT::xpath_to_string(args => "",val => "3",new =>
> > "$in{'new'}"));
> >             print $stylesheet->output_string($results);
> >         }
> > </CODE>
> >
> > 1.In my 'else' above,I don't want to pass 'args'(can I do it?),
> >
> > 2.How can I check in my xsl file whether it is passed or not probably
> > using some 'if' statement or something like this?
> > <CODE>
> >    <xsl:choose>
> >    <xsl:when test="args_is_given">
> >         <some code>
> >    </xsl:when>
> >    </xsl:choose>
> > </CODE>
>
> If you were to choose to use a sensible default parameter as suggested
> by Michael Kay
> then you could rewrite that perl to be a little simpler and avoid
> passing the redundant arg. Something like:
>
> my $parser = XML::LibXML->new();
> my $xslt = XML::LibXSLT->new();
>
> my $source = $parser->parse_file($xmlfile);
> my $style_doc = $parser->parse_file($xslfile);
>
> my $stylesheet = $xslt->parse_stylesheet($style_doc);
>
> # The quotes around your args are redundant unless
> # the values are actually objects not scalar data.
> my %params = (
>  val => XML::LibXSLT::xpath_to_string(1),
>  new =>  XML::LibXSLT::xpath_to_string($in{'new'})
> );
>
> # I changed this to a numeric comparison
> # (this may be wrong in your case).
> $params{'args'} = XML::LibXST::xpath_to_string($in{'args'}) if $in{'flag'}
== 2;
>
> my $results = $stylesheet->transform($source, %params);
> print $stylesheet->output_string($results);
>
>
> I don't tend to write that exact code myself. I usually have a function to
> set up the arguments but your mileage may vary...
>
> cheers
>
> nic
>
> --
> Nic Gibson
> Director, Corbas Consulting
> Editorial and Technical Consultancy
> http://www.corbas.co.uk/
>



--
Regards,
Himanshu Padmanabhi

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.