Table of Contents • 1. Introduction • 2. XSLT2TeX • 3. Add ruby to DocBook • 4. Validating • 5. DocBook xslTNG • 6. Setup Emacs for DocBook 5 and XSLT 3.0 • 7. Content MathML • 8. MusicXML to PMX • 9. Validation □ 9.1. Schematron □ 9.2. NVDL 1. Introduction The idea is fairly simple I would say. xsltproc is available on majority of the popular platforms. 2. Use XSLT to convert epub books to TeX A common issue is that XHTML used in epub is with a namespace. So that namespace should be specified in stylesheet header. Then for example xhtml:html can be referenced. | | | This snippet is what I use to handle ruby in EPUB files. | | | | 5 | | | \ruby[ | | 10 | m | | | g | 15 | j | | ]{ | }{ | 20 | | | | | } | For example, れいぜん, rendered as 霊れい前 ぜん, can be converted to \ruby[j]{霊前}{れい|ぜん}. 3. Add ruby to DocBook The DocBook RELAX NG grammar can be extended so HTML ruby is allowed as an inline text element. |# DocBook 5 with ruby tag |namespace db = "http://docbook.org/ns/docbook" |namespace h = "http://www.w3.org/1999/xhtml" |default namespace = "http://docbook.org/ns/docbook" 5 | |include "docbook5.rnc" { | db.extension.inlines = h.ruby |} | 10 |h.ruby = element h:ruby { | db._any.attribute*, | ((text | db._any | h.ruby), (h.ruby.rt | (h.ruby.rp, h.ruby.rt, h.ruby.rp))?)+ |} |h.ruby.rp = element h:rp { (db._any.attribute | text)* } 15 |h.ruby.rt = element h:rt { (db._any.attribute | text)* } This definition should cover much of the examples given by the HTML specification on ruby. とうなんたつみの方角 東とう南なんたつみの方角 Since ruby is prefixed by HTML namespace, no additional XSLT customization is needed. 4. Validating If you only have xmllint: $ xmllint --noout --relaxng docbook-5.0.1/rng/docbook.rng doc.xml To convert RELAX NG compact syntax to the XML syntax, you would need trang. I prefer writing RELAX NG in its compact syntax. 5. DocBook xslTNG I have recently switch to this version to have better code listing support. The setup is confusing, but still worth it and it follows the DocBook semantic better, with optimized CSS paged media, etc. It is written in XSLT 3.0 so there are more available features, but that also means it requires Saxon. The JAR is self-contained so there are not much worries about portability. 6. Setup Emacs for DocBook 5 and XSLT 3.0 The nxml-mode containted in Emacs has only DocBook 4 grammar installed. By downloading RELAX NG schema in compact syntax, and replace that to /etc/schema/ docbook.rnc or edit schemas.xml in the same directory to enable editing support in Emacs. The same can be done for update XSLT grammar to 3.0. 7. Content MathML These lines can apply the content markup to presentation markup of MathML in DocBook. | | | | The ctop.xsl is available from David Carlisle's web stylesheets. A few examples: | | | | x 5 | x | | x | dsin ⁡ x -------- = cos ⁡ x dx Example 1. Rendered by XSLT dsin ⁡ x ---------- = cos ⁡ x dx Example 2. Rendered by Temml with \frac{d \sin x}{d x} = \cos x | | | | 5 | | 12 | x | | 10 | | y | 2 | | 15 | 2 ( 12 + x ) y Example 3. Notice the parenthesis insertion 8. MusicXML to PMX PMX is the macro preprocessor for MusiXTeX, for some reason xml2pmx cannot parse MusicXML produced by Opusmodus, thus I need this stylesheet to do part of the conversion. | | 5 | | | 9 | 0 | 2 10 | 4 | 8 | 1 | 3 | 6 15 | | | | | 20 | | | | | 25 | % measure | | | | 30 | | / | | | 35 | | | ( | | 40 | | r | | | 45 | z | | | | 50 | | | | | 55 | | | d | | 60 | | | | ) | 65 | | I'm working on convert the stylesheet to XSLT 3.0, so that defining maps would be easier. 9. Validation 9.1. Schematron This is another XML schema language that is designed to be transformed by XSLT to become another XSLT stylesheet to analysis the target XML file. It can impose more complex constraint that RELAX NG cannot specify, with XPath expressions. Note that although it is possible to embed Schematron into RELAX NG, it is still required to be extracted from the RELAX NG schema to be used for validation in most case. 9.2. NVDL This is supported by Jing, however the features of Jing are relatively undocumented. By default, it would strip out elements that are in a different namespace. Thus rule needs to be used to validate against the original schema. Below is an example of NVDL I used to validate articles I wrote in DocBook. | | | | 5 | | | | | 10 | | | | | 15 | | | | | 20 | | | | | 25 | | | | | 30 | |