guile's sxml-apply-templates and sxml-match in gauche?
Andreas Reuleaux <[email protected]> Tue, 04 Oct 2022 06:03:18 +0100
| Newsgroups | gmane.lisp.scheme.gauche |
|---|---|
| Message-ID | <87mtacdvu1.fsf@softland> |
Hi,
I have started to work with Scheme's (Gauche's / Guile's) sxml
modules/functions, to replace a former xslt / fo (fop) tool chain of mine
to create some pdfs:
I still rely on fop, to create pdf's from fo files, but these fo
files I create with Scheme now, rather than with xslt.
formerly:
.xml ----<via xslt and some xslt processor>----> .fo ----<with fop>----> .pdf
now:
.xml ----<via scheme / sxml>----> .fo ----<with fop>----> .pdf
(And by the way: while fop's real power is to do the last step: .fo --> .pdf:
fop -fo file.fo -pdf file.pdf
it can do the first step in the old chain: .xml -> .fo as well (given some xslt style sheet):
fop -xml file.xml -xsl style sheet.xsl -pdf file.pdf
but I have never used that: because I rely on
xincludes in my xslt - if I remember right - and fop does not know them).
Anyway, my scheme file is about 1/4th of the size of the xslt file, and
much more manageable, in that I can use any scheme functions that I like
therein (rather than xslt). - And I guess that is some progress /
success!! (I have heard other criticism of xslt: that functions are
not composable, e.g.)
Anyway, my scheme / fop tool chain works fine now - BUT: I use
guile-Scheme, not gauche (even though in general I prefer gauche over
guile).
One (minor) reason:
-------------------
I rely on apply-templates
(as originally defined in
https://okmij.org/ftp/Scheme/xml.html
https://okmij.org/ftp/Scheme/xml.html#SXSLT-examples
and from there:
https://okmij.org/ftp/Scheme/apply-templates.scm)
And Guile makes that easy to use: it is already included in
sxml/apply-templates.scm, thus available with
(use-modules
(sxml apply-templates)
)
That is a no-brainer: this apply-templates.scm file is relatively
short, and I can just include it by hand.
(But it would be useful, if it was included in Gauche, too)!
The other, more serious reason, why I rely on Guile for now:
------------------------------------------------------------
I rely heavily on sxml-match:
https://www.gnu.org/software/guile/manual/html_node/sxml_002dmatch.html
(use-modules
(sxml match)
)
sxml/match.scm in guile's source code, which is only a small wrapper /
compatibility layer to include PLT scheme's sxml-match.ss.
guile's sxml/match.scm
-----
;;; -*- mode: scheme; coding: utf-8; -*-
;;;
;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
;;;
;;; This library is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU Lesser General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (sxml match)
#:export (sxml-match
sxml-match-let
sxml-match-let*)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-11)
#:use-module (ice-9 control))
;;; Commentary:
;;;
;;; This module provides an SXML pattern matcher, written by Jim Bender. This
;;; allows application code to match on SXML nodes and attributes without having
;;; to deal with the details of s-expression matching, without worrying about
;;; the order of attributes, etc.
;;;
;;; It is fully documented in the Guile Reference Manual.
;;;
;;; Code:
;;;
;;; PLT compatibility layer.
;;;
(define-syntax-rule (syntax-object->datum stx)
(syntax->datum stx))
(define-syntax-rule (void)
*unspecified*)
(define (raise-syntax-error x msg obj sub)
(throw 'sxml-match-error x msg obj sub))
(define-syntax module
(syntax-rules (provide require)
((_ name lang (provide p_ ...) (require r_ ...)
body ...)
(begin body ...))))
;;;
;;; Include upstream source file.
;;;
;; This file was taken from
;; <http://planet.plt-scheme.org/package-source/jim/sxml-match.plt/1/1/> on
;; 2010-05-24. It was written by Jim Bender <[email protected]> and released
;; under the MIT/X11 license
;; <http://www.gnu.org/licenses/license-list.html#X11License>.
;;
;; Modified the `sxml-match1' macro to allow multiple-value returns (upstream
;; was notified.)
(include-from-path "sxml/sxml-match.ss")
;;; match.scm ends here
--
PLT's sxml/sxml-match.ss is the real work horse (much longer,
and therefore not shown here).
Just including these same match.scm and sxml-match.ss files
in gauche, fails for me, however. - And it is a little beyond my current Gauche
abilities, to understand how this compatibility macro layer has to be
modified for Gauche [?]
Maybe (sxml-apply-templates and) sxml-match could be included in
future versions of Gauche ?
Thanks in advance.
-A