📄 0255-0259.html
字号:
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:Developing an XML Memo Application:EarthWeb Inc.-</TITLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><SCRIPT><!--function displayWindow(url, width, height) { var Win = window.open(url,"displayWindow",'width=' + width +',height=' + height + ',resizable=1,scrollbars=yes');}//--></SCRIPT></HEAD><BODY BGCOLOR="#FFFFFF" VLINK="#DD0000" TEXT="#000000" LINK="#DD0000" ALINK="#FF0000"><TD WIDTH="540" VALIGN="TOP"><!-- <CENTER><TABLE><TR><TD><FORM METHOD="GET" ACTION="http://search.itknowledge.com/excite/cgi-bin/AT-foldocsearch.cgi"><INPUT NAME="search" SIZE="20" VALUE=""><BR><CENTER><INPUT NAME="searchButton" TYPE="submit" VALUE="Glossary Search"></CENTER><INPUT NAME="source" TYPE="hidden" VALUE="local" CHECKED> <INPUT NAME="bltext" TYPE="hidden" VALUE="Back to Search"><INPUT NAME="sp" TYPE="hidden" VALUE="sp"></FORM></TD><TD><IMG SRC="http://www.itknowledge.com/images/dotclear.gif" WIDTH="15" HEIGHT="1"></TD><TD><FORM METHOD="POST" ACTION="http://search.itknowledge.com/excite/cgi-bin/AT-subscriptionsearch.cgi"><INPUT NAME="search" SIZE="20" VALUE=""><BR><CENTER><INPUT NAME="searchButton" TYPE="submit" VALUE=" Book Search "></CENTER><INPUT NAME="source" TYPE="hidden" VALUE="local" CHECKED> <INPUT NAME="backlink" TYPE="hidden" VALUE="http://search.itknowledge.com:80/excite/AT-subscriptionquery.html"><INPUT NAME="bltext" TYPE="hidden" VALUE="Back to Search"><INPUT NAME="sp" TYPE="hidden" VALUE="sp"></FORM></TD></TR></TABLE></CENTER> --><!-- ISBN=1575213346 //--><!-- TITLE=Presenting XML//--><!-- AUTHOR=Richard Light//--><!-- PUBLISHER=Macmillan Computer Publishing//--><!-- IMPRINT=Sams//--><!-- CHAPTER=13 //--><!-- PAGES=0235-0262 //--><!-- UNASSIGNED1 //--><!-- UNASSIGNED2 //--><P><CENTER><A HREF="0251-0254.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0260-0262.html">Next</A></CENTER></P><A NAME="PAGENUM-255"><P>Page 255</P></A><!-- CODE //--><PRE><?XML version="1.0"?><!DOCTYPE memo SYSTEM "memo.dtd"><memo><header><sender>Simon North</sender><recipient>Richard Light</recipient><date sortform="19970611">June 11 1997</date><main-heading>Presenting XML</main-heading></header><links><memolinks/></links><text><p id="p1"><anchor id="a1"></anchor>No thanks needed, itwill be fun to do.</p><p id="p2"><anchor id="a2"></anchor>I think yourapproach is perfect. I too have an old copy ofAuthor/Editor, if you could mail me the rules file then Ishould have everything I need to be able to generate SGMLcode that you can use as if were your own. Perhaps you can thenhandle it from there in the same way as your own chapters?</p><p id="p3">What do you do about illustrations (not thatI anticipate having any)?</p><p id="p4">Did Bev say that I was asking what the intention waswith Appendix A? If not, would you please enlighten me a little?</p></text></memo></PRE><!-- END CODE //--><H3><A NAME="ch13_ 19">Writing a Style Sheet</A></H3><P>It's particularly difficult to prepare a concrete example of an XML stylesheet for memos, because no preliminary official draft to work from exists.You'll have to do what you can from the "NOT YET!" draft and hope that nottoo many changes will be made.</P><P>Recall from Chapter 10, "The XML Style Mechanism," that a style sheettakes an XML document and turns it into something completely different—aflow object tree. You might also recall that the style sheet is driven byconstructor rules that say what to add to this flow object tree when each element typeis encountered in the document. The flow object tree is an abstraction thatrequires some format-specific processing to render it onto a physicaldisplay medium (screen or paper).</P><P>In order to produce some concrete results, you need to write a stylespecification that can work with the Jade program. Jade works with XS-compatiblestyle sheets and can produce output in a number of formats. One format isRich Text Format, which is what you should generate. Figure 13.3 shows howone of your memos will look when you are done.</P><A NAME="PAGENUM-256"><P>Page 256</P></A><BR><A HREF="javascript:displayWindow('images/ch13fg03.jpg',288,204)"><IMG SRC="images/tn_ch13fg03.jpg"></A><BR>Figure 13.3.<BR>A memo formatted by XS style sheet.<BR><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>At present, Jade does not have the means to produce anon-screen browsable version of XML documents. Software that does support thiswill clearly be a requirement if XS is to become a practicable style mechanismfor XML documents.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch13_ 20">Defining Styles</A></H4><P>First you should define a number of styles that can be used throughoutyour style sheet. The following code defines the default font—Arial—for thewhole memo:</P><!-- CODE SNIP //--><PRE>(define memo-style (style font-family-name: "Arial"))</PRE><!-- END CODE SNIP //--><P>The following code defines three different font sizes (with suitable linespacing) for paragraph text, header lines, and the main heading (which is alsocentered and bold):</P><A NAME="PAGENUM-257"><P>Page 257</P></A><!-- CODE //--><PRE>(define para-style (style line-spacing: 13pt font-size: 12pt))(define header-line-style (style line-spacing: 17pt font-size: 16pt))(define heading-style (style font-size: 24pt line-spacing: 26pt quadding: `center font-weight: `bold))</PRE><!-- END CODE //--><H4><A NAME="ch13_ 21">Declaring Procedures</A></H4><P>You need to output the header information with suitable prefixes. In orderto save yourself work, you should define a procedure calledpara-with-prefix, which takes a prefix as an argument and puts it before the text in thememo. The following is its declaration:</P><!-- CODE //--><PRE>(define (para-with-prefix prefix) (make paragraph use: header-line-style (make line-field field-width: 50pt (literal prefix)) (process-children-trim)))</PRE><!-- END CODE //--><P>The para-with-prefix procedure creates a paragraph. Within theparagraph it creates a line-field—an inline area—with a width of 50pt. It inserts theprefix into this line-field with the command (literalprefix) and then closes it. You are now back within the paragraph, and the command(process-</P><P>children-trim))) simply outputs the data characters of the currentelement into the paragraph.</P><P>The purpose of the line-field is to line up the sender, recipient, and date,which follow the various prefixes.</P><H4><A NAME="ch13_ 22">Element Rules</A></H4><P>Finally, your style sheet needs to have rules for the various elements in thememo DTD. Start off with a default rule that simply says to output the contentof elements not specified elsewhere. Here is an example:</P><P>(default (process-children-trim))</P><A NAME="PAGENUM-258"><P>Page 258</P></A><P>The following declares the next step, a construction rule for the top-levelmemo element:</P><!-- CODE SNIP //--><PRE>(element MEMO (make sequence use: memo-style (process-children-trim)))</PRE><!-- END CODE SNIP //--><P>The element construction rule for memo uses the stylememo-style, which simply sets the font to Arial. By associating this font with asequence at the highest level of the flow object tree, you are ensuring that all lower-level elementswill inherit this property. Put simply, everything that is output will use theArial font.</P><P>Now declare a construction rule for paragraphs, as follows:</P><!-- CODE SNIP //--><PRE>(element P (make paragraph use: para-style space-before: 10pt))</PRE><!-- END CODE SNIP //--><P>The preceding code uses the para-style style, which was defined earlier,and enforces a 10pt space before each paragraph.</P><P>The following is a similar rule for the main heading:</P><!-- CODE SNIP //--><PRE>(element main-heading (make paragraph use: heading-style space-before: 20pt))</PRE><!-- END CODE SNIP //--><P>Now declare construction rules for the three elements that occur in theheader, as follows:</P><!-- CODE //--><PRE>(element sender (para-with-prefix "From:"))(element recipient (para-with-prefix "To:"))(element date (para-with-prefix "Date:"))</PRE><!-- END CODE //--><P>This is where the effort of writing thepara-with-prefix procedure pays off. It becomes very simple to display these three elements, each with adifferent prefix.</P><P>The fixed links element is not something you want to display, so suppressit as follows:</P><!-- CODE SNIP //--><PRE> (element links (empty-sosofo))</PRE><!-- END CODE SNIP //--><A NAME="PAGENUM-259"><P>Page 259</P></A><P>So far you do not have any means of displaying the quoted passages fromprevious messages. In place of the quoted passages, you can use the presence ofan anchor element as a clue that quoted text should appear here and insert afixed string saying so. The following is an example:</P><!-- CODE SNIP //--><PRE>(element anchor (make paragraph (literal "[fragment of original message was here]")))</PRE><!-- END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>In order to display the quoted passages, you need anXML-aware browser that can resolve the XPointer links, which is not something thatthe XS style language has to do. The style language's job is simply to providea means of rendering complete or partial XML documents when theapplication has managed to obtain them.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch13_ 23">The Full Memo Style Sheet</A></H4><P>Listing 13.4 shows the full style sheet.</P><P>Listing 13.4. XS style sheet for memos.</P><!-- CODE //--><PRE><!doctype style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN">(define memo-style (style font-family-name: "Arial"))(define para-style (style line-spacing: 13pt font-size: 12pt))(define header-line-style (style line-spacing: 17pt font-size: 16pt))(define heading-style (style font-size: 24pt line-spacing: 26pt quadding: `center font-weight: `bold))</PRE><!-- CODE SNIP //--><PRE> continues</PRE><!-- END CODE SNIP //--><P><CENTER><A HREF="0251-0254.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0260-0262.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -