http://xmltwig.com/article/index_wtr.html
'ways to rome' series is good ... there is also a bit of perl specific
xml advice to be had at http://www.perlmonks.com
hth, Jim Fuller
On Tue, Mar 10, 2009 at 11:54 AM, Nic Gibson <nicg(_at_)corbas(_dot_)net> wrote:
2009/3/10 himanshu padmanabhi
<himanshu(_dot_)padmanabhi(_at_)gmail(_dot_)com>:
Thank you.Can anyone explain XPath more?
I was advised to use "XML::LibXSLT::xpath_to_string" in the following 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);
my $results = $stylesheet->transform($source,
XML::LibXSLT::xpath_to_string(args => "$in{'args'}",value => "$value",
cnt => "1",);
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/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--