[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Basics of XSLT
2009/3/10 himanshu padmanabhi <himanshu.padmanabhi@xxxxxxxxx>: > Thank you.Can anyone explain XPath more? > > I was advised to use "XML::LibXSLT::xpath_to_string" in the following code. > > B my $parser = XML::LibXML->new(); > B my $xslt = XML::LibXSLT->new(); > > B my $source = $parser->parse_file($xmlfile); > B my $style_doc = $parser->parse_file($xslfile); > > B my $stylesheet = $xslt->parse_stylesheet($style_doc); > > B my $results = $stylesheet->transform($source, > XML::LibXSLT::xpath_to_string(args => "$in{'args'}",value => "$value", > cnt => "1",); > > B print $stylesheet->output_string($results); > Hello again. One thing you might find useful is the perl-xml mailing list (take a look at http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/perl-xml). I'll try and answer your question about xpath_to_string. In xslt the value of a parameter (or variable) is an xpath exrpession in something like: <xsl:param name='myparam' select='foo'/> That is, we aren't talking about the string 'foo' here, we are talking about the element 'foo'. Now, that is like to not be what you mean in a global parameter (one at stylesheet level as opposed to a local param at template level). A string must be quoted in an xpath expression: <xsl:param name='myparam' select="'foo'"/> <!-- double quote with single quoted string inside it --> So... going back to perl - xpath_to_string converts a perl string to the quoting format required by xslt. The input to the function is a hash (or an array of key/value pairs). Basically the function takes every second argument and quotes it. It then returns the processed array. So, the result of: XML::LibXSLT::xpath_to_string(args => "$in{'args'}",value => "$value", cnt => "1",) will be ('args' => "'xxx'", 'value' => "'yyy'", 'cnt', => "'1'"); # double quoted strings containing single quoted values where xxx and yyy are the values of $in{'args'} and $value respectively. I think I gave you an incorrect answer yesterday because I suggested xpath_to_string('foo') - don't do that, do as you were doing before (xpath_to_string('foo', 'bar')). cheers nic -- Nic Gibson Director, Corbas Consulting Editorial and Technical Consultancy http://www.corbas.co.uk/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|