[plt-scheme] XML and Programming

From: Jordan Katz (katz at underlevel.net)
Date: Wed Sep 4 15:24:04 EDT 2002

Eli Barzilay <eli at barzilay.org> writes:

[snip]
> Now, when I was trying to compare what I'd get from SSAX (or whatever
> is the thing which is the equivalent of XSLT, sorry for not knowing
> more about it) to what I have, I realized that this functionality is
> something that I prefer over the general pattern transformations since
> the way I do it is using standard Scheme code, which gives me an
> equivalent power.  For example, with an XSLT thing I should be able to
> convert XML data to HTML for presentation -- and with my thing, I
> could just produce HTML after putting the right definitions that will
> convert something like (title: ...) to (i: ...).

I'm not sure I understand the the advantage in your way of doing it.
It's trivial, using SSAX, to set "handlers" for different tags.  For
example, if I want to define my own tag, stylesheet-ref, that inserts
a reference to a CSS stylesheet in my HTML document.  All it takes is:

(define (generate-HTML Content)
 (SRV:send-reply
  (post-order Content
   `(
     , at generic-web-rules

     (stylesheet-ref
      . ,(lambda (tag . lines)
           (list "<link rel=\"stylesheet\" type=\"text/css\" href=\""
                 lines
                 "/>")))
     ...))))

So what do exactly do you mean by "standard Scheme code"?  All it
takes in SSAX is one lambda.
     
> But there is some functionality which is more difficult with my thing:
> it would be harder to specify that the `title:'->`i:' transformation
> should happen inside a `book:' wrapper.  For this, the XSLT-style
> transformations are easier.

But that's (at least in my opinion and based on my experience) the
most important cases of transformations.  What if I want to match
the title attribute of a chapter tag that appears under the book tag in my
document?  With SSAX you can do this because it can accept any valid
XPath expression (implemented as "SXPath"):

  ;; match "book/chapter/@title"
  (apply-templates my-doc-tree
    `((book chapter @title . (lambda (node) node))))

> And this is another idea that came out of this: it might be useful to
> have these pattern transformations in Scheme even out side the context
> of XML: something that will allow to have macro transformations that
> will allow specifying rewrites like:
>   (transform stx (< (length ?x) 1) (or (null? ?x) (null? (cdr ?x))))
> in a much more convenient way that can be done now.
>
> That's all, sorry for wasted time if it wasn't interesting.

It was interesting, and your package is very neat.  I like it's HTML
outputting mechanisms a lot.  I just fail to see your view on the
usage/implementation of (XSLT and otherwise) transformations (which is
primarily what I use SSAX for).

Thanks,
-- 
Jordan Katz <katz at underlevel.net>  |  Mind the gap




Posted on the users mailing list.