The first steps with PSGML and XSlide

Just as we did in the case of PSGML we should prepare a simple XML document with an accompanying stylesheet to get used to the editing environment and to have something to test the shortly-to-be-installed parsers and processors with. We will use essentially the same document as in the PSGML example, adjusted to the XML syntax. This example also does not use an external DTD to simplify processing. There is no need to understand the syntax of the DTD at the moment, simply type it or copy it to your document.

Write an XML document with PSGML

Restart Emacs to apply the latest changes to your _emacs and open a new XML document: Type C-x C-f ~/test.xml to create the document test.xml in your home directory (you may as well type the full path of a file in any other convenient directory). Emacs should load the XML mode (check the modeline close to the bottom of the Emacs window). Now type or paste the following DTD into the new buffer:

      
<?xml version="1.0"?> 
<!DOCTYPE HTMLLite [
<!ELEMENT HTMLLite (H1|P)* >
<!ELEMENT H1 (#PCDATA|EM|STRONG)* >
<!ELEMENT P (#PCDATA|EM|STRONG)* >
<!ELEMENT EM (#PCDATA) >
<!ELEMENT STRONG (#PCDATA) >
]>
      
   

As you just have created the DTD, PSGML is not yet aware of it (when you load an existing XML file, PSGML will automatically parse the DTD due to a setting in our _emacs file). Press C-c C-p to parse the DTD now. Check your DTD again if PSGML issues an error.

Now place the cursor at the end of the buffer and start to append the contents of the document to the prolog. Use the menu command Markup->Insert Element to enter the first element. You will notice that PSGML offers only one possible element to insert: HTMLLite. Accept this and insert another element right where you are. This time you will see that you can either insert a H1 or a P element. You can enter some text between the H1 or P start and end tags. Try to insert another element when the cursor is inside the text in a H1 or P element. This will allow you to insert either a STRONG or an EM element, which again can hold some text. Try also the keyboard shortcut for inserting an element, C-c C-e. You will be prompted for the name of an element. Either enter the full name of an element, the first letters and then the tab key, or simply press the tab key twice to see a list of possible tags at the given location. Note that you don't have to enter hard returns or to manually indent, PSGML takes care of this.

When you're done, save your document by pressing C-c C-s. A valid HTMLLite document may look like this:

      
<HTMLLite>
  <H1>Character of Constantine</H1>
  <P>The person, as well as the mind, of Constantine had been enriched by
     nature with her choicest endowments.</P>
  <P>His stature was <EM>lofty</EM>, his countenance <EM>majestic</EM>, his
     deportment <EM>graceful</EM>; his strength and activity were displayed
     in every manly exercise, and, from his earliest youth to a very
     advanced season of life, he preserved the vigour of his constitution
     by a <STRONG>strict</STRONG> adherence to the domestic virtues of
     chastity and temperance.</P>
</HTMLLite>
      
   

You should also have noticed that PSGML performs syntax-highlighting: Start/end tags and other language-related constructs are shown in different colors to increase readability. Do not delete your test document yet, because you may wish to reuse it in the next chapters.

Writing an XSLT stylesheet with xslide

Now let us create a matching stylesheet for our XML document. We cannot do much with it right now besides creating it, but you'll have something to play with in the next chapters.

Create a new test.xsl file in the same directory that contains your test.xml document: Type C-x C-f ~/test.xsl (or whatever path you chose previously). You should be pleasantly surprised to see that xslide automatically inserts a skeleton stylesheet for HTML output into a new, empty buffer.

The skeleton stylesheet processes the root element ("/") and creates the HTML and BODY elements of the output file. If you wish, you can enhance the output by adding a HEAD element with a TITLE.

Move your cursor just after the xslt:template end tag and press C-c-<. This will invoke the xsl-insert-tag command. You can use the tab-completion in the minibuffer to create another xsl:template element. As an attribute, enter match="H1". Without much surprise, this template will process the HTMLLite H1 elements. As the content of this template, enter:

     
    <h1>
      <xsl:apply-templates/>
    </h1>
      
   

This will simply map the HTMLLite H1 element to the HTML H1 element.

Now add the other missing templates in the same way. You should end up with a stylesheet that looks somewhat like this:

     
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:output method="html"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>HTMLlite document</title>
      </head>
      <body bgcolor="#FFFFFF">
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="H1">
    <h1>
      <xsl:apply-templates/>
    </h1>
  </xsl:template>
  <xsl:template match="P">
    <p>
      <xsl:apply-templates/>
    </p>
  </xsl:template>
  <xsl:template match="EM">
    <i>
      <xsl:apply-templates/>
    </i>
  </xsl:template>
  <xsl:template match="STRONG">
    <b>
      <xsl:apply-templates/>
    </b>
  </xsl:template>
</xsl:stylesheet>