xsltproc and lxml are different?

148 views
Skip to first unread message

Rob Beezer

unread,
Oct 1, 2023, 8:28:17 PM10/1/23
to prete...@googlegroups.com
Almost by accident, I stumbled on a hint that xsltproc has some crypto
functions available as "extension functions". And they are part of the EXSLT
library we rely on heavily already. Plus, I have a need for them now (short
unique filenames for some knowl content).

1. In an XSLT stylesheet add the following to the "xsl:stylesheet" where
similar declarations are made.

xmlns:crypt="http://exslt.org/crypto"

2. In some template that is sure to be called a lot insert

<xsl:message>
<xsl:value-of select="crypt:sha1('foobar')"/>
</xsl:message>

3. Now process some document with xsltproc and you'll see lots of

8843d7f92416211de9ebb963ff4ce28125932878

in the console. (Which matches what I get at http://www.sha1-online.com/ !)

Now, use the pretext/pretext script, which will use the Python lxml module
which has always been seemingly 100% compatible with xsltproc since they are
built on the same libraries.

This will produce messages:

xmlXPathCompOpEval: function sha1 not found
Unregistered function

which is odd, since "xsltproc -dumpextensions" says *it is* registered.

A. The lxml "XSLT" object has an "extensions" keyword. We've not needed it for
other EXSLT functions. I was able to get the syntax right, but what I tried was
not effective. I wonder if a Pythonista could do better?

https://lxml.de/api/lxml.etree.XSLT-class.html

B. I'm guessing this is code that makes this functionality possible. Maybe
somebody with more system experience can tell if this is compiled into whatever
libraries lxml is using. I think these extensions have been around for years,
so I'd not suspect some sort of version mis-match right away.

https://gitlab.gnome.org/GNOME/libxslt/-/blob/master/libexslt/crypto.c

I'd love to have these hash functions available easily, or know that we
definitely have a difference between the two processors.

Thanks,
Rob

Andrew Scholer

unread,
Oct 2, 2023, 12:31:02 PM10/2/23
to prete...@googlegroups.com
It looks to me like the default build for libxslt does not include crypto:

Maybe some hackery with generate-id()? And or use math:random() from exslt to help generate a UUID like construct?

BTW the Windows wheel for lxml apparently does have a crypto enabled XSLT... I can run a simple test there no problem. But same one fails on Ubuntu. Maybe you should just use Windows. ;)

Andrew Scholer (he/him/his)
Computer Science Instructor/Program Chair
Chemeketa Community College


--
You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-dev/MTAwMDAxOC5iZWV6ZXI.1696206494%40quikprotect.

Rob Beezer

unread,
Oct 2, 2023, 12:59:10 PM10/2/23
to prete...@googlegroups.com
On 10/2/23 09:30, Andrew Scholer wrote:
> It looks to me like the default build for libxslt does not include crypto:
> https://gitlab.gnome.org/GNOME/libxslt/-/blob/master/CMakeLists.txt#L42
> <https://gitlab.gnome.org/GNOME/libxslt/-/blob/master/CMakeLists.txt#L42>

Thanks very much, Andrew, that'll keep me from barking up this same tree.
Really had me bugged this morning.

> Maybe some hackery with generate-id()? And or use math:random() from exslt to
> help generate a UUID like construct?

Yes, there was a point when I was using generate-id() for this sort of thing.
IIRC, it behaved differently on different OS and/or was not persistent over
time. It worked as LaTeX \label and \ref as a one-shot, non-visible identifier.
I'll need to refresh my memory on all that.

An alternate would be some lesser-quality (non-crypto) sort of hashing in pure
XSL, I guess. Its been a while since I evaluated such things.

> BTW the Windows wheel for lxml apparently does have a crypto enabled XSLT... I
> can run a simple test there no problem. But same one fails on Ubuntu. Maybe you
> should just use Windows. ;)

Very funny. ;-) I switched over to Windows about 30 years ago. Took me years
to switch out again.

Thanks,
Rob
Reply all
Reply to author
Forward
0 new messages