And Rong Note - XSL-FO & XHTML
=========
Yang He Rong
Version 2.01, modified on December 23, 2002
Introduction to XSL-FO
=========
What is XSL-FO?
------------
XSL-FO: An additional typesetting language based on XML. Its working principle is in the original text information
Join the XML statement, its role is to control the typesetting format of the original text data. XSL-FO is actually very similar to Tex, and Tex
It is widely used in various scientific and technological literature in fifteen years.
The main features of XSL-FO:
- XSL-FO uses XML language format.
- XSL-FO can also be used in conjunction with XSL conversion language, generating two effects on the processed XML file:
First, content conversion; Second, print typography.
"Hello!" Instance
------------
Here is my first XSL-FO instance, Hello.fo:
XML Version = "1.0" encoding = "UTF-8"?> - The name of all elements in the text has "FO:" forward, representing the XML namespace: " http://www.w3.org/1999/xsl/format ". The next question after the XSL-FO file is what software is used to handle such a file. I have made some investigations and tests for this: - I have no way to display the XSL-FO file with MS Internet Explorer 6.0. - XML SPY can be used to edit the XSL-FO file, but I don't know how to use it to display the XSL-FO file. - After I found someone on the Internet, I found a FOP. The trial effect is good, and the PDF file can be generated directly. Install FOP ------------ After preliminary investigation, I found that Formatting Objects Processor seems to be the most common XSL-fo now. Processing software. Below is the step of installing the FOP: 1. Until Http://xml.apache.org/dist/fop/ Extract FOP-0.20.5RC2-bin.tar.gz 2. Unpack-0.20.5rc2-bin.tar.gz in winzip, put the content into /local/fop-0.20.5RC23. Establish a command file, run_fop.bat: /LOCAL/J2SDK1.4.1_01/bin/java -cp /local/fop-0.20.5rc2/build/fop.jar; /local/fop-0.20.5rc2/lib/xercesimpl-2.2.1.jar; / local / FOP-0.20.5RC2 / lib / xalan-2.4.1.jar; /local/fop-0.20.5rc2/lib/avalon-framework-cvs-20020806.jar; /local/fop-0.20.5rc2/lib/batik. Jar org.apache.fop.apps.fop% 1% 2% 3% 4% 5% 6 Note that this is an instruction that must be written, and there is no space between the .jar file name. Due to the limitations of the display width, I have to write this instruction a few lines. If you run the above instruction file in a command window, get the following result: Run_fopusagefop [Options] [-fo | -XML] Infile [-xsl file] [-awt | -pdf | -mif | -pcl | -ps | -txt | -at | -print] Your installation is successful. According to the instructions, FOP has two main functions: - Generate .txt, .pdf, or .ps files in XSL-FO file. - Convert and type the XML file to generate .txt ,.pdf, or .ps file by converting the XML file and places the XML file .txt, .pdf, or .ps file. Generate the XSL-FO file version .txt file ------------ First let us make a simple example, generate a .txt file in the Hello.fo version. Run the following instructions: Run_fop -fo hello.fo -txt hello.txt You will get the following information: [INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser [INFO] FOP 0.20.5rc2 [INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser [INFO] building formatting object tree [INFO] setting Up fonts [info] rendering isas to text [info] [1] [info] Parsing of Document Complete, Stopping Renderer [info] Writing Out Text From this information, we can see that the FOP uses Xerces SaxParser to read the XSL-FO file. we It can also be seen that the results after the typography are only one page. For verification results, use the hello.txt file to open with notepad, you will see: Hello World! ... The typographic results are completely correct. Generate the XSL-FO file version. Pdf file ------------ Our second example is to generate a .pdf file for Hello.fo. Run the following instructions: Run_fop -fo hello.fo -pdf hello.pdf You will get the following information: [INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser [INFO] FOP 0.20.5rc2 [INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser [INFO] building formatting object tree [INFO] setting Up fonts [info] [1] [info] PARSING OF Document Complete, Stopping Renderer Then please open Hello.pdf with Adobe Reader, you will see "Hello World!" Is correctly typed The top left corner of the page. This result is very inspiring, I feel better and better to FOP. Generate the XML file conversion type version .pdf file ------------ In the above two examples, we combine the original text information and the typesetting statement. In this example, We will use two input files: one is the original text data file hello_xsl.xml, one is conversion and typography Statement file hello_fo.xls. Hello_xsl.xml: xml version = "1.0"?> Xml-stylesheet type = "text / xsl" href = "hello.xsl"?> Hello World! p> Hello_fo.xsl: XML Version = "1.0"?> - Typographic command "fo: *" is embedded in the conversion command "xsl: *". - Conversion instructions In addition to introducing typography instructions, the original text data has been simple conversion, and it is added in its first end. A character: "-". Now run the following instructions: Run_fop -xml hello_xsl.xml -xsl hello_fo.xsl -pdf hello.pdf If you open Hello.pdf, the translated text information "-hello world! -" is correctly typed on the upper left corner of the page. XML file conversion processing ------------ In the FOP package, there is an XML file processing software: "Xalan". Its function is to convert the XML file. Below is the running instruction file of Xalan, run_xalan.bat: /LOCAL/J2SDK1.4.1_01/bin/java -cp /local/fop-0.20.5rc2/lib/xercesimpl-2.2.1.jar; /LOCAL/FOP-0.20.5RC2/LIB/xalan-2.4.1.jar Org.apache.xalan.xslt.process% 1% 2% 3% 4% 5% 6 Let us use the last example above, use Xalan, listen to hello_fo.xml to convert hello_xsl.xml: Run_xalan -in hello_xsl.xml -xsl hello_fo.xsl -out hello.out The following is the result of the conversion Hello.out: XML Version = "1.0" encoding = "UTF-8"?> This result is consistent with our expectations. The typesetting statement is completely reserved, and the original information is also converted. Conclusion 1: XML file is used to organize raw text materials, and XSL files are used to define data conversion rules. If needed, The conversion rules can also be embedded in the typographic rules to control the display and printing of the data. Conclusion II: The FOP software can be used for data conversion processing, which can be used for data typography, and can also be used for the disposable processing of data conversion and typography. Other related articles: http://www.geocities.com/herong_yang Copyright Notice This article is helpful to you? Vote: Yes No Vote: 1 0 Discussant: ITJOE Participation: 66 Experts: 0 Posted: 2003-7-1 10:19 am add another point: Configuring the inner font Configure Chinese font 1. Make a font metric file a. If it is a collection of TTC types Java org.apache.fop.fonts.apps.ttfreader -ttcname "Simsun" c: /winnt/fonts/simsun.ttc simsun.xml Pay attention to case sensitive. b. If it is a TTF type font file Java org.apache.fop.fonts.apps.ttfreader c: /winnt/fonts/msgothic.ttf Msgothic.xml 2. Configure the Font section of the userconfig.xml file.
Embed-file = "c: /winnt/fonts/msgothic.ttf"> font>