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 docbook) 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 ν̄ p̂ q̇ 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) -1 (if (equal? element (car elemlist)) count (loop (cdr elemlist) (+ count 1)))))) (define math-type (lambda (ch) (cond ((> (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) result (let* ((cn (node-list-first n)) (c (node-property 'class-name cn))) (loop (node-list-rest n) (sosofo-append result (if (equal? 'data-char c) (wrap-math-list (string->list (string (node-property 'char cn)))) (process-node-list cn) )) ); loop );let );if );let )) 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> and a<INF>1</INF><SUP>i</SUP> ---> <msubsup><mi>a</mi><mn>1</mn><mi>j</mi></msubsup> Not saying about nested: a<SUP>2<SUP>2</SUP></SUP> And of course ν̄<SUP>2</SUP> ----> <msup><mi>ν̄</mi><mn>1</mn><msup> Regards, Mirek DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: RE: (dsssl) simple loop questi, Paul Tyson | Thread | (dsssl) Loop and Data content, Javier Farreres de l |
(dsssl) Mixed Content for Newbies (, m2000 | Date | (dsssl) DSSSList Archives - We Do N, Mulberry Technologie |
Month |