Markup languages through the extension of the XHTML Core modules with out prefixes
From Morfeo Wiki
Contents |
References
Introduction
XHTML Modularization provides a structure for the creation of new markup languages through the extension of the XHTML Core modules and the use of the XHTML Module Framework. This document describes the manner in which such modules are defined, and the way in which modules should be combined to create new markup languages.
This example is XHTML plus IDEAL (datefield as child tag of div).
Module Construction
XHTML Modules are made up of at least two modules - a Qname Module and a Declaration Module. In this section we will walk through building each of these. In the next section we will use this new module and some XHTML Core modules to define a new markup language and uses the new markup language in its default form - with no prefixes being defined for any module.
Defining the Qname Module
An XHTML Qname Module should be constructed using the following process:
- Define a parameter entity MODULE.prefixed that announces whether the elements in the module are being used with XML Namespace prefixed names or not. This parameter entity's default value should be "%NS.prefixed;". The NS.prefixed parameter entity is defined by the XHTML framework to be IGNORE by default, and can be used in a document instance to switch on prefixing for all included namespaces (see the prefixing example for more on this).
- Define a parameter entity MODULE.xmlns that contains the namespace identifier for this module.
- Define a parameter entity MODULE.prefix that contains the default prefix string to use when prefixing is enabled.
- Define a parameter entity MODULE.pfx that is "%MODULE.prefix;:" when prefixing is enabled, and "" when it is not.
- Define a parameter entity MODULE.xmlns.extra.attrib that contains the declaration of any XML Namespace attributes for namespaces referenced by this module (e.g., xmlns:xlink). When %MODULE.prefix is set to INCLUDE, this attribute should include the xmlns:%MODULE.pfx; declaration as well.
- For each of the elements defined by the module, create a parameter entity of the form "MODULE.NAME.qname" to hold its qualified name. The value for this parameter entity must be "%MODULE.pfx;NAME". In this way, the parsed value will be "PREFIX:NAME" when prefixes are enabled, and "NAME" otherwise. For example:
<!ENTITY % MODULE.myelement.qname "%MODULE.pfx;myelement" >
If the module adds attributes to elements defined in modules that do not share the namespace of this module, declare those attributes so that they use the %MODULE.pfx prefix. For example:
<ENTITY % MODULE.img.myattr.qname "%MODULE.pfx;myattr" >
Defining the Declaration Module
An XHTML Declaration Module should be constructed using the following process:
- Define a parameter entity to use within the ATTLIST of each declared element. This parameter entity should be %NS.decl.attrib; when %MODULE.prefixed; is set to INCLUDE, and %NS.decl.attrib; plus "xmlns=%MODULE.xmlns;" when %MODULE.prefixed; is set to IGNORE.
- Declare all of the elements and attributes for the module. Within each ATTLIST for an element, include the parameter entity defined above so that all of the required xmlns attributes are available on each element in the module.
Using the module as a stand-alone DTD
It is sometimes desirable to have an XHTML module also usable as a stand alone DTD. The easiest way to accomplish this is to define a DTD file that instantiates the components of your module. Such a DTD would have this structure:
- Include the XHTML Datatypes module (your qnames module likely uses some of these datatypes).
- Include the Qnames Module for your module.
- Define the parameter entity %NS.prefixed.attrib to be MODULE.xmlns.extra.attrib when MODULE.prefixed is set to IGNORE, or to be MODULE.xmlns.extra.attrib and "xmlns:MODULE.prefix=MODULE.xmlns" when MODULE.prefixed is set to INCLUDE.
- Include the Declaration Module(s) for your module.
This DTD can then be referenced by documents that use only the elements from your module.
DTD Construction
Once you have defined your module(s), you are going to want to combine them with XHTML and other modules to create a new markup language. Since in this document we are talking about building these markup languages using DTDs, what you need to do is define a DTD that reflects the markup language. In the remainder of this section, we will explore the process for creating such a "hybrid markup language".
Define the Content Model as a Model Module
A Model Module is an XHTML Module that defines the content model for your new markup language. This module can be extremely complex, or it can be as simple as the declaration of a parameter entity and the inclusion of some other Model Module. Regardless, the purpose is the same: Define the structure of all of the elements in your markup language.
Define the qualified names collection
Your markup language may include one or more additional XHTML-family Modules. Each of these Modules will have a Qname Module. The qualified names collection is a module in which all of the Qname Modules are instantiated, and the set of prefixed attributes are defined. Specifically, a qualified names collection module contains:
- A reference to the Qname Module of each non-XHTML module included
- A definition of the parameter entity XHTML.xmlns.extra.attrib to be the collection of the MODULE.xmlns.extra.attrib parameter entities, one from each included Module
Define the Driver
The driver is the actual file that is referenced by documents written in your new markup language. The driver may be complex or simple, depending upon the markup language. However, each XHTML-family markup language driver must contain the following elements in order to work well:
- A definition of the parameter entity XHTML.version. This should be set to the Formal Public Identifier for your new markup language.
- A definition of the parameter entity xhtml-qname-extra.mod. This must be set to the qualified names collection module defined above. It is fine to have this as only a SYSTEM identifier, since it is internal to the DTD.
- A definition of the parameter entity xhtml-model.mod. This must be set to the Model Module defined above. It is fine to also have this as only a SYSTEM identified, since it is internal to the DTD.
- A series of references to the modules that make up the DTD. This may be a reference to another DTD that you are incrementally modifying, or it may be an explicit list of the XHTML Modules that are being included, or some combination of the two. Regardless, the first thing that actually gets instantiated through this reference is the XHTML Modularization Framework Module. This Module takes care of incorporating all of the XHTML infrastructure, merging it with your specified qualified names and your content model via the parameter entities defined in steps 2 and 3. Don't forget to include your new Declaration Modules, since that is where your new markup languages elements and attributes are defined!
Module Examples
In the following sections, you will see examples of each type of module referred to in this document.
IDEAL Qname Module
File: ideal-qname-1.mod
<!-- PUBLIC "-//MORFEO PROJECT//ELEMENTS XHTML ideal Qnames 1.0//EN"
SYSTEM "http://www.morfeo-project.org/2007/DTDs/ideal-qname-1.mod"
xmlns:ideal="http://www.morfeo-project.org/2007/ideal" -->
<!ENTITY % NS.prefixed "IGNORE" >
<!ENTITY % ideal.prefixed "%NS.prefixed;" >
<!-- Declare the actual namespace of this module -->
<!ENTITY % ideal.xmlns "http://www.my.org/xmlns/ideal" >
<!-- Declare the default prefix for this module -->
<!ENTITY % ideal.prefix "ideal" >
<!-- Declare the prefix and any prefixed namespaces that are required by
this module -->
<![%ideal.prefixed;[
<!ENTITY % ideal.pfx "%ideal.prefix;:" >
<!ENTITY % ideal.xmlns.extra.attrib
"xmlns:%ideal.prefix; %URI.datatype; #FIXED '%ideal.xmlns;'" >
]]>
<!ENTITY % ideal.pfx "" >
<!ENTITY % ideal.xmlns.extra.attrib "" >
<!ENTITY % XHTML.xmlns.extra.attrib "%ideal.xmlns.extra.attrib;" >
<!ENTITY % ideal.datefield.qname "%ideal.pfx;datefield" >
IDEAL Declaration Module
File: ideal-1.mod
<!-- PUBLIC "-//MORFEO PROJECT//ELEMENTS XHTML ideal Elements 1.0//EN"
SYSTEM "http://www.morfeo-project.org/2007/DTDs/ideal-1.mod"
xmlns:ideal="http://www.morfeo-project.org/2007/ideal" -->
<!-- Define the global namespace attributes -->
<![%ideal.prefixed;[
<!ENTITY % ideal.xmlns.attrib
"%NS.decl.attrib;"
>
]]>
<!ENTITY % ideal.xmlns.attrib
"%NS.decl.attrib;
xmlns %URI.datatype; #FIXED '%ideal.xmlns;'"
>
<!ELEMENT %ideal.datefield.qname;>
<!ATTLIST %ideal.datefield.qname;
id CDATA #IMPLIED
bind CDATA #IMPLIED
%ideal.xmlns.attrib;
>
Markup Language Examples
DIAL (XHTML 2) plus IDEAL (datefield as child tag of xhtml).
Content Model Module
File: xhtml-ideal-model-1.mod
<!-- Define the content model for Misc.extra -->
<!ENTITY % Misc.class
"| %script.qname; | %noscript.qname; ">
<!-- .................... Inline Elements ...................... -->
<!ENTITY % HeadOpts.mix
"( %meta.qname; )*" >
<!ENTITY % I18n.class "" >
<!ENTITY % InlStruct.class "%br.qname; | %span.qname;" >
<!ENTITY % InlPhras.class
"| %em.qname; | %strong.qname; | %dfn.qname; | %code.qname;
| %samp.qname; | %kbd.qname; | %var.qname; | %cite.qname;
Text Module | %abbr.qname; | %acronym.qname; | %q.qname;" >
<!ENTITY % InlPres.class
"| %tt.qname; | %i.qname; | %b.qname; | %big.qname;
| %small.qname; | %sub.qname; | %sup.qname;" >
<!ENTITY % Anchor.class "| %a.qname;" >
<!ENTITY % InlSpecial.class "| %img.qname; " >
<!ENTITY % Inline.extra "" >
<!-- %Inline.class; includes all inline elements,
used as a component in mixes
-->
<!ENTITY % Inline.class
"%InlStruct.class;
%InlPhras.class;
%InlPres.class;
%Anchor.class;
%InlSpecial.class;"
>
<!-- %InlNoAnchor.class; includes all non-anchor inlines,
used as a component in mixes
-->
<!ENTITY % InlNoAnchor.class
"%InlStruct.class;
%InlPhras.class;
%InlPres.class;
%InlSpecial.class;"
>
<!-- %InlNoAnchor.mix; includes all non-anchor inlines
-->
<!ENTITY % InlNoAnchor.mix
"%InlNoAnchor.class;
%Misc.class;"
>
<!-- %Inline.mix; includes all inline elements, including %Misc.class;
-->
<!ENTITY % Inline.mix
"%Inline.class;
%Misc.class;"
>
<!-- ..................... Block Elements ...................... -->
<!ENTITY % Heading.class
"%h1.qname; | %h2.qname; | %h3.qname;
| %h4.qname; | %h5.qname; | %h6.qname;" >
<!ENTITY % List.class "%ul.qname; | %ol.qname; | %dl.qname;" >
<!ENTITY % Blkstruct.class "%p.qname; | %div.qname;" >
<!ENTITY % Blkphras.class
"| %pre.qname; | %blockquote.qname; | %address.qname;" >
<!ENTITY % Blkpres.class "| %hr.qname;" >
<!ENTITY % Block.extra "" >
<!-- %Block.class; includes all block elements,
used as an component in mixes
-->
<!ENTITY % Block.class
"%Blkstruct.class;
%Blkphras.class;
%Blkpres.class;
%Block.extra;"
>
<!-- %Block.mix; includes all block elements plus %Misc.class;
-->
<!ENTITY % Block.mix
"%Heading.class;
| %List.class;
| %Block.class;
%Misc.class;"
>
<!-- ................ All Content Elements .................. -->
<!-- %Flow.mix; includes all text content, block and inline
-->
<!ENTITY % Flow.mix
"%Heading.class;
| %List.class;
| %Block.class;
| %Inline.class;
%Misc.class;"
>
Qname Collection Module
File: xhtml-ideal-qname-1.mod
<!-- Bring in the ideal qualified names -->
<!ENTITY % ideal-qname.mod
PUBLIC "-//MORFEO PROJECT//ENTITIES XHTML Ideal Qnames 1.0//EN"
"ideal-qname-1.mod" >
%ideal-qname.mod;
<!-- Define the xmlns extension attributes -->
<!ENTITY % XHTML.xmlns.extra.attrib
"%ideal.xmlns.extra.attrib;" >
DTD Driver
File: xhtml-ideal-1.dtd
<!ENTITY % XHTML.version "-//MORFEO PROJECT//DTD XHTML Ideal Extension 1.0//EN" >
<!-- Define the xhtml qualified names module to be ours -->
<!ENTITY % xhtml-qname-extra.mod
SYSTEM "xhtml-ideal-qname-1.mod" >
<!-- reserved for use with document profiles -->
<!ENTITY % XHTML.profile "" >
<!-- Define the Content Model for the framework to use -->
<!ENTITY % xhtml-model.mod
SYSTEM "xhtml-ideal-model-1.mod" >
<!-- Disable bidirectional text support -->
<!ENTITY % XHTML.bidi "INCLUDE" >
<!-- Bring in the XHTML Framework -->
<!ENTITY % xhtml-framework.mod
PUBLIC "-//W3C//ENTITIES XHTML Modular Framework 1.0//EN"
"http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod" >
%xhtml-framework.mod;
<!-- IDEAL Module before Text Module because datefield is child tag of div -->
<!-- IDEAL Module ........................................ -->
<!ENTITY % ideal-elements.mod
SYSTEM "ideal-1.mod" >
%ideal-elements.mod;
<!-- Text Module (Required) ............................... -->
<!ENTITY % xhtml-text.mod
PUBLIC "-//W3C//ELEMENTS XHTML Text 1.0//EN"
"xhtml-text-1.mod" >
%xhtml-text.mod;
<!-- Hypertext Module (required) ................................. -->
<!ENTITY % xhtml-hypertext.mod
PUBLIC "-//W3C//ELEMENTS XHTML Hypertext 1.0//EN"
"http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-hypertext-1.mod" >
%xhtml-hypertext.mod;
<!-- Lists Module (required) .................................... -->
<!ENTITY % xhtml-list.mod
PUBLIC "-//W3C//ELEMENTS XHTML Lists 1.0//EN"
"http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-list-1.mod" >
%xhtml-list.mod;
<!-- XHTML Images module ........................................ -->
<!ENTITY % xhtml-image.mod
PUBLIC "-//W3C//ELEMENTS XHTML Images 1.0//EN"
"http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-image-1.mod" >
%xhtml-image.mod;
<!-- Document Metainformation Module ............................ -->
<!ENTITY % xhtml-meta.mod
PUBLIC "-//W3C//ELEMENTS XHTML Metainformation 1.0//EN"
"xhtml-meta-1.mod" >
%xhtml-meta.mod;
<!-- Document Structure Module (required) ....................... -->
<!ENTITY % xhtml-struct.mod
PUBLIC "-//W3C//ELEMENTS XHTML Document Structure 1.0//EN"
"http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-struct-1.mod" >
%xhtml-struct.mod;
Block Structural Declaration Module
ELEMENTS XHTML Text (xhtml-text.mod) -> ELEMENTS XHTML Block Structural (xhtml-blkstruct.mod)
Include datefield as child tag of div (File: xhtml-blkstruct-1.mod).
<!ENTITY % div.element "INCLUDE" >
<