[Previous] [Contents] [Next]
XML to RTF and MIF Conversion
As a first exercise, lets convert a simple XML file into RTF. The XML input file is shown in Listing 19.3.
Listing 19.3 A Simple XML File for jade
|
1: <?xml version="1.0"?>
2: <!DOCTYPE test [
3: <!ELEMENT test (a | b)*>
4: <!ELEMENT a (#PCDATA)>
5: <!ELEMENT b (#PCDATA)>
6: ]>
7: <test>
8: <a>This is a test</a>
9: <b>This is also a test</b>
10: <b>And this is another test</b>
11: </test>
| As you can see, it's a very simple XML file indeed, using an internal DTD subset to avoid any difficulty with filenames and paths. Now let's try a simple DSSSL style sheet. Have a look at Listing 19.4. |
Listing 19.4 A Basic DSSSL Style Sheet for XML-RTF Conversion
|
1: <!DOCTYPE style-sheet PUBLIC
2: "-//James Clark//DTD DSSSL Style Sheet//EN">
3: (define *rgb-color-space*
4: (color-space "ISO/IEC 10179:1996//Color-Space Family::Device RGB"))
5:
6: (define *blue*
7: (color *rgb-color-space* 0 0 1))
8:
9: (define *red*
10: (color *rgb-color-space* 1 0 0))
11:
12: (root ;set up the page geometry
13: (make simple-page-sequence ;as a simple page
14: page-width: 8.5in ;with characteristics
15: page-height: 11in
16: top-margin: 1in
17: bottom-margin: 1in
18: left-margin: 1in
19: right-margin: 1in
20: (process-children))) ;process the content of document
21:
22: (element test
23: (process-children))
24:
25: (element a
26: (make paragraph ; make a paragraph
27: font-size: 24pt
28: color: *blue*
29: quadding: 'center
30: space-before: 10pt
31: line-spacing: 20pt))
32:
33: (element b
34: (make paragraph ; make another paragraph
35: font-size: 18pt
36: color: *red*
37: line-spacing: 30pt))
| It isn't a particularly simple style sheet because it uses colors and the color definitions are something unique to jade. Fortunately, you don't even really have to understand how the mechanism works. |
| If you want to color a particular element, all you have to do is declare the color space and then declare the colors that you want to use using the R (red), G (green), and B (blue) values. I use *red* and *blue* for the names of the colors because the asterisks make it easier to find the values when you're changing the style sheet. |
|
Figure 19.3 shows the output RTF file loaded in Microsoft Word.
Figure 19.3 The converted XML file loaded in Microsoft Word.
Converting this into MIF format is as simple as changing the-t rtf parameter into -t mif and then loading the output file into FrameMaker, as demonstrated in Figure 19.4.
Figure 19.4 The converted XML file loaded in Adobe FrameMaker+SGML.
[Previous] [Contents] [Next]