Composing a Site

4 juni 2006

A small language (containing 12 specific words) used to describe a collection of html pages, and how to build them from xml documents and text files such as css.

Site and Page

A site may be furnished with pages. In this example the Site named “first_site” has one Page named “first_page”:


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#">
   <sv:Site rdf:ID="first_site">
      <sv:furnishedWith rdf:resource="#first_page"/>
   </sv:Site>
</rdf:RDF>
				

This page is specified as <html><head/><body/></html>, and will be saved at the location “c:/hf/1.htm”:


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Page rdf:ID="first_page">
      <sv:location>c:/hf/1.htm</sv:location>
      <sv:specifiedAs rdf:parseType="Literal">
         <html><head/><body/></html>
      </sv:specifiedAs>
   </sv:Page>
</rdf:RDF>
				

Note that the words furnishedWith and specifiedAs have been introduced here.

XML Transformations

Any part of the content of a page may be an Element, for example an html div tag, obtained by transforming an xml document by an xslt stylesheets. For example, the body of “first_page” may be generated by transforming m.xml with s.xsl:


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Page rdf:ID="first_page">
      <sv:location>c:/hf/1.htm</sv:location>
      <sv:specifiedAs rdf:parseType="Literal">
         <html><head></head>
         <body>
         <sv:Element>
            <sv:data>c:/mf/m.xml</sv:data>
            <sv:xslt>c:/sf/s.xsl</sv:xslt>
         </sv:Element>
         </body></html>
      </sv:specifiedAs>
   </sv:Page>
</rdf:RDF>
				

Parameters are entered after the xslt file. The following example has two parameters x and y.


<sv:xslt>c:/sf/s.xsl x=a y=b</sv:xslt>
				

Transformations may be chained. In the following example the transformation of the xml document m.xml with sa.xsl gives a new xml document that is transformed with sb.xsl.


<sv:Element>
   <sv:data>c:/mf/m.xml</sv:data>
   <sv:xslt>c:/sf/sa.xsl</sv:xslt>
   <sv:xslt>c:/sf/sb.xsl</sv:xslt>
</sv:Element>
				

The xml and xslt documents are labeled data and xslt. These may also be read using http.


<sv:data>http://www.example.com/a.xml</sv:data>
				

File Aggregations

Files in a directory may be aggregated before the transformation. In the following example all files in the directory c:/mf are aggregated before the transformation with s.xsl.


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Page rdf:ID="first_page">
      <sv:location>c:/hf/1.htm</sv:location>
      <sv:specifiedAs rdf:parseType="Literal">
         <html><head></head>
         <body>
         <sv:Element>
            <sv:data>c:/mf</sv:data>
            <sv:xslt>c:/sf/s.xsl</sv:xslt>
         </sv:Element>
         </body></html>
      </sv:specifiedAs>
   </sv:Page>
</rdf:RDF>
				

A regular expression, such as for example “\w+”, may be employed to aggregate only some of the files in a directory:


<sv:data>c:/mf/(\w+).xml</sv:data>
				

Observe that regular expressions must be enclosed within paranthesis.

Files may also be aggregated by enclosing them within a any element, for example rdf:RDF.


<rdf:RDF>				
   <sv:data>c:/mf1/ma.xml</sv:data>
   <sv:data>c:/mf2/mb.xml</sv:data>
</rdf:RDF>
				

File Fragments

Fragments of a file may be selected. For example the elements with ID of apple and banana is picked from the file ma.xml.

				
<sv:data>c:/mf1/ma.xml apple banana</sv:data>
				

An element may be excluded by means of a ! prefix. For example, all elements except the one with an orange ID.

				
<sv:data>c:/mf1/ma.xml !orange</sv:data>
				

Elements may also be picked by XPath expressions. Three examples are given here:


 1 <sv:data>c:/mf1/ma.xml /*/animal</sv:data>
 2 <sv:data>c:/mf1/ma.xml /*/{http://example.org}n:animal</sv:data>
 3 <sv:data>c:/mf1/ma.xml //mammal //fish //bird</sv:data>
				

Plain Text Files

The content of a plain text file may be included by enclosing the filename within a tag other than data. For example, a css file could be included by enclosing it within a style tag.


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Page rdf:ID="first_page">
      <sv:location>c:/hf/1.htm</sv:location>
      <sv:specifiedAs rdf:parseType="Literal">
         <html><head>
         <sv:Element>
            <style type="text/css">c:/cf/a.css</style>
         </sv:Element>
         </head><body></body></html>
      </sv:specifiedAs>
   </sv:Page>
</rdf:RDF>
				

Books

A site may also be furnished with Books.


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#">
   <sv:Site rdf:ID="first_site">
      <sv:furnishedWith rdf:resource="#first_page"/>
      <sv:furnishedWith rdf:resource="#first_book"/>
   </sv:Site>
</rdf:RDF>
				

A Book may be specified as an xml transformation that unfolds pages:


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Book rdf:ID="first_book">
      <sv:specifiedAs rdf:parseType="Collection">
         <sv:Element>
            <sv:data>c:/mf/m.xml</sv:data>
            <sv:xslt>c:/sf/sp.xsl</sv:xslt>
         </sv:Element>
      </sv:specifiedAs>
   </sv:Book>
</rdf:RDF>
				

The transformation could for example be devised to yield:


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Book rdf:ID="first_book">
      <sv:specifiedAs rdf:parseType="Collection">
         <sv:Page rdf:ID="book_page1">
            …
         </sv:Page>
         <sv:Page rdf:ID="book_page2">
            …
         </sv:Page>
      </sv:specifiedAs>
   </sv:Book>
</rdf:RDF>
				

The Element is, in this case, converted to a collection of two Pages, not to a single Page. More than one Page is allowed only if the Element tag is enclosed by a specifiedAs having Collection as parseType.

Folders

[Update 2007-01-13: The Folder template seems to be unescessary because the Book template can be used for the same things but is more powerful.]

A site may also be furnished with Folders.


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#">
   <sv:Site rdf:ID="first_site">
      <sv:furnishedWith rdf:resource="#first_page"/>
      <sv:furnishedWith rdf:resource="#first_book"/>
      <sv:furnishedWith rdf:resource="#first_folder"/>
   </sv:Site>
</rdf:RDF>
				

A Folder could be thought of as a folded page: Unlike a Book that can be specified in terms of pages, a Folder does not contain, but is split into, pages. The split is described by means of parameters, in the following example by means of $x.


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#">
   <sv:Folder rdf:ID="first_folder">
      <sv:x>a</sv:x>
      <sv:x>b</sv:x>
      <sv:location>c:/html/{$x}.htm</sv:location>
      <sv:specifiedAs rdf:parseType="Literal">
         <html><head></head>
         <body>
         <sv:Element>
            <sv:data>c:/mf/{$x}.xml</sv:data>
            <sv:xslt>c:/sf/s.xsl</sv:xslt>
         </sv:Element>
         </body></html>
      </sv:specifiedAs>
   </sv:Folder>
</rdf:RDF>
				

A Book may contain Folders. This can be useful for batch processing files in a directory. An example is given in Appendix.

Directory Listings

The list keyword is used to construct an xml document of information, such as file names, of a set of files.


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">

   <sv:Page rdf:ID="first_page">
      <sv:location>c:/hf/1.htm</sv:location>
      <sv:specifiedAs rdf:parseType="Literal">.
         <sv:Element>
            <sv:data>list c:/mf</sv:data>
            <sv:xslt>c:/sf/s.xsl</sv:xslt>
         </sv:Element>
      </sv:specifiedAs>
   </sv:Page>
</rdf:RDF>
				

In this example the list c:/mf produces an xml document with data about (but not the content of) the files in the directory c:/mf. A regular expression may be used to select a subset of the files in the directory. Recursive collection of files uses the key words list deep.

Sections

A Section is a piece of markup that may be re-used in many other places.


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Section rdf:ID="site_title">
      <sv:specifiedAs rdf:parseType="Literal">
         <title>My Homepage</title>
      </sv:specifiedAs>
   </sv:Section>
   <sv:Section rdf:ID="license">
      <sv:specifiedAs rdf:parseType="Literal">
         <sv:Element>
            <sv:data>c:/mf/m.xml</sv:data>
            <sv:xslt>c:/sf/s.xsl</sv:xslt>
         </sv:Element>
      </sv:specifiedAs>
   </sv:Section>
</rdf:RDF>
				

Sections may be used in a Page, in a Book, or in a Folder. For example:


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Page rdf:ID="first_page">
      <sv:location>c:/hf/1.htm</sv:location>
      <sv:specifiedAs rdf:parseType="Literal">
         <html><head>
         <sv:Section rdf:about="#site_title"/>
         </head><body>
         <sv:Section rdf:about="#license"/>
         </body></html>
      </sv:specifiedAs>
   </sv:Page>
</rdf:RDF>
				

Stores

A Store has a location where data are read or written.


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Store rdf:ID="h">
      <location>c:/html_files</location>
   </sv:Store>
   <sv:Store rdf:ID="m">
      <location>c:/data_files</location>
   </sv:Store>
   <sv:Store rdf:ID="s">
      <location>c:/xslt_files</location>
   </sv:Store>
</rdf:RDF>
				

Stores are used in Pages, Books, and Folders.


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Page rdf:ID="first_page">
      <sv:location>{h}/1.htm</sv:location>
      <sv:specifiedAs rdf:parseType="Literal">
         <html><head/><body>
         <sv:Element>
            <sv:data>{m}/m.xml</sv:data>
            <sv:xslt>{s}/s.xsl</sv:xslt>
         </sv:Element>
         </body></html>
      </sv:specifiedAs>
   </sv:Page>
</rdf:RDF>
				

Acknowledgement

I have used Cocoon to great benefit for several years. The present language is smaller, and less powerful, than the Cocoon sitemap language.

There are several xml pipeline languages. The present language includes pipelines but is not a general pipeline language.

Revisions

  1. 1 Removed the special meaning of a collection element. Now, in order to aggregate several data elements, these may just be enclosed by any convenient element. Lars · 2006-06-23

  2. 2 Improved the aggregation method in Composer class. Lars · 2006-06-23

  3. 3 Added some support for picking elements by means of XPath expressions. Lars · 2006-06-23

  4. 4 Exchanged the * wildcard to general regular expressions. Lars · 2006-10-29

  5. 5 Added support for generating directory listings. The word list and list deep within a data tag. Lars · 2006-10-29

  6. 6 Has modified the Composer to accept http requests, matching a URI to the regular expression, enclosed within a request tag, of templates of type Archetype. This adds two new words to the previous 12 words. Lars · 2006-12-31

Permission to Use or Redistribute

If you redistribute this work or a derivative, please include a reference to the source (preferably this page). Direct commercial use of this work, or any derivative, requires special licence.

Appendix — a Folder Example

For example we may start from two files batch.xml and book.xsl:


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Book rdf:ID="second_book">
      <sv:specifiedAs rdf:parseType="Collection">
         <sv:Element>
            <sv:data>c:/mf/batch.xml</sv:data>
            <sv:xslt>c:/sf/book.xsl</sv:xslt>
         </sv:Element>
      </sv:specifiedAs>
   </sv:Book>
</rdf:RDF>
				

Here batch.xml could for example be given by:


<?xml version="1.0" encoding="utf-8"?>
<B>
   <input>c:/mf</input>
   <xslt>c:/sf/s.xsl</xslt>
   <output>c:/hf</output>
</B>
				

The transformation book.xsl may be devised to collect the filenames from the directory labeled by the input tag, for example a.xml and b.xml, and generate the following Folder.


<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:sv="http://www.solidera.com/vocabulary#"
      xmlns="http://www.w3.org/1999/xhtml">
   <sv:Book rdf:ID="first_book">
      <sv:specifiedAs rdf:parseType="Collection">
         <sv:Folder rdf:ID="book_folder">
            <sv:x>a</sv:x>
            <sv:x>b</sv:x>
            <sv:location>c:/hf/{$x}.htm</sv:location>
            <sv:specifiedAs rdf:parseType="Literal">
               <html><head>
               <title>page {$x}</title>
               </head><body>
               <sv:Element>
                  <sv:data>c:/mf/{$x}.xml</sv:data>
                  <sv:xslt>c:/sf/s.xsl</sv:xslt>
               </sv:Element>
               </body></html>
            </sv:specifiedAs>
         </sv:Folder>
      </sv:specifiedAs>
   </sv:Book>
</rdf:RDF>
				

The output is two files: a.htm and b.htm, both placed in the directory “c:/hf”.