Subject: Re: Example of multiple html files from one xml file From: Brandon Ibach <bibach@xxxxxxxxxxxxxx> Date: Fri, 27 Oct 2000 18:43:15 -0500 |
Quoting janusz.prusaczyk@xxxxxx <janusz.prusaczyk@xxxxxx>: > Can anybody show me how to get multiple html files from one xml source? > Let's take an example: > > <?xml version='1.0' encoding="ISO-8859-2"?> > <root> > <a> > <b>text 1</b> > <b>text 2</b> > </a> > <a> > <b>text 1</b> > <b>text 2</b> > </a> > </root> > > I want to get 7 files: > > index.html : > > <html> > <head><title></title></head> > <body> > <a href="a1.html">a1</a> > <a href="a2.html">a2</a> > </body> > </html> > > 2 files with <a></a> contents, like a2.html: > > <html> > <head><title></title></head> > <body> > <a href="b3.html">b3</a> > <a href="b4.html">b4</a> > </body> > </html> > > and 4 files with <b></b> tag contents. The names of the files can be > generated, but I can use ID attributes for tags as well (<a ID="a1"></a>). > Is it possible with OpenJade? Can someone show me how to do it? > Here's a solution (untested, but covers the basic issues): (define (file-name nd) (or (attribute-string "ID" node) (let* ((nds (select-elements (descendants (node-list-property 'grove-root nd)) (gi nd))) (num (let loop ((n nds) (r 1)) (if (node-list-empty? n) 0 (if (node-list=? (node-list-first n) nd) r (loop (node-list-rest n) (+ r 1))))))) (string-append (gi nd) (number->string num) ".html")))) (define (make-file fname ssf) (make entity system-id: fname (make element gi: "html" (make element gi: "head" (make element gi: "title")) (make element gi: "body" ssf)))) (element root (make-file "index.html" (process-children))) (define (abrule) (let ((f (file-name (current-node)))) (sosofo-append (make-file f (process-children)) (make element gi: "a" attributes: (list (list "href" f)) (literal (substring f 0 (- (string-length f) 4))))))) (element a (abrule)) (element b (abrule)) The file-name function generates the file name to be used for an element. If the element has an ID attribute, it uses that, otherwise, it concatenates the element name (GI) with a number which is the number of elements with the same GI that precede this one in the document. In other words, the second <a> in the document will get "a2.html". The make-file function takes a file name and a SOSOFO and generates a file with that file name, the contents of which are an HTML document of the structure you displayed, above, with the contents of the <body> being whatever was passed in in the SOSOFO argument. This function uses the (make entity ...) construct that was mentioned earlier. This construct does just what it says: It creates a new entity. "System ID" essentially means file name (though there are other possibilities for them). The abrule function is just a convenience since the <a> and <b> elements should be handled the same. It calls file-name to get the file name to use for the current element, calls make-file to create the HTML for that element, and also creates an <a> element, which will be put in the file of the parent element. If you have any questions, or if anything in the above code doesn't work, let me know. -Brandon :) DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Example of multiple html files from, janusz . prusaczyk | Thread | Re: Example of multiple html files , Markus . Reinsch |
RE: Example of multiple html files , janusz . prusaczyk | Date | Re: The DSSSList Digest V4 #71, Kathie Drake |
Month |