Introducing XWeb
|
Using your own XMLUsing XWeb for XHTML files allows you to separate the aspects of navigation, layout and textual content in your website, but there is another step you can do to handle your site in an easier way: use XML formats specific for your data. Let's consider a simple example: you want to put your CV on your private site. Of course this can be written in XHTML like this: <h1>Curriculum Vitae</h1> <h2>Education</h2> <dl> <dt>01/01/01 - 03/03/03</dt> <dd>Visited some school</dd> </dl> But a format like this is not easy to maintain since it does not capture the structure of the data directly. Whenever you add a new item you have to make sure that you keep consistency in the layout and if you decide to try another layout, maybe using tables instead of the description lists, you will have to change the whole file. The solution for this problem is to use a data specific XML format. You can either try to find a format someone already defined for the kind of data you have (e.g. BibTeXML for publications or others you can find in special databases) or you just make up your own format, with or without DTD or XML Schema definition. Here is a simple way to write down the information in a CV as XML formatted file: <cv> <section title="Education"> <item> <time>01/01/01 - 03/03/03</time> <description>Visited some school</description> </item> </section> </cv> There are no hard rules how to define these formats, how to call elements and attributs or which parts to model as attributes, which as elements. Here is another version modelling the same data: <curriculumVitae> <group> <title>Education</title> <event time="01/01/01 - 03/03/03">Visited some school</event> </group> </curriculumVitae> And there are many more like splitting the time down into start/end, maybe day/month/year or adding a description to the sections/groups. Here are some rules of thumb that might be useful:
Once you have decided which format to use, you need some XSLT code to change this into XHTML. Once you have the stylesheet for turning your format into XHTML you can give the result of this process into the normal layout stylesheet to be turned into a page of your site. This two-step process allows reusing the layouting part on one hand and the transformation into XHTML form your XML on the other: you can always create a normal XHTML page from your XML file using the same stylesheet you use for XWeb. The way XWeb handles this is called an
XWeb will use an XSLT chain whenever you put another <xsl> element into an existing <xsl> element like this: <xsl stylesheet="stylesheets/layout.xsl" navigationElement="html"> <xsl stylesheet="stylesheets/cv2xhtml.xsl"/> </xsl> You can nest other stylesheets into the inner one, each of them can have <parameter>s attached and each of them is allowed to use the navigationElement attribute. XWeb will first call the inner stylesheet with the parameters attached to the inner <xsl> element, then use the result as input for the outer stylesheet, using the parameters on this level. Here is a simple stylesheet that can be used for turning the first XML version of the example into the HTML version: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <!-- match root element --> <xsl:template match="cv"> <!-- create HTML main parts --> <html> <head> <title>Curriculum Vitae</title> </head> <body> <h1>Curriculum Vitae</h1> <!-- process all sections --> <xsl:apply-templates select="section"/> </body> </html> </xsl:template> <!-- called for each section --> <xsl:template match="section"> <!-- give title attribute as header --> <h2><xsl:value-of select="@title"/></h2> <!-- create list with all items in this section --> <dl> <xsl:apply-templates select="item"/> </dl> </xsl:template> <!-- called for all items --> <xsl:template match="item"> <!-- put time and description as title and text into the decription list --> <dt><xsl:value-of select="time"/></dt> <dd><xsl:value-of select="description"/></dd> </xsl:template> </xsl:stylesheet> The "homesite" example in the distribution uses this approach for the CV, adding parameters to determine the language and splitting the dates into the subparts to give localized date formats. |