6.2. Hello, World II, or XML to SXML

This example demonstrates automatic conversion of data from XML to the SXML format. Additionally, it's a way to convert an XML file to the SXML format.

Example 11. XML to SXML stylesheet

  xmlns:x = "http://www.w3.org/1999/XSL/Transform"
  xmlns:s = "http://xsieve.sourceforge.net"
  version = "1.0">
<!-- -->

  (use-modules (ice-9 pretty-print))   1

<x:template match="/">                 2
    (pretty-print (x:current))         3


Scheme code inside s:init is executed before applying templates. In this example, the code loads a Guile module that supports pretty printing.


The only one XSLT template, which matches the root node of an XML file.


The XSieve function x:current returns the context node of a template, transparently converting the node from XML to SXML. In this template, the context node is the root node.

The pretty-print function puts the pretty printed SXML result into the standard output. SXML is the only point of interest in this example, so the result of the XML transformation can be ignored. Thereby, one can execute the stylesheet the following way.

$ xsieve -o /dev/null hello2.xsl XML-file

Let XML-file be the following file.

Example 12. XML file for the XML to SXML example

<?xml version="1.0"?>
<article id="hw">
  <para>Hello, <object>World</object>!</para>

The output of the stylesheet for the XML file is the following.

Example 13. SXML result for the XML to SXML example

(*TOP* (article            1
         (@ (id "hw"))
         "                 2
         (title "Hello")
         (para "Hello, " (object "World") "!")

The symbol *TOP* stands for the document root node, and article is the document top-level element node.


Space between tags is character data. In this case it consist of the new line symbol followed by two space symbols.