3 # XSLT 1.0 への修正 result-document(XSLT 2.0)
6 require 'rexml/document'
9 # xslt = XML::XSLT.new()
10 # xslt.xsl = 'data/swjz.xsl'
11 # xslt.xml = 'data/swjz.xml'
15 SOURCE_DIR = File.join(File.dirname(__FILE__), '..', 'data')
16 SOURCE_XML = File.join(SOURCE_DIR, 'swjz.xml')
17 SOURCE_XSL = File.join(SOURCE_DIR, 'swjz2.xsl')
18 OUTPUT_DIR = File.join(File.dirname(__FILE__), '..', 'htdocs', 'swjz')
20 HEADER = '<?xml version="1.0"?>' +
21 '<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-tw" xml:lang="zh-tw">' +
22 '<head><title>説文解字注データ</title>' +
23 '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
24 '</head><body><h1>説文解字注データ</h1><ul>'
25 FOOTER = '</ul></body></html>'
26 @out = File.new(File.join(OUTPUT_DIR, '..', 'swjz.html'), 'w')
28 def chapter_doc(chapter)
29 doc = REXML::Document.new
33 def chaptertitle(chapter)
34 title = chapter.elements["chaptertitle"]
35 note = title.elements["duan_note"]
36 sub = note ? note.text : ""
37 return title.text + sub
40 title = chapter.elements["chaptertitle"]
41 chapter_id = title.attribute("id").to_s
42 return File.join(OUTPUT_DIR, chapter_id + '.html')
46 doc = REXML::Document.new File.open(SOURCE_XML)
47 doc.elements.each("*//chapter/") do |chapter|
48 xslt = XML::XSLT.new()
50 xslt.xml = chapter_doc(chapter)
51 filename = filename(chapter)
52 chaptertitle = chaptertitle(chapter)
53 @out.printf("<li><a href='%s'>%s</a></li>\n", filename, chaptertitle)
55 printf("> %s\n", filename)