Re: Xpath
Tod Harter <[email protected]> Tue, 11 Dec 2012 10:21:35 -0500
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <CAC0h5Yy1xKSUH_ieLFtusktzsCUtH9h-A3HjsdYsGZ0XdKEUtg@mail.gmail.com> |
--===============0022858909== Content-Type: multipart/alternative; boundary=089e0141a840ca80c004d0953c32 --089e0141a840ca80c004d0953c32 Content-Type: text/plain; charset=ISO-8859-1 Yeah, it works great too. You can for instance build an entire rather nice web app framework just by binding all the stuff you need into XSLT functions and writing style sheets ;) Of course it isn't always the FASTEST thing in the universe, but one thing it does let you do, if you're bold, is carry a bit more state around than XSLT allows for (IE you can make callbacks into perl via functions and those can store perl variables etc). Its cheating in a sense, but kinda nice sometimes. On Tue, Dec 11, 2012 at 6:12 AM, Daniel Perrett <[email protected]>wrote: > Oops! In which case I apologise for my previous statement, I have no idea > why I either didn't notice that section or comprehend it fully before, the > docs seem pretty clear. > > Thanks a lot - my life just got measurably easier! > > Daniel > > > > From: Tim Brody <[email protected]> > To: Daniel Perrett <[email protected]> > Cc: Perl XML List <[email protected]> > Date: 11/12/2012 11:03 > Subject: Re: Xpath > ------------------------------ > > > > In http://search.cpan.org/~shlomif/XML-LibXSLT-1.79/LibXSLT.pm > > "register_function" and "register_element", which do indeed allow you to > call a Perl function on either XPath functions or XSL elements. > > InputCallback is something completely different. > > /Tim. > > On Tue, 2012-12-11 at 10:48 +0000, Daniel Perrett wrote: > > "XML::LibXSLT also supports callbacks into Perl space, so you can mix > > and match XSLT and Perl in the same template." > > Wow, I've been using LibXSLT on a weekly to daily basis for several > > years and I never knew that. The POD is very cryptic on the matter: > > > > "To define XML::LibXSLT or XML::LibXSLT::Stylesheet specific input > > callbacks, reuse the XML::LibXML input callback API as described in > > XML::LibXML::InputCallback(3)." > > > > ... which tells me nothing about what an input callback is in this > > context, let alone why I might want to use it. > > > > So does this mean I can create custom XSLT functions that pass a value > > (or better, a DOM node) to Perl and get a result back? That would be > > *very* handy, not least to et around my occasional need to translate > > what ought to be a series of regex replacements into a template that > > recurses through a flat list and then does string replacements that > > approximate the reex. Or does it mean something else? > > > > Daniel > > > > > > > > From: Tim Brody <[email protected]> > > To: [email protected] > > Cc: Perl XML List <[email protected]> > > Date: 11/12/2012 10:25 > > Subject: Re: Xpath > > Sent by: [email protected] > > > > ______________________________________________________________________ > > > > > > > > To use an analogy, XSLT is to XML what regexps are to text. Yes, it > > takes some time to get your head around but once you do it makes XML > > transformations quick to achieve. XSLT is flexible enough to be used > > procedurally or as pattern matching - "foreach" vs. "template". > > > > XML::LibXSLT also supports callbacks into Perl space, so you can mix > > and > > match XSLT and Perl in the same template. > > > > To work effectively with XML you should familiarise yourself with DOM, > > SAX and XSLT, then you can apply the best technology to the problem in > > hand. Otherwise, you can always use one of the modules that turns XML > > into native Perl structures ... > > > > -- > > All the best, > > Tim. > > > > On Tue, 2012-12-11 at 00:23 -0500, Tod Harter wrote: > > > It is a bit of a thing to wrap your head around, and XSLT is > > certainly > > > not the most friendly example of a functional language, but once you > > > do get a grip on it its kind of elegant. Really I think mostly I'd > > > like a non-xml syntax to use, that would make it a lot more fun. The > > > other thing is XSLT2 is a LOT nicer, but unfortunately probably will > > > never have an implementation with perl bindings. > > > > > > On Mon, Dec 10, 2012 at 9:14 PM, Thomas Krichel > > <[email protected]> > > > wrote: > > > Tod Harter writes > > > > > > > IF you know XSLT (or if you're going to learn it anyway > > > there's > > > > no time like the present). Its a useful language to know. > > > > > > > > > Coming from Perl, I found it hard to learn as you have > > > to unlearn procedural thinking. > > > > > > Cheers, > > > > > > Thomas Krichel > > > http://openlib.org/home/krichel > > > > > > http://authorprofile.org/pkr1 > > > skype: > > > thomaskrichel > > > > > > > > > > > > > > > -- > > > The Wise adapts himself to the world. The Fool adapts the world to > > > himself. Therefore, all progress depends on the Fool. > > > _______________________________________________ > > > Perl-XML mailing list > > > [email protected] > > > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs<http://listserv.activestate.com/mailman/mysubs> > > > > [attachment "signature.asc" deleted by Daniel > > Perrett/ELT/UK/cambridge] > > _______________________________________________ > > Perl-XML mailing list > > [email protected] > > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs<http://listserv.activestate.com/mailman/mysubs> > > > > [attachment "signature.asc" deleted by Daniel Perrett/ELT/UK/cambridge] > > _______________________________________________ > Perl-XML mailing list > [email protected] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > -- The Wise adapts himself to the world. The Fool adapts the world to himself. Therefore, all progress depends on the Fool. --089e0141a840ca80c004d0953c32 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Yeah, it works great too. You can for instance build an entire rather nice = web app framework just by binding all the stuff you need into XSLT function= s and writing style sheets ;) Of course it isn't always the FASTEST thi= ng in the universe, but one thing it does let you do, if you're bold, i= s carry a bit more state around than XSLT allows for (IE you can make callb= acks into perl via functions and those can store perl variables etc). Its c= heating in a sense, but kinda nice sometimes. <br> <br><div class=3D"gmail_quote">On Tue, Dec 11, 2012 at 6:12 AM, Daniel Perr= ett <span dir=3D"ltr"><<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>></span> wrote:<br><blockquote cla= ss=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa= dding-left:1ex"> <font face=3D"sans-serif">Oops! In which case I apologise for my previous statement, I have no idea why I either didn't notice that sect= ion or comprehend it fully before, the docs seem pretty clear. </font> <br> <br><font face=3D"sans-serif">Thanks a lot - my life just got measurably easier!</font> <br><div class=3D"im"> <br><font face=3D"sans-serif">Daniel</font> <br> <br> <br> <br><font color=3D"#5f5f5f" face=3D"sans-serif" size=3D"1">From: =A0 =A0 = =A0 =A0</font><font face=3D"sans-serif" size=3D"1">Tim Brody <<a href=3D"mai= lto:[email protected]" target=3D"_blank">[email protected]</a>></f= ont> <br></div><font color=3D"#5f5f5f" face=3D"sans-serif" size=3D"1">To: =A0 = =A0 =A0 =A0</font><font face=3D"sans-serif" size=3D"1">Daniel Perrett <<a href= =3D"mailto:[email protected]" target=3D"_blank">[email protected]= </a>></font> <br><div class=3D"im"><font color=3D"#5f5f5f" face=3D"sans-serif" size=3D"1= ">Cc: =A0 =A0 =A0 =A0</font><font face=3D"sans-serif" size=3D"1">Perl XML List <<a href=3D= "mailto:[email protected]" target=3D"_blank">perl-xml@lists= erv.ActiveState.com</a>></font> <br></div><font color=3D"#5f5f5f" face=3D"sans-serif" size=3D"1">Date: =A0 = =A0 =A0 =A0</font><font face=3D"sans-serif" size=3D"1">11/12/2012 11:03</font> <br><font color=3D"#5f5f5f" face=3D"sans-serif" size=3D"1">Subject: =A0 =A0 =A0 =A0</font><font face=3D"sans-serif" size=3D"1">Re: Xpath</font> <br> <hr noshade><div class=3D"HOEnZb"><div class=3D"h5"> <br> <br> <br><tt><font>In </font></tt><a href=3D"http://search.cpan.org/%7Eshlomif/X= ML-LibXSLT-1.79/LibXSLT.pm" target=3D"_blank"><tt><font>http://search.cpan.= org/~shlomif/XML-LibXSLT-1.79/LibXSLT.pm</font></tt></a><tt><font><br> <br> "register_function" and "register_element", which do indeed allow you to<br> call a Perl function on either XPath functions or XSL elements.<br> <br> InputCallback is something completely different.<br> <br> /Tim.<br> <br> On Tue, 2012-12-11 at 10:48 +0000, Daniel Perrett wrote:<br> > "XML::LibXSLT also supports callbacks into Perl space, so you can mix<br> > and match XSLT and Perl in the same template." <br> > Wow, I've been using LibXSLT on a weekly to daily basis for severa= l<br> > years and I never knew that. The POD is very cryptic on the matter: <br> > <br> > "To define XML::LibXSLT or XML::LibXSLT::Stylesheet specific input<br> > callbacks, reuse the XML::LibXML input callback API as described in<br= > > XML::LibXML::InputCallback(3)." <br> > <br> > ... which tells me nothing about what an input callback is in this<br> > context, let alone why I might want to use it. <br> > <br> > So does this mean I can create custom XSLT functions that pass a value= <br> > (or better, a DOM node) to Perl and get a result back? That would be<br> > *very* handy, not least to et around my occasional need to translate<b= r> > what ought to be a series of regex replacements into a template that<b= r> > recurses through a flat list and then does string replacements that<br= > > approximate the reex. Or does it mean something else? <br> > <br> > Daniel <br> > <br> > <br> > <br> > From: =A0 =A0 =A0 =A0Tim Brody <<a href=3D"mailto:[email protected]= .uk" target=3D"_blank">[email protected]</a>> <br> > To: =A0 =A0 =A0 =A0<a href=3D"mailto:[email protected]"= target=3D"_blank">[email protected]</a> <br> > Cc: =A0 =A0 =A0 =A0Perl XML List <<a href=3D"mailto:perl-xml@listse= rv.ActiveState.com" target=3D"_blank">[email protected]</a>= > <br> > Date: =A0 =A0 =A0 =A011/12/2012 10:25 <br> > Subject: =A0 =A0 =A0 =A0Re: Xpath <br> > Sent by: =A0 =A0 =A0 =A0<a href=3D"mailto:[email protected]= tiveState.com" target=3D"_blank">[email protected]<= /a> <br> > <br> > ______________________________________________________________________= <br> > <br> > <br> > <br> > To use an analogy, XSLT is to XML what regexps are to text. Yes, it<br= > > takes some time to get your head around but once you do it makes XML<b= r> > transformations quick to achieve. XSLT is flexible enough to be used<b= r> > procedurally or as pattern matching - "foreach" vs. "te= mplate".<br> > <br> > XML::LibXSLT also supports callbacks into Perl space, so you can mix<b= r> > and<br> > match XSLT and Perl in the same template.<br> > <br> > To work effectively with XML you should familiarise yourself with DOM,<br> > SAX and XSLT, then you can apply the best technology to the problem in<br> > hand. Otherwise, you can always use one of the modules that turns XML<br> > into native Perl structures ...<br> > <br> > --<br> > All the best,<br> > Tim.<br> > <br> > On Tue, 2012-12-11 at 00:23 -0500, Tod Harter wrote:<br> > > It is a bit of a thing to wrap your head around, and XSLT is<br> > certainly<br> > > not the most friendly example of a functional language, but once you<br> > > do get a grip on it its kind of elegant. Really I think mostly I'd<br> > > like a non-xml syntax to use, that would make it a lot more fun. The<br> > > other thing is XSLT2 is a LOT nicer, but unfortunately probably will<br> > > never have an implementation with perl bindings. <br> > > <br> > > On Mon, Dec 10, 2012 at 9:14 PM, Thomas Krichel<br> > <<a href=3D"mailto:[email protected]" target=3D"_blank">krichel@o= penlib.org</a>><br> > > wrote:<br> > > =A0 =A0 =A0 =A0 =A0 Tod Harter writes<br> > > =A0 =A0 =A0 =A0 <br> > > =A0 =A0 =A0 =A0 > IF you know XSLT (or if you're going to learn it anyway<br> > > =A0 =A0 =A0 =A0 there's<br> > > =A0 =A0 =A0 =A0 > no time like the present). Its a useful language to know.<br> > > =A0 =A0 =A0 =A0 <br> > > =A0 =A0 =A0 =A0 <br> > > =A0 =A0 =A0 =A0 =A0 Coming from Perl, I found it hard to learn as you have<br> > > =A0 =A0 =A0 =A0 =A0 to unlearn procedural thinking.<br> > > =A0 =A0 =A0 =A0 <br> > > =A0 =A0 =A0 =A0 =A0 Cheers,<br> > > =A0 =A0 =A0 =A0 <br> > > =A0 =A0 =A0 =A0 =A0 Thomas Krichel<br> > > =A0 =A0 =A0 =A0 =A0</font></tt><a href=3D"http://openlib.org/home= /krichel" target=3D"_blank"><tt><font>http://openlib.org/home/krichel</font= ></tt></a><tt><font><br> > > =A0 =A0 =A0 =A0 <br> > > =A0 =A0 =A0 =A0 </font></tt><a href=3D"http://authorprofile.org/p= kr1" target=3D"_blank"><tt><font>http://authorprofile.org/pkr1</font></tt><= /a><tt><font><br> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0skype:<br> > > =A0 =A0 =A0 =A0 thomaskrichel<br> > > =A0 =A0 =A0 =A0 <br> > > <br> > > <br> > > <br> > > -- <br> > > The Wise adapts himself to the world. The Fool adapts the world to<br> > > himself. Therefore, all progress depends on the Fool.<br> > > _______________________________________________<br> > > Perl-XML mailing list<br> > > <a href=3D"mailto:[email protected]" target=3D"_b= lank">[email protected]</a><br> > > To unsubscribe: </font></tt><a href=3D"http://listserv.activestat= e.com/mailman/mysubs" target=3D"_blank"><tt><font>http://listserv.ActiveSta= te.com/mailman/mysubs</font></tt></a><tt><font><br> > <br> > [attachment "signature.asc" deleted by Daniel<br> > Perrett/ELT/UK/cambridge]<br> > _______________________________________________<br> > Perl-XML mailing list<br> > <a href=3D"mailto:[email protected]" target=3D"_blank"= >[email protected]</a><br> > To unsubscribe: </font></tt><a href=3D"http://listserv.activestate.com= /mailman/mysubs" target=3D"_blank"><tt><font>http://listserv.ActiveState.co= m/mailman/mysubs</font></tt></a><tt><font><br> > <br> <br> [attachment "signature.asc" deleted by Daniel Perrett/ELT/UK/camb= ridge] </font></tt> <br></div></div><br>_______________________________________________<br> Perl-XML mailing list<br> <a href=3D"mailto:[email protected]">[email protected]= veState.com</a><br> To unsubscribe: <a href=3D"http://listserv.ActiveState.com/mailman/mysubs" = target=3D"_blank">http://listserv.ActiveState.com/mailman/mysubs</a><br> <br></blockquote></div><br><br clear=3D"all"><br>-- <br>The Wise adapts him= self to the world. The Fool adapts the world to himself. Therefore, all pro= gress depends on the Fool.<br> --089e0141a840ca80c004d0953c32-- --===============0022858909== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs --===============0022858909==--