About Sitellite       Screenshots       Downloads       Forge      Documentation       Community       Support

You are here: Home / Documentation / XT Reference

XT Reference

A Complete Example

Here is an example XT document that creates an RSS news feed out of a database query.

<xt:tpl version="1.0">
<xt:xmldecl version="1.0" encoding="ISO-8859-1" />

<xt:doctype
	root="rss"
	access="PUBLIC"
	name="-//Netscape Communications//DTD RSS 0.91//EN"
	uri="http://my.netscape.com/publish/formats/rss-0.91.dtd"
/>

<rss version="0.91">
	<channel>
		<title xt:content="object/title">RSS Feed</title>
		<link xt:content="site/url">http://www.simian.ca/</link>
		<description xt:content="object/description">
			RSS Feed summary...
		</description>
		<language xt:content="object/lang | string: en-us">en-us</language>

	<xt:sql query="
		select		id, title, description
		from		sitellite_news
		order by	date desc
		limit		10
	">
		<xt:sub>
			<item>
				<title xt:content="result/title">Item One</title>
				<link xt:content="string: http://www.simian.ca/index/news/id.${path: result/id}">
http://www.simian.ca/index/news/id.555
</link>
<description xt:content="result/description">
Summary of item one...
</description>
</item>
</xt:sub>
</xt:sql>

</channel>
</rss>

</xt:tpl>

As you can see, a template opens and closes with the <xt:tpl> tag. These denote the template, and their inclusion helps ensure XML conformance even in documents that are not necessarily in XML format.

The most fundamental tag or command in XT is the xt:content attribute, found on the title, link, and description tags in the above example. This tells XT to substitute the current text contained within that XML tag for the value contained in the XTE expression passed to the xt:content attribute, which may be a string, an object path, or a piece of PHP code. We'll look at what the contents of each of the expressions in the example mean later on.

There are a few tags that behave in a very similar manner to xt:content, which are the xt:var tag, and the xt:replace attribute. For example, the following each result in identical output:

<title xt:content="object/title">RSS Feed</title>

<title><span xt:replace="object/title">RSS Feed</span></title>

<title><xt:var name="object/title" /></title>

However, while these three result in the same output, they perform separate functions that are important to differentiate between. xt:content replaces the content of a tag with the result of its XTE expression. xt:replace replaces the entire tag with the result of its XTE expression. xt:var replaces itself (being a complete tag and all) with the result of its XTE expression, but does not allow for fake text to appear inside itself, making it the less appealing of the three in many cases. It wins out however, when fake text for previewing is unwanted, however the <span xt:replace=""></span> option can usually work in those cases as well, with the choice of having fake text still being an option, but not being necessary. The latter two are sometime also preferred when you're only replacing part of the value of the surrounding tag, for example:

<title>-- Your Site: <span xt:replace="page/title">Home</span> --</title>

This is not as easy with the xt:content attribute, since you'd have to write an expression that is a concatenation of the string "-- Your Site:" plus the object path "page/title" plus the string "--". This would be less elegant.

The <xt:sql> block is really more of an advanced feature of XT, so we won't explore it too much for now, but it is rather self-explanatory anyway. The SQL query is executed against the database and the results that are returned (if any) are displayed using the <xt:sub> block on each result, like a loop. The result/id, result/title, result/description values are set by XTE so that you can refer to the current query result as an object path, making it easy to query a database and display formatted results.



Page 1: Design Goals
Page 2: A Complete Example
Page 3: Command Reference
Page 4: Troubleshooting

All Tutorials

Members

Note: You can use your SitelliteForge.com account here and vice versa.

Username

Password

Forgot your password?

Not a member? Click here to register

Sitellite 5 Beta


Copyright © 2008, SIMIAN systems Inc.
All rights reserved. Privacy policy
Some of the icons on this site were created by the Gnome Project.