Re: XSL equivalent sought.

Subject: Re: XSL equivalent sought.
From: Brandon Ibach <bibach@xxxxxxxxxxxxxx>
Date: Mon, 4 Oct 1999 02:37:40 -0500
Quoting Peter Nilsson <pnidv96@xxxxxxxxxxxxxx>:
> Ok. Where is this discussion going? Some people want a path language (I
> also think it could be useful). I proposed that such a language be
> implementable in DSSSL (not that it has to be implemented in DSSSL).
> However, I don't find it that important that I would spend muh time on it.
> If anyone has some code to show that implements some path language, we
> could check it out and experiment with it. Otherwise, it may be that
> people don't find it critical to have and we could drop the idea.
> 
   Well, I had hoped to do more with this before I posted it, but I
guess I should speak up now.  DSSSL already *has* a path language, of
sorts, in the form of the match-element? and select-elements
procedures.  Of course, something more powerful, such as XPath, would
be a nice feature to have.
   Toward that end (and in response to Didier's challenge from a
couple of days ago), here's an interesting little thing I put
together.  The document, which contains its own, very simple, DTD,
basically contains a 3x3 "grid" of color names, the rows being marked
A, B and C, and the columns D, E and F.  An attribute of the document
element contains a match-element? pattern which is modified in the
stylesheet to anchor it to the root.
   The document actually gets the value of this attribute from an
entity which get *its* value, via a formal system identifier, from
standard input.  Thus, after starting Jade/OpenJade, you should type
in an A, B or C and a D, E or F, separated by whitespace, then
indicate end of file.  Alternatively, just use "echo" to feed in your
selection.  You will get a report of which color you "chose".
   This, in itself, is not terribly impressive, but it does show the
potential for a string to be parsed into a pattern with which to
select nodes from the grove.  I don't think it would be too difficult
to create functions in DSSSL for parsing and executing XPath
expressions.  We could even create extensions to XPath (which is
allowed by its specification) to generalize it a bit more for use with
non-SGML groves.
   There is nothing that can't be read from a grove with SDQL.  In
fact, a very small subset of SDQL (smaller, even, then the "Core"
query language) provides access to everything in the grove.  All of
the more powerful functions, such as match-element?, are simply built
on top of this subset (or can be, anyway).  XPath, being a
higher-level, declarative language, can be built on top of the more
basic functions in much the same way.

-Brandon :)
<!doctype nav [
<!element nav     o o (a|b|c)+>
<!attlist nav     pick CDATA #REQUIRED>
<!element (a|b|c) - o (d|e|f)+>
<!element (d|e|f) - o (#PCDATA)*>
<!entity stdin SYSTEM "<osfd>0">
]>
<nav pick="&stdin;">
<a><d>Red<e>Orange<f>Yellow</a>
<b><d>Green<e>Blue<f>Indigo</b>
<c><d>Violet<e>Black<f>White</c>
<!doctype style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN">

<style-specification id=nav>

(define debug
  (external-procedure "UNREGISTERED::James Clark//Procedure::debug"))

(declare-flow-object-class formatting-instruction
  "UNREGISTERED::James Clark//Flow Object Class::formatting-instruction")

(define cr (string #\U-000D #\U-000A))
(define ws (list #\space #\U-0009 #\U-000A #\U-000D))

(define groot (lambda () (node-property 'grove-root (current-node))))
(define docelem (lambda () (node-property 'document-element (groot))))

(define from-root (lambda (p)
  (select-elements (descendants (docelem)) (cons (gi (docelem)) p))))

(define parse-pat (lambda (s) (reverse
  (let loop ((i 0) (w -1) (p '()))
    (if (>= i (string-length s)) (if (< w 0) p (cons (substring s w i) p))
      (if (not (member (string-ref s i) ws)) (loop (+ i 1) (if (< w 0) i w) p)
          (loop (+ i 1) -1 (if (< w 0) p (cons (substring s w i) p)))))))))

(root (sosofo-append
        (make formatting-instruction data: "You picked: ")
        (process-node-list
          (from-root (parse-pat (attribute-string "PICK" (docelem)))))
        (make formatting-instruction data: cr)))

</style-specification>
Current Thread