![]() |
|
|
Your First AxKit PageNow we're going to see how AxKit works by transforming an XML file containing data about Camelids (note the dubious Perl reference) into HTML. First you will need a sample XML file. Open the text editor of your choice and type the following:
Save this file in your web server root (normally /path/to/apache/htdocs/) as test.xml. Now we need a stylesheet to transform that to HTML. For this first example we are going to introduce XPathScript, an XML transformation language specific to AxKit. Later we will give a brief introduction to XSLT. Create a new file and type in:
Save this file as test.xps. Now to get the original file test.xml to be transformed on the server with text.xps we need to somehow associate that file with the stylesheet. Under AxKit there are a number of ways to do that with varying flexibility. The simplest way is to edit your test.xml file, and immediately after the <?xml version="1.0"?> declaration, add the following:
Now assuming the files are both in the same directory under your httpd document root, you should be able to do a request for text.xml and see in your browser server side transformed XML. Now try changing the source XML file, and watch AxKit detect the change next time you load the file in the browser. If things go wrong...If you don't see HTML in your browser, but instead get the source XML in your browser (in Internet Explorer you will see a tree based representation of the XML, and in Mozilla or Netscape you will see all the text in the document joined together), then you will need to check your error log. AxKit sends out varying amounts of debug information depending on the value of AxDebugLevel (which we set to the maximum value of 10). If you can't decipher the contents of the error log, contact the AxKit User's mailing list at axkit-users@axkit.org with details of your problem. How does it work?The stylesheet above specifies how the various tags work. The ASP <% %> syntax delimits Perl code from HTML. You can execute any code within the stylesheet, however here we are making use of the special XPathScript $t hash ref. This specifies the names of tags, and how they should be output to the browser. There are several options for the second level of the hash, and here we see two of those options: pre and post. This specifies quite simply, what appears before the tag, and what appears after it. These values in $t only take affect when we call the apply_templates() function, which iterates over the nodes in the XML, executing the matching values in $t. XPathOne of the key specifications being used in XML technologies is XPath. This is a little language used within other languages for selecting nodes within an XML document. The initial appearance is similar to that of Unix directory paths. In the above example we can see the XPath /dromedaries/species, which starts at the root of the document and finds first the dromedaries root element, then the species children of the dromedaries element. Note that unlike Unix directory paths, XPaths can match multiple nodes, so in the case above, we select all of the species elements in the document. Documenting all of XPath here would take up many pages. The grammar for XPath allows many constructs of a full programming language, such as functions, string literals, and boolean expressions, but it is important to know that the syntax we are using to find nodes in our XML document is not just something invented for AxKit!
|
||||||||||||||||||||||||||||||