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&#39;t always the FASTEST thi=
ng in the universe, but one thing it does let you do, if you&#39;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">&lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt;</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&#39;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 &lt;<a href=3D"mai=
lto:[email protected]" target=3D"_blank">[email protected]</a>&gt;</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 &lt;<a href=
=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
</a>&gt;</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 &lt;<a href=3D=
"mailto:[email protected]" target=3D"_blank">perl-xml@lists=
erv.ActiveState.com</a>&gt;</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>
&quot;register_function&quot; and &quot;register_element&quot;, 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>
&gt; &quot;XML::LibXSLT also supports callbacks into Perl space, so you
can mix<br>
&gt; and match XSLT and Perl in the same template.&quot; <br>
&gt; Wow, I&#39;ve been using LibXSLT on a weekly to daily basis for severa=
l<br>
&gt; years and I never knew that. The POD is very cryptic on the matter:
<br>
&gt; <br>
&gt; &quot;To define XML::LibXSLT or XML::LibXSLT::Stylesheet specific
input<br>
&gt; callbacks, reuse the XML::LibXML input callback API as described in<br=
>
&gt; XML::LibXML::InputCallback(3).&quot; <br>
&gt; <br>
&gt; ... which tells me nothing about what an input callback is in this<br>
&gt; context, let alone why I might want to use it. <br>
&gt; <br>
&gt; So does this mean I can create custom XSLT functions that pass a value=
<br>
&gt; (or better, a DOM node) to Perl and get a result back? That would
be<br>
&gt; *very* handy, not least to et around my occasional need to translate<b=
r>
&gt; what ought to be a series of regex replacements into a template that<b=
r>
&gt; recurses through a flat list and then does string replacements that<br=
>
&gt; approximate the reex. Or does it mean something else? <br>
&gt; <br>
&gt; Daniel <br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; From: =A0 =A0 =A0 =A0Tim Brody &lt;<a href=3D"mailto:[email protected]=
.uk" target=3D"_blank">[email protected]</a>&gt;
<br>
&gt; To: =A0 =A0 =A0 =A0<a href=3D"mailto:[email protected]"=
 target=3D"_blank">[email protected]</a> <br>
&gt; Cc: =A0 =A0 =A0 =A0Perl XML List &lt;<a href=3D"mailto:perl-xml@listse=
rv.ActiveState.com" target=3D"_blank">[email protected]</a>=
&gt;
<br>
&gt; Date: =A0 =A0 =A0 =A011/12/2012 10:25 <br>
&gt; Subject: =A0 =A0 =A0 =A0Re: Xpath <br>
&gt; Sent by: =A0 =A0 =A0 =A0<a href=3D"mailto:[email protected]=
tiveState.com" target=3D"_blank">[email protected]<=
/a>
<br>
&gt; <br>
&gt; ______________________________________________________________________=
<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; To use an analogy, XSLT is to XML what regexps are to text. Yes, it<br=
>
&gt; takes some time to get your head around but once you do it makes XML<b=
r>
&gt; transformations quick to achieve. XSLT is flexible enough to be used<b=
r>
&gt; procedurally or as pattern matching - &quot;foreach&quot; vs. &quot;te=
mplate&quot;.<br>
&gt; <br>
&gt; XML::LibXSLT also supports callbacks into Perl space, so you can mix<b=
r>
&gt; and<br>
&gt; match XSLT and Perl in the same template.<br>
&gt; <br>
&gt; To work effectively with XML you should familiarise yourself with
DOM,<br>
&gt; SAX and XSLT, then you can apply the best technology to the problem
in<br>
&gt; hand. Otherwise, you can always use one of the modules that turns
XML<br>
&gt; into native Perl structures ...<br>
&gt; <br>
&gt; --<br>
&gt; All the best,<br>
&gt; Tim.<br>
&gt; <br>
&gt; On Tue, 2012-12-11 at 00:23 -0500, Tod Harter wrote:<br>
&gt; &gt; It is a bit of a thing to wrap your head around, and XSLT is<br>
&gt; certainly<br>
&gt; &gt; not the most friendly example of a functional language, but once
you<br>
&gt; &gt; do get a grip on it its kind of elegant. Really I think mostly
I&#39;d<br>
&gt; &gt; like a non-xml syntax to use, that would make it a lot more fun.
The<br>
&gt; &gt; other thing is XSLT2 is a LOT nicer, but unfortunately probably
will<br>
&gt; &gt; never have an implementation with perl bindings. <br>
&gt; &gt; <br>
&gt; &gt; On Mon, Dec 10, 2012 at 9:14 PM, Thomas Krichel<br>
&gt; &lt;<a href=3D"mailto:[email protected]" target=3D"_blank">krichel@o=
penlib.org</a>&gt;<br>
&gt; &gt; wrote:<br>
&gt; &gt; =A0 =A0 =A0 =A0 =A0 Tod Harter writes<br>
&gt; &gt; =A0 =A0 =A0 =A0 <br>
&gt; &gt; =A0 =A0 =A0 =A0 &gt; IF you know XSLT (or if you&#39;re
going to learn it anyway<br>
&gt; &gt; =A0 =A0 =A0 =A0 there&#39;s<br>
&gt; &gt; =A0 =A0 =A0 =A0 &gt; no time like the present). Its
a useful language to know.<br>
&gt; &gt; =A0 =A0 =A0 =A0 <br>
&gt; &gt; =A0 =A0 =A0 =A0 <br>
&gt; &gt; =A0 =A0 =A0 =A0 =A0 Coming from Perl, I found
it hard to learn as you have<br>
&gt; &gt; =A0 =A0 =A0 =A0 =A0 to unlearn procedural thinking.<br>
&gt; &gt; =A0 =A0 =A0 =A0 <br>
&gt; &gt; =A0 =A0 =A0 =A0 =A0 Cheers,<br>
&gt; &gt; =A0 =A0 =A0 =A0 <br>
&gt; &gt; =A0 =A0 =A0 =A0 =A0 Thomas Krichel<br>
&gt; &gt; =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>
&gt; &gt; =A0 =A0 =A0 =A0 <br>
&gt; &gt; =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>
&gt; &gt; =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>
&gt; &gt; =A0 =A0 =A0 =A0 thomaskrichel<br>
&gt; &gt; =A0 =A0 =A0 =A0 <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; -- <br>
&gt; &gt; The Wise adapts himself to the world. The Fool adapts the world
to<br>
&gt; &gt; himself. Therefore, all progress depends on the Fool.<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; Perl-XML mailing list<br>
&gt; &gt; <a href=3D"mailto:[email protected]" target=3D"_b=
lank">[email protected]</a><br>
&gt; &gt; 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>
&gt; <br>
&gt; [attachment &quot;signature.asc&quot; deleted by Daniel<br>
&gt; Perrett/ELT/UK/cambridge]<br>
&gt; _______________________________________________<br>
&gt; Perl-XML mailing list<br>
&gt; <a href=3D"mailto:[email protected]" target=3D"_blank"=
>[email protected]</a><br>
&gt; 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>
&gt; <br>
<br>
[attachment &quot;signature.asc&quot; 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==--