msv.schmit.doc.readme.html Maven / Gradle / Ivy
Schmit: SCHema In Transformation
Schmit: SCHema In Transformation
By Kohsuke Kawaguchi
$Id: readme.html 1551 2003-04-30 00:03:46Z kk122374 $
Table of Contents
Introduction
Schmit is an XSLT extension that allows you to access schema annotation information from within the stylesheet.
This functionality can be used to write more generic stylesheet that isn't tied to any particular XML vocabulary.
The current release works for Apache Xalan.
Getting Started
To use Schmit, you first prepare a schema that validates the input of the transformation. For example, if you are converting a DocBook to XHTML, you need a schema for DocBook. Schmit supports RELAX NG and W3C XML Schema.
Assume you have the following schema:
Note that this schema contains attributes from namespace "test". Schmit treats all the non-RELAX NG namespaces in a grammar as "annotations". For XML Schema, elements and attributes inside <xs:annotation> are considered as "annotations".
Inside your stylesheet, you first declare Schmit as an XSLT extension:
As usual, you can use any prefix instead of "sc". But in this document, we assume that the prefix "sc" is used for the extension declaration.
Next, you need to tell the processor to apply the above schema to the input.
This will be done by using the sc:useSchema
extension element.
This can be done at the very beginning of the stylesheet:
...
The href
attribute points to the location of the schema. When this instruction is executed, the schema is loaded.
Once you load a schema, you can use another extension function sc:annotation
to obtain the annotation.
The sc:annotation
function takes a node set, and returns a node set that contains all the annotation elemetns/attributes attached to it. In the above example, we are retriving the value of the a:note
attribute attached to each child
element.
If an input looks like:
Then the result will look like:
1st
2nd
The use of sc:annotation
is not limited to xsl:value-of
; it can be used anywhere where you can write XPath functions. For example, you can write a template matching rule like this:
which will match any element whose definition have a:visible
attribute, or you can write:
which copies HTML documentation of the current element (assuming that you've written one inside schema) into the current location.
XML Schema
When you choose W3C XML Schemas as your schema language, you need to use the sc:annotation
like this:
In other words, you can assume that this method returns xs:annotation
element itself --- therefore you need to be prepared to see elements like xs:appinfo
or xs:documentation
before you get to your own annotation.
Reference
Schmit has one extension element and one extension function. This section defines the syntax of those extensions.
useSchema
extension element
Loads a schema from the specified location and annotate the current input document (the document that includes the context node) with it.
The href attribute takes an attribute value template, meaning that you can write things like this:
annotation
extension function
sc:annotation()
sc:annotation([node-set])
Looks up the annotation attached to the specified nodes, and returns them as a node set.
sc:annotation()
is equivalent of sc:annotation(.)
.
Contact
If you have any comment or suggestion to this technology, please feel free to drop a note to Kohsuke Kawaguchi.