The Saxon website says Saxon/C can be invoked from Perl, but I can't find any examples. The only thing I've found that interfaces to Saxon is one old Perl module (XML::Saxon::XSLT2) which uses Inline::Java and apparently is very slow. But I can find nothing that uses Saxon/C. Has anyone had any success in doing this who can share some tips?
Asked
Active
Viewed 252 times
1
-
See also [XML::LibXSLT](https://metacpan.org/pod/XML::LibXSLT) and [XSLT2.0 processor for Perl?](https://stackoverflow.com/questions/4496515/xslt2-0-processor-for-perl). If the C bindings provided by the module isn't sufficient, you can also write your own using e.g. [`FFI::Platypus`](https://metacpan.org/pod/FFI::Platypus), [Swig](http://www.swig.org/), [XS](https://perldoc.perl.org/perlxs.html), or [`Inline::C`](https://metacpan.org/pod/Inline::C) – Håkon Hægland Sep 21 '19 at 04:26
-
Thanks for the suggestions. But I need Saxon (3.1 compliant), not LibXSLT. I can't be the first person to want to use Saxon with Perl, so someone has to have done this before. The Saxon/C page even specifically says it can be invoked from Perl. I'm not looking to create something new here, just using Saxon with Perl the way others do it. So how do the rest of you use Saxon with Perl? – lschult2 Sep 21 '19 at 10:00
1 Answers
1
we have not yet officially done the integration work needed to extend Saxon/C on perl it is still on our todo list. Therefore we currently don't support it. I don't know of anyone who has done this work as yet but I know it is can be done.
On the Saxon website we state that it is possible to create extensions in languages like Perl since Saxon/C has a C/C++ interface. Currently, we only have extensions for PHP and Python (available in the next release).
As a workaround you could run the transform command from Saxon/C using the exec function in Perl instead of the Java version, therefore avoiding the need to run Java VM.

ond1
- 691
- 6
- 10
-
Ah, that explains the statement on the Saxon website. Thank you for that clarification. Can you tell me more about the workaround? I'm currently running Saxon via a filehandle: open(SAXON, "| java -jar saxon9he.jar -s:- -xsl:my.xsl -o:output.xml"), just for the convenience of printing the XML input to STDIN; this should be equivalent to an exec with an XML file as input. What would running the transform command from Saxon/C, avoiding the need to run Java VM, look like? I followed the installation instructions in the readme file, then got stuck. – lschult2 Sep 23 '19 at 16:39
-
Please can you give details of what you got stuck with? The Transform.c, Query.c and Validate.c files are available in Saxon-/C install in the directory 'command'. The bash shell build script should also be in the same directory to compile and create the executable. The executables will run in a similar way to its Java counterpart (same options are available). – ond1 Sep 23 '19 at 16:46
-
Got a little further by adding the include for the directory containing jni.h, but still stuck. Seems some headers are missing, but don't see instructions on how to get the headers for MacOS `sh-3.2# ./buildpec-command.sh -I../Saxon.C.API/jni Transform.c:13:14: fatal error: 'windows.h' file not found #include
` – lschult2 Sep 24 '19 at 00:48 -
This is a bug. The Apple preprocessor directive is missing. See bug issue: https://saxonica.plan.io/issues/4317 I have fixed it and added the workaround simply by replacing the files with the ones in the bug issue. i.e. Transform.c: https://dev.saxonica.com/repos/archive/opensource/latest9.8/hec/command/Transform.c – ond1 Sep 24 '19 at 10:49
-
Progress, but new errors now: `sh-3.2# ./buildpec-command.sh -I../Saxon.C.API/jni Transform.c:15:13: error: cannot combine with previous 'int' declaration specifier typedef int bool; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/include/stdbool.h:31:14: note: expanded from macro 'bool' Transform.c:15:1: warning: typedef requires a name [-Wmissing-declarations] Transform.c:217:9: warning: format string is not a string literal (potentially insecure) Transform.c:217:9: note: treat the string as an argument to avoid this` – lschult2 Sep 24 '19 at 16:17
-
It looks like there are other issue here when running building on macOS. 1) We need to comment out the defining of the bool variable 2) Add preprocessor code for the library path on macOS. – ond1 Sep 24 '19 at 16:39
-
-
I have fixed the two outstanding issues. You should now be able to checkout files from svn and try to build again. – ond1 Sep 24 '19 at 17:04
-
Got it compiled! It was still failing and had to make two more changes: `gcc Transform.c -o transform -ldl -lc -lsaxonpec -DPEC -I../Saxon.C.API/jni` changed to `gcc Transform.c -o transform -ldl -lc -DHEC -I../Saxon.C.API/jni`. So removed -lsaxonpec and changed -DPEC to -DHEC... – lschult2 Sep 24 '19 at 21:45
-
Just following up since it's been a year. Has the integration work needed to extend Saxon/C on Perl come off your todo list yet? – lschult2 Dec 20 '20 at 08:24
-