TEI2SVGdiagrams

From TEIWiki
Revision as of 13:00, 2 October 2007 by Piotr Banski (talk | contribs) (Known Restrictions or Problems: + internal links)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Summary

These XSLT stylesheets take a TEI XML document and produce SVG nested boxes to diagram their structure. They were written by Wendell Piez.

Add any comments to the 'discussion' tab.

Required Input

A TEI XML document.

Actually, any XML document will do, but the 'pruning' stage (see below) of the stylesheets as distributed is tuned for TEI.

Expected Output

An SVG File producing nested boxes to diagram the structure of the input document

Known Restrictions or Problems

These XSLT stylesheets are designed to be run in a pipeline (each stylesheet in the sequence processes the results of the previous stylesheet). Also, several of them require XSLT 2.0 (currently in draft). They were originally implemented and tested in Apache Cocoon 2.1.7, using the Saxon 8.4 XSLT 2.0 stylesheet engine.

Stylesheets

Stylesheets in this package:

  • prune.xsl Removes unwanted elements from input data. This version removes teiHeader and a couple of "formworks" elements. Skip this step if you don't want to prune anything.
  • box-measurer.xsl "Digests" the input document by providing it with a simple code used (in the next step) to determine drawing offsets.
  • tei-svg-render.xsl TEI customizations over svg-render.xsl (which it imports), providing special rules for drawing or labelling TEI elements.
  • svg-render.xsl Generates an SVG "nested box" diagram from the document profile generated in the last step (box-measurer.xsl).
  • svg-scale.xsl Based on input parameters, scales an SVG image (useful for images intended for printing).
  • line-length-setting.xsl Sets a parameter required by both box-measurer.xsl and svg-render.xsl (this module is included by both). If this parameter is not the same for both stylesheets, expect strange results!

Also included here, for completeness

  • directory-list.xsl Makes a directory listing of a given subdirectory of TEI documents, with links to their SVG diagram renditions as called by Cocoon
  • teitext.xsl A rough-and-ready HTML output stylesheet for TEI (pretty sketchy and not intended to be comprehensive)

Cocoon Sitemap

Following is the Cocoon sitemap that configures the installation of these documents in Cocoon.

Assumptions:

  1. The directory 'tei-data' in the subdirectory *under* this sitemap configuration contains an arbitrary repository of (TEI) data. (Note that the features of this pipeline that customize it for TEI are easily removed, so in practice the source could be any XML.)
  2. Stylesheets are stored in a 'stylesheets' subdirectory.

Note I am not a Cocoon expert, so this could probably be optimized!

<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  <map:components>
    <map:generators default="file"/>
    <map:transformers default="xsltc"/>
    <map:serializers default="svgxml"/>
    <map:readers default="resource"/>
    <map:matchers default="wildcard"/>
    <map:selectors default="browser"/>
  </map:components>
  <map:pipelines>
    <map:pipeline internal-only="true">
      <map:match pattern="directory">
        <map:generate src="tei-data" type="xpathdirectory">
        <map:parameter name="xpath" value="/*/teiHeader/fileDesc/titleStmt/title[not(@type='sub')] |
          /*/teiHeader/fileDesc/titleStmt/author"/>
        <map:parameter name="xmlFiles" value="\.xml$"/>
        </map:generate>
        <map:serialize type="xml"/>
      </map:match>
    </map:pipeline>
    <map:pipeline>
      <map:match pattern="**index">
        <map:generate src="cocoon:/directory"/>
        <map:transform type="xslt2" src="stylesheets/directory-list.xsl"/>
        <map:serialize type="html"/>
        <!-- map:serialize type="xml"/ -->
      </map:match>
      <map:match pattern="**/source">
        <map:generate src="tei-data/{1}.xml"/>
        <map:serialize type="xml"/>
      </map:match>
      <map:match pattern="**/html">
        <map:generate src="tei-data/{1}.xml"/>
        <map:transform type="xsltc" src="stylesheets/teitext.xsl"/>
        <map:serialize type="html"/>
      </map:match>
      <map:match pattern="**/tei-svg">
        <map:generate src="tei-data/{1}.xml"/>
        <map:transform type="xsltc" src="stylesheets/prune.xsl"/>
        <map:transform type="xslt2" src="stylesheets/box-measurer.xsl"/>
        <map:transform type="xslt2" src="stylesheets/svg-render.xsl"/>
        <map:transform type="xslt2" src="stylesheets/svg-scale.xsl">
          <map:parameter name="use-request-parameters" value="true"/>
        </map:transform>
        <!--
        <map:serialize type="xml"/>
        -->
        <map:serialize type="svgxml"/>
      </map:match>
    </map:pipeline>
  </map:pipelines>
</map:sitemap>