[Previous] [Contents] [Next]
Fancy Prefixing
In the previous example we used the name of the element to add a prefix to the element text. Let's take this a step further and do something fancy with these special elements. We'll use the same XML file (Listing 19.5) but a different style sheet, Listing 19.11. To shorten the listing (you will soon get tired of seeing the same old DOC element specification), I'll only include the part of the file that's really relevant (all the code demonstrated in this chapter can be downloaded from the Web site that accompanies this book).
Listing 19.11 DSSSL Cookbook File 2, Advanced Prefixing
|
1: <!DOCTYPE style-sheet PUBLIC
2: "-//James Clark//DTD DSSSL Style Sheet//EN"[
3: <!ENTITY lt "&#60;">
4: <!ENTITY gt ">">
5: ]>
6:
7: <![CDATA[
8: (define RED-ON (make formatting-instruction
9: data: "<FONT COLOR='RED'>"))
10: (define RED-OFF (make formatting-instruction data: "</FONT>"))
11: (define RULE (make formatting-instruction
12: data: "<HR SIZE=5 NOSHADE WIDTH=300>"))
13: ]]>
14:
15: (define (make-special-para)
16: (make sequence
17: RULE
18: (make element
19: gi: "P"
20: attributes: '(("ALIGN" "center"))
21: (make element
22: gi: "B"
23: (literal (string-append (gi) ":"))))
24: (make element
25: gi: "BLOCKQUOTE"
26: attributes: '(("ALIGN" "center"))
27: (process-children)
28: ) RULE ))
29:
30: (element NOTE (make-special-para))
31:
32: (element CAUTION (make sequence RED-ON (make-special-para)
33: RED-OFF))
34:
35:
36: (element PARA (make element gi: "P" ))
| This time I'm using the same make-special-para procedure, but I've added to it. First, I've defined a formatting instruction: |
(define RULE (make formatting-instruction
data: "<HR SIZE=5 NOSHADE WIDTH=300>"))
This means that I can use RULE as shorthand for all that HTML code.
|
Note that I use the keyword data to prevent the markup from being interpreted. (Remember I said that the style sheet was an SGML document. This means that you have to hide any markup that you don't want jade to see.)
I have done the same with the RED-ON and RED-OFF instructions, but this time I've hidden the markup by putting them both inside a CDATA section.
|
|
A NOTE element now has a rule placed above and below it, and it's centered with the text "NOTE:" above it. A CAUTION element is now expanded so that I make a sequence of "RED-ON make-special-para RED-OFF" so that cautions are nicely displayed in red, as shown in Figure 19.8.
Figure 19.8 More advanced properties displayed in the HTML code.
[Previous] [Contents] [Next]