RE: RE: (dsssl) simple loop question

Subject: RE: RE: (dsssl) simple loop question
From: Miroslaw Prywata <Miroslaw.Prywata@xxxxxxxxxx>
Date: Mon, 14 Apr 2003 13:15:57 +0200
> -----Original Message-----
> From: Paul Tyson [mailto:paul@xxxxxxxxxxxxxxxxxxxxxx]

> When Miroslaw first posted his question, I thought he wanted to put 
> chunks of #PCDATA that occur inside of a mixed-content element into a 
> <mi> element in the output.  Subsequent posts seemed to show that he 
> wanted to put <mi> tags around each individual character.  
> That's what 
> Miroslaw's latest code does.

It's even more complicated. But first thing I wanted to do was to be able to
process mixed-content separately for text and separately for nodes.

Every character has to be wrap in an element depending on his type
(operator, number, symbol). The lists of operators presented below is
incomplete, but the code works very well (I took list-member-find from

The problem is converting text from some DTD to MathML. In MathML each
character has to be represented as <mi> <mn> ora <mo> (symbol/italic,
number, operator). The input SGML is Unicode and the code does not take into
account, that one character can be represented by many characters --- that's
quite typical in unicode, e.g. adding accents like


But I do not have simple answer how to do it in DSSSL (maybe first
preprocessing and wrapping "many characters'' that should appear as one one
in wrap element, and then process such temporary tree).

(define operator-list
  '(#\+ #\- #\=))

(define number-list '(#\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\0))

(define (list-member-find element element-list)
  ;; Finds element in element-list and returns the index of its location.
  ;; The first element in a list has index 0.
  (let loop ((elemlist element-list) (count 0))
    (if (null? elemlist)
    (if (equal? element (car elemlist))
        (loop (cdr elemlist) (+ count 1))))))

(define math-type (lambda (ch)
    ((> (list-member-find ch operator-list) -1)  #\O)
    ((> (list-member-find ch number-list) -1)    #\N)
    (else	    #\I)

(define wrap-math-char (lambda (c)
    (case (math-type c)
    ((#\O) (make element gi: "mo" (literal (string c))))
    ((#\I) (make element gi: "mi" (literal (string c))))
    ((#\N) (make element gi: "mn" (literal (string c))))
    (else  (make element gi: "mo" (literal (string c))))

(define (sosofo-list->sosofo sl)
    (apply sosofo-append sl)

(define wrap-math-list (lambda (l)
    (sosofo-list->sosofo (map wrap-math-char l))

(define wrap-with-mi (lambda (#!optional (nl (children (current-node))))
    (let loop ((n nl) (result (literal "")))
	(if (node-list-empty? n) 
    	(let* ((cn (node-list-first n))   (c (node-property 'class-name
		(node-list-rest n)  
		    (if (equal? 'data-char c)
			    (string->list (string (node-property 'char
		    (process-node-list cn)
	    ); loop
There is one more problem. Apart from the above simultaneously one should
also convert subscripts and superscripts:

a<INF>1</INF> --->  <msub><mi>a</mi><mn>1</mn><msub>
a<INF>1</INF><SUP>i</SUP> --->

Not saying about nested:


And of course

&#957;&#772;<SUP>2</SUP> ----> <msup><mi>&#957;&#772;</mi><mn>1</mn><msup>


 DSSSList info and archive:

Current Thread