<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- You can remove all whitespace entirely by setting "stripws" in the URL equal to "all" or remove no whitespace by setting it to "none" -->
<?xml-stylesheet href="docbook.css" type="text/css" media="screen"?>
<?xml-stylesheet href="docbook.xsl" type="text/xsl"?>
<!-- Notes for this file are taken at: "/dr_mainnotes.txt" -->
<book xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:html="http://www.w3.org/1999/xhtml" version="5.0">






	<title>SmartyDocB</title>
	<bookinfo>

		<author>
			<firstname>Brett</firstname>
			<surname>Zamir</surname>
		</author>
		<copyright>
			<year>2007</year>
			<holder>Brett Zamir</holder>

		</copyright>
	</bookinfo>
	<!--
	<toc>
		<tocdiv><tocentry>Introduction
			<tocdiv><tocentry><html:strong>Important set-up instructions</html:strong></tocentry></tocdiv>
			<tocdiv><tocentry>Dependencies</tocentry></tocdiv>
			<tocdiv><tocentry><html:strong>Avoiding potential pitfalls</html:strong></tocentry></tocdiv>
			<tocdiv><tocentry>Differences with the original SmartyDoc</tocentry></tocdiv>
		</tocentry></tocdiv>
		<tocdiv><tocentry>Doc_info/doc_raw types<tocdiv><tocentry>(bom, xml, robots, pi, xsl, css, notes, comments, root_pre, dtd, doctype, entity, xsd, root, html, head, meta, title, base, style, link, script, code, head_post, body, body_post, root_post)</tocentry></tocdiv></tocentry></tocdiv>
		<tocdiv><tocentry></tocentry></tocdiv>
		<tocdiv><tocentry>Public API<tocdiv><tocentry>(public vars and methods)</tocentry></tocdiv></tocentry></tocdiv>
		<tocdiv><tocentry>Miscellaneous<tocdiv><tocentry>(tag/tagc, XSL functions, cdata, XInclude, Content Type, Tidy, mobile phones, gzipped output, working solely with templates/working solely with PHP)</tocentry></tocdiv></tocentry></tocdiv>
		<tocdiv><tocentry>FAQ/Trouble-shooting</tocentry></tocdiv>
	</toc>
	-->
	<chapter>
	<title>Acknowledgments</title>
		<para>Many thanks to "boots" for getting me interested in his useful and well-written SmartyDoc code by providing it open source, by answering my questions, giving helpful feedback, and by encouraging my participation. I would also like to thank "vain" for helping out, and despite having only just joined in on the development (around 3/07) has made some very helpful improvements and ideas for the future. The PHPDocumentor documentation was by his doing.</para>
		<para>While the implementation and functionality is slightly different, I owe the idea of the partial-page XSL conversions to Richard Bateman's <link xlink:type="simple" xlink:href="http://smarty.incutio.com/?page=SomeXSLTPlugins">SomeXSLTPlugins</link> and Serge Stepanov's <link xlink:type="simple" xlink:href="http://smarty.incutio.com/?page=XSLTBlockFunction">XSLT block function</link>. Thanks are also definitely in order to Jonah Winters, who has generously and patiently enabled me to work with him on his <link xlink:type="simple" xlink:href="http://bahai-library.com">Bah&#x00E1;'&#x00ED; Library Online</link> site.</para>

	</chapter>
	<chapter>
		<title>Introduction</title>
		<para>SmartyDocB is a tool for <link xlink:type="simple" xlink:href="http://smarty.php.net">Smarty</link> to allow you to edit XML (including XHTML) or plain HTML in a flexible fashion. It is a fork of the original <link xlink:type="simple" xlink:href="http://smarty.incutio.com/?page=SmartyDoc">SmartyDoc plugin</link> by "boots". This documentation itself was created using SmartyDocB.</para>
		<para>While the separation of data, structural output, styles, and localization indeed holds many desirable benefits and has been made possible via XML, XSLT, CSS, and XML entities respectively (not to mention the separation of (PHP) server-side code from data/structure/styles/localization brought by Smarty templating), all of this separation can become a hassle--both in terms of managing different files (e.g., opening them, referencing them, etc.) and switching back-and-forth between them. Sometimes, it would be nice to have the ability again (as with an old HTML page) to look at a file and understand what type of data, styles, and localized content (i.e., translations) were intended to go within that page. This holds true even for files which we have ourselves created, as it can be hard on our memories--even in the short-term--to understand a page without any concrete examples of intended output, styles, and localization being made within it.</para>

		<para>SmartyDocB makes it possible to have the best of both worlds. One can stuff all of the above into one's templates if desired (e.g., data, styles, scripts)--while having the output shuttled off into different directions (e.g., into the head of the document, into separate files, or into one site-wide file for scripting, styles, localized content, etc.). SmartyDocB will also add comments/notes to the files where the content was moved (and optionally within the main output document), in order that when viewing the resulting files, you or your designers can know the name of the template from which the various content there originated.</para>
		<para>In addition to the possibilities of including style and script content that is shuffled away, one can also shuffle away the following to a site-wide file or to separate files: XSL, DTDs, XML Schema, entities, and even notes to yourself (which you can either hide or reference in the comments). Various other tags can be invoked from anywhere within a template to be created in the proper sequence within the head of an XHTML document (e.g, title, meta, link) or an XML/XHTML prolog (e.g., XML declaration, processing instructions, internal doctype, etc.), and generic content can be sent to various general parts of a typical document such as before the root element (prolog), to the head (epilog) or body (post-epilog), or after the root.</para>
		<para>While the shuffling of content in SmartyDocB generally occurs one whole block at a time, the tag/tagc functions also enable one to have style data shuffled away to the head of the document or to an external file while the style assignment itself is attached to just a single tag. This allows a person to replicate the functionality of the now-deprecrated "style" attribute in XHTML without it showing up in the source code as such. However, it goes beyond the "style" attribute in that one can decide how to treat it--whether to add the style information to the stylesheet using the element's id, or to reuse that style by assigning the style to a whole element and/or class. An id or class will even be auto-created if none were manually added. These functions (which can appear similar to a regular XML tag) allow for more portability, since, to make changes, one does not need, for example, to change the class name in both the head and in the document when making a class name change. And, this offers the ability to place the styles exactly where you are really using them (or where you first use them)--directly within such an element. This will thus allow you to both visualize your data with your desired styles, but let the data also be reused, and take advantage of the other benefits of external stylesheets--e.g., browser caching.</para>
		<para>SmartyDocB also seeks to automate certain aspects of writing XHTML and XML so that common tags, headers, etc., can be auto-created. The application also makes XML easier in other ways (e.g., partial or complete server-side XSL transformations, Tidying of output, creation of CDATA sections, managing whitespace, etc.).</para>
		<para>SmartyDocB is intended to make XML more fun and manageable than would otherwise be possible with expecting you to separate all the components of your pages from the get-go. It is intended to allow you to write and edit in a more organic fashion, while still producing documents which offer cleanly-separated PHP, data/localizations, structure, styles, client-side scripts, etc.</para>
		<para>Questions on setup or use are also welcome in the <link xlink:type="simple" xlink:href="http://www.phpinsider.com/smarty-forum/viewtopic.php?p=38610">forums</link> as is any feedback.</para>

		<sect1>
			<title>Installation and set-up</title>
			<para>SmartyDocB must have the class required along with the Smarty class and then create a new Render_SmartyDoc object (instead of creating just a regular Smarty object):</para>
			<html:code>require($smarty_dir.'/smarty/libs/Smarty.class.php');
require($smarty_dir.'SmartyDoc2.class.php5');
new Render_SmartyDoc();</html:code>
			<para>This will create an object that will let you use the default 'doc_info' and 'moveto' functions.</para>
			<para>Note that this manual and the program's API, for historical reasons, still refer to 'moveto' as 'doc_raw'. However, within templates, you can use the preferable function name 'moveto'. For example,
			<html:code>{moveto target=head}&lt;-- head items --&gt;{/moveto}</html:code>

			To use the older terms (or other ones) within the template as well, the desired terms can be added, respectively, to the constructor call:</para>
			<html:code>require($smarty_dir.'/smarty/libs/Smarty.class.php');
require($smarty_dir.'SmartyDoc2.class.php5');
new Render_SmartyDoc('doc_info', 'doc_raw');</html:code>
			<para>One could thus use the older:
			<html:code>{doc_raw target=head}&lt;-- head items --&gt;{/doc_raw}</html:code>
			</para>
			<para>Future editions of this program will probably move exclusively toward "moveto", so please use that within your templates for now.</para>

			<para>As with Smarty, you'll need to define the following directories:</para>
			<html:code>$smarty->template_dir = $sm_base_dir.'/smarty/templates';
$smarty->compile_dir = $sm_base_dir.'/smarty/templates_c';
$smarty->cache_dir = $sm_base_dir.'/smarty/cache';
$smarty->config_dir = $sm_base_dir.'/smarty/configs';</html:code>
			<para>The following must refer to your own site. Note that to change their setting you must first make the above call to construct the smarty object, and then reference your Smarty object such as follows: <html:code>$smarty->site_root_public = '/home/main/public_html';</html:code></para>
			<itemizedlist>
				<listitem><html:var>$site_root_public</html:var>: used as a base for main files (e.g., for writing to a main site CSS file)</listitem>
				<listitem><html:var>$site_root_hidden</html:var>: used as a target for hidden files (e.g., if you are embedding publicly hidden notes across your files--this feature assembles those notes into one place); this directory should be out of the publicly-accessible directory (e.g., above /htdocs or /public_html in Apache) if you want to avoid the chance for others to guess its location! Although the script should work as intended, just to be sure, if you have sensitive content, you might not want to add them through this script; the main idea was to allow you to embed programming to-dos and notes within your templates and be able to retrieve them later all in one file automatically.</listitem></itemizedlist>

				<para>You should also set the following for your site (if you are using them) or otherwise set <html:var>$auto_xform_mobile</html:var> to false:</para>
				<itemizedlist>
				<listitem><html:var>$Browscap_cache_dir</html:var></listitem>
				<listitem><html:var>$Browscap_file</html:var></listitem>
				</itemizedlist>
				<para>If you want to use browscap or browscap.ini to allow your pages to be auto-transformed into XHTML Basic for cell phones, be sure to save a copy of the XSL stylesheet from the <link xlink:type="simple" xlink:href="http://www.w3.org/2003/04/xhtml1ToBasic.xsl">W3C site</link> to your own system and then set <html:var>$xhtmlbasic_xsl</html:var> to the location of your local file; otherwise, the transforms will take much, much too long if you try to reference the file above directly! One unfortunate inevitable inadequacy of any such XHTML to XHTML Basic transformation is that this stylesheet won't work properly if your page has nested tables, since XHTML Basic doesn't support them, and the stylesheet doesn't know how to convert them.</para>

			<para>You will also need to consider the following important settings:</para>
			<itemizedlist>	
			<listitem>In order to avoid constant file-rewriting, the default value of <html:var>$rewrite_doc_raw_on</html:var> is set to FALSE. However, please realize that in such a case, no externally targeted doc_raws will be written if you do not at least once set this to true and visit the page! You can then set <html:var>$rewrite_docraw_on</html:var> back to FALSE after debugging (but preferably before going live) so that rewrites (e.g., of the main site's CSS file) will not be performed on each script execution. You may also want to set <html:var>$rewrite_docraw_get</html:var> to false or at least change the name of <html:var>$rewrite_docraw_get_url</html:var> if you don't want others to be able to selectively force a rewrite of those files on the live site (it is there for your testing and debugging convenience).</listitem>

			<listitem>Note that when <html:var>$rewrite_docraw_on</html:var> is true, the styles (and scripts, etc.) generated by the external doc_raws for that set of template(s) will be replaced (if they already existed) and placed at the top of the preexisting file(s). They are placed first so that later cascading will force the designer to see that new changes may be being overridden by styles added from other templates (and comments are always auto-created for external doc_raws (out of necessity in order for the script to know where to find the portion of the file that should be replaced), so you can see where the other styles/code is coming from).</listitem>
			<listitem>You also have the following options (the following are all on and set by default, so you'll need to turn them off if you don't want this available to your site's users--and for extra security, you may in fact wish to turn them off unless you are debugging or if your site wishes to be especially open in sharing its content):
				<itemizedlist>
					<listitem>With <html:var>$comments_get</html:var> set to TRUE and a URL GET string set for <html:var>$comments_get_url</html:var> to turn on all of the comments in the output document (if caching is not on) through a URL GET request.</listitem>

					<listitem>You can also optionally strip some, all, or none of the extra whitespace with a URL request when <html:var>$whitespace_get</html:var> is set to TRUE and <html:var>$whitespace_get_url</html:var> has a URL GET string set.</listitem>
					<listitem>With <html:var>$xform_get</html:var> set to TRUE and <html:var>$xform_get_url</html:var> set to a GET string, you will be able to circumvent all server-side transforms and allow the transformation to be done client-side.  Be aware that this will allow your site visitors to see the generated XML document as well as your XSL stylesheets.</listitem>

					<listitem>And one can have <html:var>$xformtobasic_get</html:var> set to TRUE with <html:var>$xformtobasic_url</html:var> string defined in order to allow a URL request to transform the document into XHTML Basic, using the file at <html:var>$xhtmlbasic_xsl</html:var> for the transformation (please do not use <link xlink:type="simple" xlink:href="http://www.w3.org/2003/04/xhtml1ToBasic.xsl">http://www.w3.org/2003/04/xhtml1ToBasic.xsl</link> directly but instead go to this site, save a copy of this file on your system, and reference it within the <html:var>$xhtmlbasic_xsl</html:var> class variable to avoid long delays at your site and undue calls to the W3C site!). XHTML Basic is used by devices such as cell phones, and although this script offers the possibility for auto-detection of mobile phone devices and automatic server-side transformation of your pages into XHTML Basic, you may wish to keep a GET request available for either yourself during debugging (if you want to see how the page will appear to cell phones), or to mobile phone users directly in case the transformation is not made.
					</listitem>

					</itemizedlist>		
			</listitem>
			<listitem>You will probably want to also set the public <html:var>$comments</html:var> item to false (or tweak the related comments object variables) once you go live, since quite a few comments can be added and this can slow things down during loading time (they also make reference to your template file names if not locations, but then again, so are comments referring to your template file names also necessarily added within your attached CSS/script/etc. files which can be viewed publicly anyways).</listitem>
			<listitem><html:var>$debug</html:var> is set to true, but you may wish to set it to FALSE so that things like your XSL file location will not show up in the error output in the event that there is a failure in making a stylesheet transformation.</listitem>
			</itemizedlist>
			<para>Finally, instead of using $smarty->display() to display your template, you will invoke "displayDoc", such as:
			<html:code>$smarty->displayDoc('mytemplate.tpl');</html:code>

			As with Smarty's 'display' method, 'displayDoc' allows you to add a pipe-separated sequence of variables for conditional caching. For example:
			<html:code>$smarty->displayDoc('mytemplate.tpl', $language.'|'.$userstatus);</html:code>
			</para>
			<para>If you would like to display documents without making any $smarty->assign() calls, such as if you wished to inject X/HT/ML from the PHP side into a blank template (e.g., for testing purposes) or if, on the converse, you just wished to use templates written in X/HT/ML (without using any $smarty->assign's) while taking advantage of the doc_raw features of SmartyDocB, see the sections below on "Working solely with templates (XML/HTML)" or "Working solely with PHP injection of content".</para>
			<para>You are now ready to use the program.</para>
		</sect1>
		<sect1>
			<title>Dependencies</title>

			<para>To use XSL server-side transforms, one must have installed the <link xlink:type="simple" xlink:href="http://php.net/XSL">XSL extension</link> (the update of the "XSLT" extension from PHP4).</para>
			<para>To use Tidy, one must have the <link xlink:type="simple" xlink:href="http://php.net/tidy">Tidy extension</link> installed (for PHP5).</para>
			<para>To use <link xlink:type="simple" xlink:href="http://cn.php.net/function.get-browser">Browscap</link>, one must have it installed and follow its licensing--use of the <link xlink:type="simple" xlink:href="http://browsers.garykeith.com/index.asp">browscap.ini database</link> is under Creative Commons Attribution-Non-Commercial (or get its author's permission) whereas the <link xlink:type="simple" xlink:href="http://garetjax.info/projects/browscap/">PHP class for Browscap</link> is under the Creative Commons Attribution-Share Alike 2.5 License).</para>

			<para>The script checks to see if you have the <link xlink:type="simple" xlink:href="http://php.net/zlib">zlib extension</link> loaded in order to avoid using PHP's own <link xlink:type="simple" xlink:href="http://php.net/ob_gzhandler">gzip</link>. This extension is not in any way required.</para>
		</sect1>
		<sect1>
			<title>Working solely with templates (XML/HTML)--no PHP injection of content or Smarty assigns</title>
			<para>If you wanted to just work with XML or HTML as template files (i.e., without PHP adding any template variables for you, but you wanted to take advantage of doc_raws shuffling off content or doc_infos), after requiring all of the necessary Smarty files (including this one), you might simply consider a PHP script like the following (though you should look into the relevant security concerns, as I'm sure there are by allowing data in like this unfiltered):</para>

			<para>
		<html:code>
&lt;?php
// $smarty->xml_plain = true; // Uncomment if you want to work with XML
// $smarty->add_openclose = false; // Uncomment if you want to work with (non-XHTML) XML

$tpl = $_GET['tpl'].'.tpl';
if (file_exists($smarty->template_dir.'/'.$tpl)) {
   $smarty->displayDoc($tpl);
} // end if
else {
   print "Template could not be found.";
} // end else
?>

</html:code></para>
			<para>You could thus have a URL like the following work: http://example.com/portal/index.php?tpl=myxhtml (where myxhtml.tpl was a template in your template directory)</para>
</sect1>
		<sect1>
			<title>Working solely with PHP injection of content--no templates or Smarty assigns</title>
			<para>If you wanted the opposite of the above (i.e., just to work in PHP without templates--e.g., for testing), consider using the addRaw functions (perhaps on contents gathered by ob_get_clean() after a ob_start() call within the PHP script) on a blank template, then calling displayDoc on the blank file:</para>

			<para>
<html:code>

&lt;?php
$avar = "Some";
$postcontent = &lt;&lt;&lt;HERE
&lt;!-- Content on each page but not on any template -->
&lt;!-- some comments or tags could go here -->
HERE;
$smarty->addRawContent($precontent, '', 'head_post');
$smarty->displayDoc('blank.tpl');
?>

</html:code>
</para>
		</sect1>

		<sect1>
			<title>Avoiding potential pitfalls</title>

			<para>If you do not assign different values to these member variables, the default "&lt;&lt;" and "&gt;&gt;" are used for tag and tagc functions. I did not bother to add yet another regular expression to escape these even within the {literal} tag, so you will have to use &amp;lt; and &amp;gt; to do so. The prefilter for the class also does some escaping that could potentially interfere with certain sequences of characters (although it is not likely).</para>
			<para>One very necessary tip for debugging if you decide to tweak the code at all (especially the prefilter or changing the tag/c delimiters too!): be sure to delete both your caches and compiled template files!</para>
		</sect1>
		<sect1>
			<title>Differences with the original SmartyDoc</title>

			<para>SmartyDocB was naturally heavily inspired by SmartyDoc. However, due to some changes I wanted to make for naming consistency, I have not made SmartyDocB to be wholly compatible with the original SmartyDoc (at least for a number of the items such as DTD's).</para>
			<para>At this stage, you will need to consult their respective source code to find the exact differences or consult the relevant part of this manual to see how a given feature is now used.</para>
			<para>However, the following paragraphs describe some of the key differences.</para>
			<para>The purpose of this fork was originally to improve XHTML support and allow unescaped CSS (expanding on doc_raw) until such time as Boots was able to update his version (SmartyDoc) and reconcile any parts of the fork that he wished to incorporate. However, the file has since expanded considerably to include:</para>
			<itemizedlist>
				<listitem>strong support for XML (including XHTML)</listitem>

				<listitem>the ability to shuffle off styles, scripts, XSL's, DTD's, XML Schema, parsed/unparsed entities, and personal notes, not only into the head of the document (where appropriate and specified), but also into either one coordinated site-wide external file or into specified files (the idea for the latter, I should mention, was already envisaged by boots).</listitem>
				<listitem>auto-generation of comments denoting which blocks were created by SmartyDocB and from what templates the code within originated.</listitem>
				<listitem>features for facilitating use of XML (e.g., CDATA, XInclude, robots/processing instructions, targetting pre- or post-root, byte-order-marks, etc.)</listitem>
				<listitem>ability to add attributes to doc_raws (where appropriate--e.g., when shuffling off content to a style tag</listitem>
				<listitem>leveraging of a number of PHP extensions or external code (e.g., Tidy, XSL, zlib, Browscap (for detecting mobile phones to serve them XHTML Basic))</listitem>
				<listitem>some new functions/modifiers that can also be used independently: various PHP5-compatible XSL conversions that mimic and expand upon the function of some user-submitted XSL plugins for PHP4 (Richard Bateman's <link xlink:type="simple" xlink:href="http://smarty.incutio.com/?page=SomeXSLTPlugins">SomeXSLTPlugins</link> and Serge Stepanov's <link xlink:type="simple" xlink:href="http://smarty.incutio.com/?page=XSLTBlockFunction">XSLT block function</link>).</listitem>

				<listitem>functions which in combination with the prefilter allow one to make individual tags which will be printed out where they were called (unlike doc_info and doc_raw), but which will intelligently shuffle off style information into external files or the head (Tag and tagc functions).
</listitem>
				<listitem>some developer-related changes: the bulk of doc_raw processing has been moved to its own 2 functions to facilitate code maintenance.</listitem>
			</itemizedlist>
			<para>The new version of this fork has regrettably also made some backwards-compatibility-breaking changes. For example, 'DOCTYPE' was changed to 'dtd' for definitions referencing an external file, while it is now 'doctype' that creates internal doctype additions (following the convention I've started to have the tag-name (e.g., doctype, style, script) represent internal additions, with a pseudonym (e.g., dtd, css, code) representing externally-targeted items). There are certainly other backwards-compatibility-breaking changes for which one should consult the documentation.</para>
			<para>There are also a few features (such as boots' modules and a number of the public API functions that I do not document here) which I have not tested on the code and may well break if used in the new version without modifications.</para>
		</sect1>
		</chapter>

	<chapter>
		<title>Doc_info and moveto/doc_raw types</title>
		<para>Note: "moveto" is the new name for "doc_raw" (explained below), but for historical reasons, much of the API still uses "doc_raw". You should use "moveto" within the templates (though for backwards compatibility one can add an argument to the constructor at present to use "doc_raw" instead). This documentation will use the term "doc_raw", however.</para>
		<para>Doc_raws and doc_infos allow one to place certain blocks of content (or references to content) and shuffle them off into other areas including external files. Doc_raw is a Smarty block function (i.e., encapsulates text), whereas doc_info is a plain Smarty function (i.e., no encapsulated text besides any content contained within its attributes).</para>
		<para>Doc_raws, when not being targeted to the head or other place within the document, can have their content shuffled off into:</para>
		<itemizedlist>
		<listitem>Any number of separate external files (as indicated by the "file" attribute for the doc_raw)</listitem>

			<listitem>One site-wide external file (specifiable via the API) into which all styles, scripts, etc. for the site are to be collected (as indicated by the absence of any "file" attribute).</listitem>
		</itemizedlist>
	<para>Targeting the doc_raw blocks into the latter type (one site-wide external file each for scripts, styles, etc.) has numerous benefits including:</para>
		<itemizedlist>
			<listitem>One is forced to coordinate all of one's styles (or scripts, etc.) and avoid duplicating items that must be maintained separately.</listitem>
			<listitem>One is forced to provide site-wide styles that are consistent and follow the same naming pattern.</listitem>
			<listitem>One's pages can take advantage of browser caching of stylesheets, as visitors' browsers will not reload the same external file (e.g., a stylesheet) if the file were already loaded (e.g., after visiting the main page).</listitem>

		</itemizedlist>	

		<para>A key can be assigned to doc_raws to force them to follow a prescribed order (or to override an existing doc_raw elsewhere in the template). For example, <html:code>{doc_raw target="script" key=2}alert('a');{/doc_raw}
{doc_raw target="script" key=1}alert('b');{/doc_raw}
</html:code> will create two alerts--with 'b' coming before 'a'. One can also overwrite a previous doc_raw of a given type (and file if present) by using the same key for the subsequent (overriding) item.</para>
		<para>The various subsections here describe in detail how to use a given doc_info/doc_raw feature. In many cases, if a name exists for doc_info, it will exist for doc_raw and vice versa.</para>
		<para>All features are available when writing XHTML, and as appropriate if writing plain HTML. For plain or "pure" (non-XHTML) XML, one can of course also use the features to create an XML declaration, XSL stylesheets, and XML Schemas, doctypes and dtd (internal or external references), CSS (will be external only and as a xml-stylesheet processing instruction) and notes (which if shown, are only comments). However, one can also use body, body_post, head, and head_post in plain XML (with the object variable <html:var>$xml_plain</html:var> set) but they will not have the head/body tags printed (it will simply target the encapsulated block of XML toward the top, top-middle, bottom-middle, or bottom of the document). However, if the type is specified (via the API or a relevant doc_info) in some way as XHTML, it will try to print the tags and any attributes specified (in the case of "head" and "body").</para>
		
		<para>Please note the following important points:</para>

		<itemizedlist>
		<listitem>Doc_info's will be necessary to indicate such things as DTD, html/root, head, body, etc. elements, if you want the doc_raw or <html:var>$add_openclose</html:var> automated addition of tags to mix well with these elements. Otherwise, if you have a doc_raw targeted for the head, for example, and then manually add a &lt;head> tag, the doc_raw content is going to be placed before the head tag, since the script doesn't know to find and move your manually added tags into the right place--i.e., manually-added tags (besides doc_raw and doc_info) will go into a section of the document earmarked for the body.</listitem>
		<listitem>In doc_raws (or in style/script doc_infos with content), in order to have escaping of braces (curly brackets) work within, the target attribute (or script/style attribute for the doc_infos) must be the first attribute.</listitem>
		<listitem>While comments can be turned off via the API for printing within a document, comments (C-style or XML-style depending) are also used automatically to allow the script to identify sections within the external document that it should recreate when <html:var>$rewrite_docraw_on</html:var> is true (and it will leave the rest of the page alone, so that you can manually edit the site-wide file without it being erased later). So if you edit the site-wide file, don't tamper with those comments or the content between the beginning and ending of them! (Also be sure to back-up any manual additions you make just in case the automatic rewriting process goes awry for some reason and overwrites your manual additions).
		</listitem>

		<listitem>Note that some attributes must be escaped in order to work with Smarty: to create a colon, two underscores must be used (e.g., "xml__lang" for "xml:lang") or one underscore for a hyphen (e.g,. "http_accept" for "http-accept")</listitem>
		<listitem>Except for "pi" and "root", one cannot add arbitrary attributes to doc_raw or doc_info--at best they will be ignored. Each doc_info/doc_raw performs a simple kind of validation to check that only those attributes contained within the relevant section of the <html:var>$doc_info_types</html:var> array are produced.</listitem>
		<listitem>As a mnemonic device, all of the doc_raws with content targeted internally (for the head) will generally have the same name as the name of the element or pseudo-element after which they are named (e.g., 'doctype', 'script', 'style', 'comments') whereas those targeted externally will be named with a pseudonym (e.g., 'dtd', 'code', 'css', 'notes'). Some types, such as XSD may not, by their nature, have content targeted interally (e.g., 'xsd').</listitem>
		<listitem>Since SmartyDocB needs to escape curly brackets in order to allow curly brackets to be added unescaped within doc_raw script and style blocks, Smarty variables, Smarty config variables, and Smarty functions (which also use curly brackets), must be escaped with &#x005B;-...-&#x005D;, &#x005B;#...#&#x005D;, or &#x005B;=...=&#x005D;, respectively, if placed within a doc_raw block.  Thus,
		<html:code>{assign var=myvar value="alert('You!');"}
{doc_raw target="code" file="javascript.js" charset="UTF-8" defer="defer"}

&#x005B;-myvar-&#x005D;
alert('Howdy!');
{/doc_raw}</html:code>
		will produce the following in the code:
		
		<html:samp>/* Begin doc_raw documentation.tpl */
alert('You!')
alert('Howdy!');			
/* documentation.tpl end doc_raw */</html:samp>
		</listitem>
		</itemizedlist>
		<sect1>
			<title>"bom" (byte-order mark)</title>

			<para>Note I have added "bom" for "byte-order mark". You will probably not need this unless dealing with UTF-16 (e.g., for documents with mostly Chinese characters). If you do need it, simply use it like in this example: <html:code>{doc_info bom="&amp;#xFEFF;"}</html:code> As with items targeted before the root, to the head, etc., you can't just add the mark to the top of your text because this script places such things as XML declarations, etc. ahead of your own content (unless called by a doc_info, doc_raw, or inserted via the API or automatically).
</para>
		</sect1>
		<sect1>
			<title>"xml"</title>
			<para>
			<html:code>{doc_info xml="1.0" encoding="UTF-8" standalone="yes"}</html:code> produces the following at the top of the document (the value of "xml" turning into a version attribute-value pair):
			<html:samp>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?></html:samp>

			</para>
		</sect1>
		<sect1>
			<title>"robots"</title>
			<para>
			<html:code>{doc_info robots="yes" follow="no" archive="yes"}</html:code> produces the following at the top of the document:
			<html:samp>&lt;?robots index="yes" follow="no" archive="yes"?></html:samp>. See the <link xlink:type="simple" xlink:href="http://www.atrus.org/writings/technical/robots_pi/">official specification</link> for more.
			</para>

		</sect1>
		<sect1>
			<title>"pi" (processing instruction)</title>
			<para>Processing instructions can be added to the top of an XML document. One can use a doc_info with "pi" being set to the prefix, and "_content" defining the raw instruction going within the processing instruction.</para>
			<html:code>{doc_info pi="php" _content="print 'ok';"}</html:code> which produces the following at the top of the document:
			<html:samp>&lt;?php print 'ok';?></html:samp>
			
		<para>A doc_raw can also be used to inject even more content:</para>

		<html:code>{doc_raw target=pi prefix="php"}
		print 3;
		exit;
		{/doc_raw}</html:code>
		
		<para>which produces:</para>
		<html:samp>
		&lt;?php 		print 3;
		exit;

?></html:samp>
		<para>(Note that the above are not regular PHP commands (though they could be designed to be used as such), but rather will show up in the XML document and will be ignored unless the script operates on it.)</para>
		<para>One can also add an indefinite number of pseudo-attributes which will be added as such (looking like real attributes, but not considered as such by the XML parser).</para>

			<html:code>{doc_info pi="execute-this" attr="val"}</html:code>
			<para>which produces:</para>
			<html:samp>&lt;?execute-this attr="val"?></html:samp>
		</sect1>
		<sect1>
			<title>"xsl"</title>
			<para>One can shuffle off parts of a stylesheet (or a whole stylesheet) into external file(s) via an XSL doc_raw. Doc_info can be used to attach an existing stylesheet to the document. By using the pseudo-attribute, "xform", one can also opt to perform a server-side transform for the given stylesheet before sending it out to the user (one must have the PHP5 XSL extension installed).</para>

			<para>Note that I have set the default of XSL types to "text/xsl" for the sake of keeping Explorer happy. However, the standard is supposed to be "application/xml".</para>
			<para>Please note that in using the doc_raw function, a basic prolog and root element is added. If you want to change this (e.g., to add prefixes), you have to manually make the change to <html:var>$xsl_prefixed</html:var> (i.e., via the API).</para>
			<html:code><![CDATA[
{doc_raw target=xsl file="/myfile.xsl" type="text/xsl" title="stylesheet1" media="screen" 
			charset="UTF-8" alternate="no"}
<xsl:template match="/">
<html><body>Test:
	<xsl:apply-templates/>
</body></html>
</xsl:template>
{/doc_raw}
]]>
</html:code>
			<para>will produce:</para>
			<html:samp>&lt;?xml-stylesheet href="/myfile.xsl" type="text/xsl" title="stylesheet1" media="screen" charset="UTF-8" alternate="no"?>

</html:samp>
<para> and a valid XSL file "/myfile.xsl" which includes the contents within this doc_raw.</para>
<para>Please note that if you try to use a relative URL you may have problems, unless the page calling the XSL file is also at the directory specified by <html:var>$site_root_public</html:var></para>
<para>As with other doc_raw's, you can inject additional code into an existing stylesheet by referring to the same file again. For example, we could, in addition to the above doc_raw, add the following:</para>
<html:code><![CDATA[
{doc_raw target=xsl file="/myfile.xsl"}
<xsl:template match="p">
<p><strong><xsl:apply-templates/></strong></p>
</xsl:template>
{/doc_raw}
]]>
</html:code>

<para>If both of the above doc_raws are placed anywhere in the document (assuming they are in the sequential order, or have keys that place them in sequential order), the following will be produced in the external document:</para>
<html:samp>&lt;?xml version="1.0"?>
<![CDATA[
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<!-- Begin doc_raw index.tpl -->
<xsl:template match="/">
<html><body>Test:
	<xsl:apply-templates/>
</body></html>
</xsl:template>
<!-- index.tpl end doc_raw -->

<!-- Begin doc_raw index.tpl -->
<xsl:template match="p">
<p><strong><xsl:apply-templates/></strong></p>
</xsl:template>
</xsl:stylesheet>
<!-- index.tpl end doc_raw -->

]]>
</html:samp>

<para>We don't need to readd any other attributes since they were already defined by the former doc_raw.</para>
		</sect1>
		<sect1>
			<title>"root_pre" (prologue) / "head_post" / "body_post" / "root_post"</title>
			<para>This category of doc_raws allows one to inject generic content into various predefined parts of a document (with the doc_raw being placed anywhere within your template(s)). While the terms such as 'head' and 'body' relate to HTML/XHTML, since no tag or attributes are being created here--only raw content being moved into a specific area--they can also be used within generic XML documents as well. So, in a generic XML document, "head_post" would allow one to shuffle off XML content into what some call the "epilogue": an area after the root, but before other content.</para>
	<para>Any content allowable in that region can be included within the doc_raw:</para>
	<html:code>{doc_raw target=root_pre}

&lt;!-- root pre comments -->
&lt;?my-proc-inst myattr="myval"?>
{/doc_raw}</html:code>
			
	<para>The above will simply move the enclosed contents as is into a section following any doc_raw/doc_info-added XSL stylesheet processing instructions or comments.</para>
	<para>"head_post" gets targeted at the end of the X/HTML head element (if one is being added automatically by <html:var>$add_openclose</html:var> or by a doc_info or doc_raw), "body_post" to the end of an X/HTML body element, while root_post actually posts content entirely after the root element's closing tag (e.g., comments can be legally placed here). One can use "head" or "body" to inject content toward the beginning of these sections (or "root" to target toward after the root for non-XHTML XML documents). One can also optionally create attributes for the latter types--see the relevant section for details.</para>
		</sect1>
		<sect1>
			<title>"notes" / "comments"</title>

			<para>These doc_raws/doc_infos let you have comments added. "Notes" will save the comments to an external file and then optionally reference the file in an X/HT/ML comment added before the doctype (known as being a part of the prolog in XML), whereas "comments" simply places the comments themselves within the document (also before the doctype/in the prolog area).</para>
			<para>
			<html:code>{doc_raw file="notes.txt" target=notes comment_style="c"}
			comment_style c in an external file{/doc_raw}</html:code>
			
			will add the following to 'notes.txt':
			
			<html:samp>/* Begin doc_raw documentation.tpl */
comment_style c in an external file
/* documentation.tpl end doc_raw */</html:samp>
			while:
			
			<html:code>{doc_raw target=comments}
			Comments targeted for the prolog{/doc_raw}</html:code>
			
			will add the following to a comment preceding any DOCTYPE declaration:
			
			<html:samp>&lt;!-- 			Comments targeted for the prolog
			
 --&gt;</html:samp>

			</para>
			
			<para>'comment_style' can currently be set to 'c' (for C-style comments: /*...*/), 'xml' (for XML-style comments: &lt;!----&gt;), or 'none' (though the latter will still print text such as 'Begin doc_raw documentation.tpl' and 'documentation.tpl end doc_raw', albeit without comments).</para>
			
					
			<para>'notes' and 'comments' both accept a 'hide' attribute. For 'notes', if you add the attribute, this will cause the referencing comment to be hidden, even if <html:var>$visible_notes</html:var> is TRUE. You can also hide all of your note references by setting <html:var>$visible_notes</html:var> to FALSE. By hiding the notes through either method, this does not delete or otherwise obscure the file itself--only the reference to it within your X/HT/ML source code. If you absolutely don't want people to have the ability to see your notes, set <html:var>$notes_in_hiddendir</html:var> to TRUE (and be sure that <html:var>$site_root_hidden</html:var> is set to a directory which is not publicly accessible--e.g., in Unix systems, higher in the hierarchy that htdocs or public_html). In such a case, your file will be saved on your file system, off of the web. (While we think it should work fine as intended, we are not responsible for any damages that may occur to you if the script does not work properly at concealing your notes files though, so please use discretion.)</para>

			<para>(For 'comments', adding the 'hide' attribute means you will only be able to see these comments within the template so you'd probably be better off using Smarty's comment features unless you want the ability to quickly toggle the visibility of the given comments.)</para>	
			
			<para>Note that 'comments' (and 'notes') will appear in the document even if <html:var>$comments</html:var> and <html:var>$comments_get</html:var> are set to false.</para>
		</sect1>
		<sect1>
			<title>"xsd" (XML Schema)</title>

			<para>"xsd" doc_raw will shuffle away the contents of an XSD file into an external file (named within the 'file' attribute) and then reference that file as part of the xsi:schemaLocation attribute within the root element of the document ('html' if the document is X/HTML). Additional schemaLocation's can be added via the xsi__schemaLocation attribute. For this to work in plain non-XHTML XML, the 'root' doc_info must be used to set the root element into which the XML Schema referencing information can go.</para>
			<para><html:code><![CDATA[
{doc_raw target=xsd file="xsdfile.xsd" xsi__schemaLocation="schemaloc2.xsd" 
xsi__noNamespaceSchemaLocation="nnsschema.xsd" xmlns__xsi="http://www.w3.org/2001/XMLSchema-instance2"}
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>

<xs:attribute name="zip" type="xs:string"/>

<xs:element name="contact">
 <xs:complexType>
  <xs:sequence>
   <xs:element ref="name"/>
   <xs:element ref="address"/>
   <xs:element ref="city"/>
  </xs:sequence>
  <xs:attribute ref="zip" use="required"/>
 </xs:complexType>
</xs:element>
</xs:schema>{/doc_raw}
]]>
</html:code>
			
			will produce:
	<html:samp><![CDATA[
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://mysites-target-ns.com"
xmlns="http://mysites-ns.com"
elementFormDefault="qualified">
<!-- Begin doc_raw documentation.tpl -->
			<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>

<xs:attribute name="zip" type="xs:string"/>

<xs:element name="contact">
 <xs:complexType>
  <xs:sequence>
   <xs:element ref="name"/>
   <xs:element ref="address"/>
   <xs:element ref="city"/>
  </xs:sequence>
  <xs:attribute ref="zip" use="required"/>
 </xs:complexType>
</xs:element>
</xs:schema>
			<!-- documentation.tpl end doc_raw -->


</xs:schema>
]]>
</html:samp>
			</para>
			<para>Doc_info can create a reference to XSD's (though the 'file' attribute is not used in the doc_info since no file is being created):
			<html:code><![CDATA[
{doc_info xsd=schemaloc2.xsd xsi__noNamespaceSchemaLocation="nnsschema.xsd" xmlns__xsi="http://www.w3.org/2001/XMLSchema-instance"}
]]>
</html:code> gives the following (when used with XHTML--the root element name will of cuorse be different for other languages depending on the document type):

			<html:samp><![CDATA[
<html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance2" xsi:noNamespaceSchemaLocation="nnsschema.xsd"
	xsi:schemaLocation="schemaloc2.xsd">
]]>

</html:samp>
</para>
			<para>Note that 'xmlns__xsi' does not really need to be added to either the doc_info or doc_raw since it is added by default.</para>
		</sect1>
		<sect1>
			<title>"dtd" / "doctype"</title>
			<para>A 'dtd' or 'doctype' doc_raw will add raw document type definition data into an external file or into the internal 'DOCTYPE' within the document, respectively.</para>
			<para>To use a doc_raw DTD or doctype in plain (non-XHTML) XML, you must set the rootnode of the document (through the root attribute here, through having set a 'root' doc_info', or through setting <html:var>$rootnode</html:var> to something other than 'html')--the script doesn't auto-detect a manually added root-node. 
			<html:code><![CDATA[

{doc_raw target="dtd" file="mydtd.dtd" root="contacts"}
<!ELEMENT name (address+)>
{/doc_raw}
]]>

</html:code>
will produce:
<html:samp><![CDATA[
<!DOCTYPE contacts SYSTEM "mydtd.dtd">
]]>
</html:samp> and, in the mydtd.dtd document will be:

<html:samp><![CDATA[
<!-- Begin doc_raw documentation.tpl -->
<!ELEMENT contacts (contact+)>
<!-- documentation.tpl end doc_raw -->



]]>
</html:samp>
			</para>
			<para>To use an internal doctype doc_raw, the following 
			<html:code><![CDATA[

{doc_raw target="doctype"}
<!ELEMENT name (address+)>
{/doc_raw}
]]>
</html:code>
			will create:
			<html:code><![CDATA[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" [
<!ELEMENT name (address+)>


]>
]]>
</html:code>
			</para>
			<para>XHTML 1.1 is assumed if no root has been set.</para>			
			<para>Setting the root on a doctype or dtd doc_raw does not create the root element itself. To create one, use a 'root' doc_info.</para>
			<para>To add a SYSTEM or PUBLIC identifier, add it under the attribute "type" (e.g., <html:code>type=public</html:code>) and its file(s) under "subtype" (e.g., <html:code>subtype='publicid" "localdtd.dtd'</html:code>--notice how the subtype can allow two quoted files if both are surrounded by apostrophes instead of quotation marks).</para>

			<para>Note that entities added through these doc_raws can be transformed server-side into their appropriate values if <html:var>$entity_replaces</html:var> is set to TRUE.</para>
		</sect1>		
		<sect1>
			<title>"entity"</title>
			<para>Entities are probably the most complicated feature of SmartyDocB but could be helpful for those wishing to have their site easily translated into other languages.</para>
			<para>Due to poor browser support, however, and due to the fact that many of the features this function offers can be easily replaced by Smarty functions such as 'include' or 'capture', this function might only really be useful at the present time when the translation features are used and server-side conversion features are turned on--or for those writing XML for off of the web. Still, the fact that the files are saved externally and based on a standard (XML) does offer the opportunity for better reusability in other systems (as well as transparent sharing of your site's data to your users).</para>

			<para>Entities are used by XML (including XHTML) to allow a user to define their own symbols (within an internal doctype or external DTD file) which, when referenced within the document, will have their text automatically substituted with the designated replacement text. They are defined like this: 
			<html:code><![CDATA[
<!ENTITY asymbol "replacement text">
]]>
</html:code>
			One can then refer to the symbol by adding an ampersand in front of it and a semicolon after it (e.g., <html:code><![CDATA[
&asymbol;
]]>
</html:code>). This will insert the phrase "replacement text" wherever this symbol is thus placed (though entities cannot be placed inside of tags, except within attribute values). 
			</para>
			<para>If you use the symbols in place of each piece of translatable text in your document and place these symbols and their translated values in separate files--with each file having the symbols translated differently according to the language being employed, you can then have the script optionally attach the appropriate DTD so that the page will be translated into the desired language. The conversion will usually be done by the visitor's browser, but for those users whose browsers can't support entities (support for entities in external files is especially poor now--even Firefox doesn't support them), SmartyDocB can perform the conversions (as well as the selective attachment of DTD's) server-side.</para>
			<para>While you could just add the entities via the 'doctype' or 'dtd' doc_raw functions, the 'entity' doc_raw offers special features not possible with these functions. The 'entity' doc_raw can also be used to create external entity files and add content to them.</para>
			<para>External parameter entities/External DTD subsets can also be created with this doc_raw, though due to a lack of support of external entities in many browsers, this function may have little use now for web use of SmartyDocB. In addition, bug https://bugzilla.mozilla.org/show_bug.cgi?id=267350 of Firefox, instantiating this will not only not work in Firefox, but cause subsequent references, etc. in the internal doctype to be ignored; for Firefox as of now (1/29/2007).</para>

			<para>The following will create the contents of the following doc_raw as an external parameter entity file (i.e., allow inclusion of reusable DTD data (that will become a subset of the current DTD) from an external file):
			<html:code><![CDATA[
{doc_raw target="entity" param=true name="insertme" type="SYSTEM" file="subset.dtd"}
<!ELEMENT myelement (#PCDATA)>
{/doc_raw}
]]>
</html:code>
			will create the doc_raw's contents in the file subset.dtd:

			<html:samp><![CDATA[
<?xml version="1.0"?>
<!-- Begin doc_raw documentation.tpl -->
<!ELEMENT myelement (#PCDATA)>
<!-- documentation.tpl end doc_raw -->
]]>
</html:samp>

			and add a reference to the created (or edited) file inside of the internal doctype:
			<html:samp><![CDATA[
<!ENTITY % insertme SYSTEM "subset.dtd">
%insertme;

]]>
</html:samp>
			</para>
			<para>The following will create the contents of the following doc_raw as an external general entity file (i.e., allow inclusion of its contents in the document via a symbol) from an external file):
			<html:code><![CDATA[
{doc_raw target="entity" name="insertent" type="SYSTEM" file="extgenent.xml"}
<p>hey guys</p>
{/doc_raw}
]]>

</html:code>
			will create the following within extgenent.xml:
			<html:samp><![CDATA[
<?xml version="1.0"?>
<!-- Begin doc_raw documentation.tpl -->
<p>hey guys</p>
<!-- documentation.tpl end doc_raw -->

]]>
</html:samp>
			and add this reference to that file within the internal DOCTYPE:
			<html:samp><![CDATA[
<!ENTITY insertent SYSTEM "extgenent.xml">

]]>
</html:samp>
			</para>
			<para>Thus, the document will now include <html:samp><![CDATA[
<p>hey guys</p>
]]>
</html:samp> wherever the symbol <![CDATA[
&insertent;
]]>

 is used.</para>
			<para>If no file is specified (but a name and type are present), the content will be added to the main site's entity file. If the document root is 'html', <html:var>$dr_entity_file_src</html:var> will be set by default to "/html.xml" (i.e., the root element's name plus '.xml' located at the root directory.</para>
			<para>Unlike in XInclude, external parsed general entity references must themselves resolve into well-formed XML when included within the document without depending on other entities to do things such as close tags started within the entity (also, unlike in XInclude, there is no means of including portions of a document or including documents which themselves contain a DOCTYPE, etc.). Also, unlike internal entities, they cannot be used inside of attribute values.</para>
			<para>An external unparsed entity can also be created (along with a NOTATION declaration)--i.e., to include non-XML data, though again browser support may be quite lacking:
			<html:code><![CDATA[
{doc_info entity="insertme3" type="SYSTEM" file="publicstuff7.xml" ndata="gif" notation_type="system" notation="image/gif"}
]]>
</html:code>
			will create the following within the internal doctype:
			<html:samp><![CDATA[
<!ENTITY insertme3 SYSTEM "mypicture.gif" NDATA gif>
<!NOTATION gif SYSTEM "image/gif">
]]>

</html:samp>
			</para>
			<para>Besides not working in browsers, there is also no standard defined for the notation identifiers and their contents. However, if there is a PUBLIC type, one can use the subtype attribute to define the locations of the definitions.</para>
			<para>If no file and no name attributes are present, the 'entity' doc_raw will simply be treated as a 'doctype' doc_raw (i.e., its contents such as raw entity declarations will be sent to the internal doctype).</para>
			<para>As far as localization, the 'entity' doc_raw also allows items to be added in a tab-delimited fashion so that multiple translations can be added for a page in one place. The first item in a row will become the name of the entity while each subsequent column's data will represent the entity value (i.e., a translation). If no file attribute is set, then the entity declarations will be added to the internal doctype--only for the column called by a GET request, or the second column if there are only two columns.</para>
			<para>If a file attribute is set (with a pipe-delimited list of files in the same order as the data columns), each column's data will be saved into its own file (e.g., for reuse) but only one file will be referenced, according to a GET request (again, if there is more than one column--otherwise the second column will automatically be chosen).
			<html:code>{doc_raw target=entity file=en.ent|zh.ent|fr.ent}
hello	hi	ni hao	salut;
goodbye	bye	zai jian	au revoir
{/doc_raw}</html:code>

			<html:samp><![CDATA[
<?xml version="1.0"?>
<!-- Begin doc_raw documentation.tpl -->
<!ENTITY hello "hi">
<!ENTITY goodbye "bye">
<!-- documentation.tpl end doc_raw -->
]]>
</html:samp>
			 If English is chosen (see below how this is done), the value will be referenced as follows:
			<html:samp><![CDATA[
<!ENTITY % ents SYSTEM "en.ent">
%ents;

]]>
</html:samp>

			An alternative is to set the file attribute to 'defaults' and then the files chosen will be those set in the pipe-delimited (i.e., delimited by the "|" character) <html:var>$entity_files</html:var>:
			
			<html:code>{doc_raw target=entity file=defaults}
hello	hi	ni hao	salut;
goodbye	bye	zai jian	au revoir
{/doc_raw}</html:code>
			</para>
			<para>As shown above, the external file that is chosen will be referenced via an external parameter entity (with the default name of this parameter entity specified by <html:var>$parsed_ent_name</html:var>). Since there is poor browser support for external entities, one may instead wish to avoid the use of a file attribute entirely (unless server-side replacement of entities is performed--see below), except to have the entity files saved (e.g,. for sharing, reusing).</para> 
			<para><html:var>$noextparams</html:var> can be set to true (the default) in order to avoid external parameter entities from printing at all. This could be set to false if more browsers start supporting external (parameter) entity references (currently Firefox has a bug even printing one let alone using it) or if one simply wanted to generate the XML for non-web purposes; server-side replacement can still take place if this is set to true (see below).</para>

			<para>However, the use of external files (targeted to the same localization files across your templates) is potentially quite helpful as it allows one's localization data to be saved all together for one site but with the localization data being placeable in various templates (e.g., in the context in which they will first or most prominently appear). When server-side replacement of entities takes place (see below), the entity file that is currently being used will be read in its entirety, so any manually-added changes to that language's entity file will be available to the current document.</para>
			<para>The GET request has the same name as the first item in a space-delimited list defined by <html:var>$getentparams</html:var>. Subsequent items in the list will represent the GET value that will trigger that numbered column's localization data. The given localization files (which can be localization targets of other templates too) to which the data should be saved should be in the same pipe-delimited (i.e., delimited by the "|" character) sequence in <html:var>$entity_files</html:var>.</para>
			
			<para>For example, given this doc_raw:
			<html:code>{doc_raw target=entity file=en.ent|zh.ent|fr.ent}
hello	hi	ni hao	salut;
goodbye	bye	zai jian	au revoir
{/doc_raw}</html:code>
			if <html:var>$getentparams</html:var> is "langu en zh fr" then if the GET request is "?langu=zh", the 3rd column of tab-delimited data will be the value of each entity.</para>

			<para>Thus, the entities in use with this GET request would be:

			<html:samp><![CDATA[
<!ENTITY hello "ni hao">
<!ENTITY goodbye "zai jian">
]]>
</html:samp>
			and they would be saved to the 2nd column of the file data (since there is no need for the first item in the files list to represent the GET request name nor to represent the entity symbol name): i.e., here, to 'zh.ent'. And, the entity file would thus be referenced by:
			<html:samp><![CDATA[
<!ENTITY % ents SYSTEM "zh.ent">
%ents;

]]>
</html:samp>
			</para>
			<para>Again, if there are no GET requests sent or set, the 2nd column of data will be used.</para>
			<para>Server-side replacement of these entities (as well as those added via a 'doctype' or 'dtd' doc_raw, via a non-tab-delimited 'entity' doc_raw, or also by any entities which were manually-added) can be performed for the sake of browsers that do not support entities (especially ones in external files) by setting <html:var>$entity_replace</html:var> to TRUE. Even if <html:var>$noextparams</html:var> is set to TRUE, parameter entity references won't be printed out at all, though server-side transformations can still take place.
			</para>

		</sect1>

		<sect1>
			<title>"root"</title>
			<para>Note that if using a root doc_info, it can have any attributes, though 'xsi__schemaLocation' and 'xsi__noNamespaceSchemaLocation', if used, will be allocated in such a way as to meld with any doc_info or doc_raw 'xsd's (and will auto-create xmlns:xsi if not specified). Other common attributes for generic root tags might include prefixed namespaces, but remember to use "__" instead of ":", however, and also use '_' in place of '-' within your attribute names--this is for the sake of Smarty's function parsing).</para>
			<para>
			<html:code>{doc_info root="purchase-orders" myattr="75" anotheratt="June 2003" xsi__schemaLocation="schema.xsd" 
	xsi__noNamespaceSchemaLocation="nns.xsd" xmlns="http://example.com/mynamespace"</html:code>
			will produce:
			<html:samp><![CDATA[
<purchase-orders xmlns="http://example.com/mynamespace" myattr="75" anotheratt="June 2003"
	xsi:noNamespaceSchemaLocation="nns.xsd" xsi:schemaLocation="schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
]]>

</html:samp>
			</para>
			<para>The value of the root attribute will also change the root reference within a DOCTYPE, if one has been set.</para>
		</sect1>
		
		<sect1>
			<title>"script" / "code"</title>
			<para><html:strong>Notes</html:strong>: The "script" doc_raw or doc_info will create a script tag in the head of the document. The 'script' attribute (for doc_infos) or 'target' (for doc_raws) should be the first attribute.</para>

			<para>Note that the script at present allows a global variable <html:var>$langu</html:var> to influence the script name. The purpose of this is so that scripts can also be localized (e.g., if you have an alert of text to display tot he user).</para>
			
			<para><html:strong>Required attributes</html:strong>: <html:em>Script</html:em>: (doc_raw content or doc_info 'script'); <html:em>Code</html:em>: (doc_raw content or doc_info 'code')</para>
			<para><html:strong>Optional attributes</html:strong>: type, charset, defer</para>

			<para><html:strong>Default attributes</html:strong>: type="text/javascript"</para>

			<para>
			<html:code>{doc_info script="alert('Hi!');" type="text/javascript" charset="UTF-8" defer="defer"}</html:code>
			will produce			
			<html:samp>&lt;script type="text/javascript" charset="UTF-8" defer="defer">
	&lt;!--//-->&lt;![CDATA[//>&lt;!--
alert('Hi!');
	//-->&lt;!]]&gt;&lt;/script></html:samp>

			</para>
			<para>The following will produce the same results as above:
			<html:code>{doc_raw target="script" type="text/javascript" charset="UTF-8" defer="defer"}
alert('Hi!');
{/doc_raw}</html:code>
			</para>
			<para>'code' (whether as a doc_info or doc_raw) will create a reference to an external javascript file (as opposed to putting the code itself in the head):
			<html:code>{doc_info code="http://example.com/javascript.js" type="text/javascript" charset="UTF-8" defer="defer"}</html:code>
			will produce:
			<html:samp><![CDATA[
<script type="text/javascript" defer="defer" charset="UTF-8" src="http://example.com/javascript.js"></script>
]]>
</html:samp>
			</para>

			<para>
			The doc_raw for 'code' will additionally add the content to the designated file (whether the file designated in the 'file' attribute or, if there is no file attribute, in <html:var>$this->dr_code_file</html:var>):	
			<html:code>{doc_raw target="code" file="javascript.js" charset="UTF-8" defer="defer"}
alert('Howdy!');			
{/doc_raw}</html:code>
			will produce:
			<html:samp><![CDATA[
<script src="javascript.js" type="text/javascript" defer="defer" charset="UTF-8"></script>
]]>
</html:samp>
			and create the following within javascript.js:
			<html:samp>/* Begin doc_raw documentation.tpl */
alert('Howdy!');			
/* documentation.tpl end doc_raw */</html:samp>
			</para>

			<para>Note that for those new to XHTML-treated-fully-as-XML, when serving files as application/xhtml+xml (attempted if the <html:var>$xml_plain</html:var> attribute is true and the file is specified as XHTML) it is recommended to avoid inline scripts/styles.</para>
		</sect1>
		<sect1>
			<title>"style" / "css"</title>

			<para><html:strong>Notes</html:strong>: The "style" doc_raw or doc_info will create a style tag in the head of the document. The 'style' attribute (for doc_infos) or 'target' (for doc_raws) should be the first attribute. The "css" doc_raw or doc_info will create an external stylesheet reference whose implementation will depend on whether the mode is XHTML/XML or not (see below).</para>

			<para>In style or css doc_raws or in style doc_infos, in order to have escaping of braces (curly brackets) work within, the target attribute (or style attribute for the style doc_info) must be the first attribute.</para>
		<para>Since SmartyDocB needs to escape curly brackets in order to allow curly brackets to be added unescaped within doc_raw style blocks, Smarty variables, Smarty config variables, and Smarty functions (which also use curly brackets), must be escaped with &#x005B;-...-&#x005D;, &#x005B;#...#&#x005D;, or &#x005B;=...=&#x005D;, respectively, if placed within a doc_raw block.  Thus,
		<html:code>{assign var=blue value="color:blue;"}
{doc_raw target="css" file="mycss.css"}
p {&#x005B;-blue-&#x005D;}
{/doc_raw}</html:code>
		will produce the following in mycss.css:

		<html:samp>/* Begin doc_raw documentation.tpl */
p {color:blue;}
/* documentation.tpl end doc_raw */</html:samp>

			</para>
			<para><html:strong>Required attributes</html:strong>: For doc_info 'style' or 'css', the 'style' or 'css' attribute is required, for doc_raw 'style' or 'css', target must be equal to 'style' or 'css'</para>
			
			<para><html:strong>Optional attributes in HTML</html:strong>: 
rel', 'id', 'class', 'dir', 'lang', 'style', 'xml__lang', 'type', 'target', 'rev', 'hreflang', 'media', 'charset', 'title
</para>
			<para><html:strong>Optional attributes in XML/XHTML</html:strong>: 
type', 'media', 'title', 'lang', 'xml__lang'</para>

			<para>Note that for those new to XHTML-treated-fully-as-XML, when serving files as application/xhtml+xml (attempted if the <html:var>$xml_plain</html:var> attribute is true and the file is specified as XHTML) it is recommended to avoid inline scripts/styles. However, there is a <link xlink:type="simple" xlink:href="http://www.w3.org/TR/xhtml1/#C_14">convention to reference the inline style tag</link> via an id attribute:
			
				<html:code>{doc_raw target=style id="toc"}
div.toc {color:green;}
span.toc {color:orange;}
{/doc_raw}</html:code>

				will produce:
				<html:samp><![CDATA[
<?xml-stylesheet href="#toc" type="text/css"?>
]]>
</html:samp>
				and
				<html:samp>&lt;style type="text/css" id="toc">
&lt;!--/*-->&lt;![CDATA[/*>&lt;!--*/
div.toc {color:green;}
span.toc {color:orange;}
/*]]&gt;*/-->&lt;/style></html:samp>
			</para>
			<para>If no 'id' is present on any doc_raw or doc_info-added style tag when in (non-text/html) XML/XHTML mode, one will be auto-created in both the xml-stylesheet instruction and on the style tag (the id having the prefix, 'style_tag_id' followed by an incrementing number). Thus,
		
			<html:code>{doc_info style="div.toc {color:green;}
span.toc {color:orange;}"}</html:code>

			will produce:
			<html:samp><![CDATA[
<?xml-stylesheet href="#style_tag_id1" type="text/css"?>
]]>
</html:samp>
				and
			<html:samp>&lt;style type="text/css" id="style_tag_id1">
&lt;!--/*-->&lt;![CDATA[/*>&lt;!--*/
div.toc {color:green;}
span.toc {color:orange;}
/*]]&gt;*/-->&lt;/style></html:samp>
			
			</para>

			<para>The CSS doc_info and doc_raw, when in XML/XHTML mode, will reference an external xml-stylesheet with type 'text/css'. Thus,
			
			<html:code>{doc_info css="mycss.css"}</html:code>

			will produce the following (including the 'type' and 'media' defaults which can be overridden):
<html:samp><![CDATA[
<?xml-stylesheet href="mycss.css" type="text/css" media="screen"?>
]]>
</html:samp>
			</para>
			<para>
			The CSS doc_raw will also first save its enclosed contents to the file to be referenced. If no file attribute is provided, the site-wide styles file defined by <html:var>$dr_css_file_src</html:var> will be used.
			<html:code>{doc_raw target=css}
div.header {font-weight:bold;}
{/doc_raw}</html:code>
			will, in XHTML/XML mode, produce the following in the document:
			<html:samp><![CDATA[
<?xml-stylesheet href="/dr_mainstyles.css" type="text/css" media="screen"?>
]]>

</html:samp>

			and save the following to the main stylesheet:
			<html:samp>/* Begin doc_raw documentation.tpl */
div.header {font-weight:bold;}
/* documentation.tpl end doc_raw */</html:samp>
			</para>
			
			<para>
			If XHTML/XML mode is not on (i.e., regular HTML mode where <html:var>$xml_plain</html:var> is not set) and there is an "external" attribute set to true:
				<html:code>{doc_info css="mycss.css" external=true}</html:code>

				will produce:
				<html:samp><![CDATA[
<link rel="stylesheet" type="text/css" media="screen" href="mycss.css" />
]]>
</html:samp>
			</para>
			<para>
			If XHTML/XML mode is not on (i.e., regular HTML mode where <html:var>$xml_plain</html:var> is not set) and there is no "external" attribute set to true:
				<html:code>{doc_info css="mycss.css"}</html:code>
				will produce:
				<html:samp>&lt;style type="text/css" media="screen">

&lt;!--/*-->&lt;![CDATA[/*>&lt;!--*/
@import "mycss.css";
/*]]&gt;*/-->&lt;/style></html:samp>
			</para>
		</sect1>
		<sect1>
			<title>"html"</title>
			<para>A doc_info 'html' will insert an HTML tag with any specified attributes.</para>

			<para>The standard xmlns for XHTML will be added by default for XHTML when <html:var>$xml_plain</html:var> is TRUE.</para>
			<para>The 'v' attribute is not printed, but is rather a shortcut to represent the XHTML version in use. If XHTML is not specified by any other means, this attribute will also be used to flag the document as XHTML (e.g., for setting the content type). It will also let an appropriate XHTML doctype be created if not specified by a dtd doc_info.</para>
			<para>
			<html:code>{doc_info html="ar" xsi__schemaLocation="schemaloc.xsd"
	xsi__noNamespaceSchemaLocation="nnsschema.xsd" id="htmlid" dir="rtl" lang="ar"}</html:code>
			will produce
			<html:samp><![CDATA[
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" lang="ar" id="htmlid" xml:lang="ar"
	xsi:noNamespaceSchemaLocation="nnsschema.xsd" xsi:schemaLocation="schemaloc.xsd" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...
</html>
]]>

</html:samp>
			</para>
			<para>The XML Schema attributes can also be created through an XSD doc_info or doc_raw.</para>
		</sect1>
		<sect1>
			<title>"head"</title>
			<para>A doc_info or doc_raw 'head' will create a head element with its specified attributes. A doc_raw 'head' will also add content immediately after the head tag (as can a doc_info which includes content within the "head" attribute. To independently add head content toward the end of the head, use 'head_post'.</para>
			<para>

			<html:code>{doc_info head="&lt;!-- head content here -->" profile="http://purl.org/net/ns/metaprof" id="thehead" dir="rtl" xml__lang="fa" lang="fa"}</html:code>
			will produce:
			<html:samp><![CDATA[
<head profile="http://purl.org/net/ns/metaprof" dir="rtl" xml:lang="fa" lang="fa" id="thehead">
<!-- head content here -->
....
</head>
]]>
</html:samp>
			</para>
		</sect1>
		<sect1>
			<title>"meta"</title>

			<para>
				The meta attribute in a doc_info is converted into the 'content' attribute:
				<html:code>{doc_info meta="23-05-1844" name="date" scheme="Europe"}</html:code>
				gives:
				<html:samp><![CDATA[
<meta scheme="Europe" name="23-05-1844" />
]]>
</html:samp>
			</para>
			<para>
				When the content value is set to "http_accept", the http-accept type will be automatically inserted according to content negotiation and an encoding will be added according to the setting of <html:var>$charset</html:var> (default is UTF-8):
				<html:code>{doc_info meta="http_accept" http_equiv="content-type"}</html:code>

			gives:
				<html:samp><![CDATA[
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
]]>
</html:samp>
			</para>
			<para> Or:
				<html:code>{doc_info meta="Brett Zamir" name="author" id="author1" lang="en" xml__lang="en"}</html:code>
			gives:
<html:samp><![CDATA[
<meta name="Brett Zamir" id="author1" lang="en" xml:lang="en" />
]]>
</html:samp>
			</para>

			<para>Instead of using this meta tag for "robots" instructions, one should use the 'robots' doc_info, as this can also serve the appropriate XML processing instruction when serving as application/xhtml+xml.</para>
		</sect1>
		<sect1>
			<title>"title"</title>
			<para>Produces an (X)HTML "title" tag. Doc_info-only. Internal-only.</para>
			<para><html:strong>Notes</html:strong>: As with all doc_infos (and doc_raws), it can be placed anywhere in the document, though it will end up in the 'head' (as it should be).</para>

			<para><html:strong>Required attributes</html:strong>: title (its value becomes the title element's content)</para>
			<para><html:strong>Optional attributes</html:strong>: lang (HTML or  XHTML &lt;= version 1.0), xml__lang (XHTML only), dir, id</para>
			<para><html:strong>Example:</html:strong>
				<html:code>{doc_info title="My page title" dir="ltr" lang="en" xml__lang="en"}</html:code> will create the following in the head of the document:
				<html:samp><![CDATA[
<title dir="ltr" lang="en" xml:lang="en">My page title</title>
]]>

</html:samp>
				(Note that the "lang" attribute is not used in XHTML 1.1 as xml:lang should be used to replace it. When using earlier versions of XHTML, it can be kept alongside xml:lang or by itself.)
			</para>
		</sect1>
		<sect1>
			<title>"base"</title>
			<para><html:strong>Required attributes</html:strong>: href ('base' translates into "href" for doc_infos)</para>
			<para><html:strong>Optional attributes</html:strong>: target, id</para>

			<para><html:strong>Example:</html:strong>
			<html:code>{doc_info base="http://example.com" target="_top" id="baseid"}</html:code> 
			will create the following in the head of the document:
			<html:samp><![CDATA[
<base target="_top" id="baseid" href="http://example.com" />
]]>
</html:samp>
			</para>
		</sect1>
		<sect1>
			<title>"link"</title>

			<para><html:strong>Notes</html:strong>: When the 'link' attribute is set, it will translate into 'href'.</para>
			<para><html:strong>Optional attributes</html:strong>: 'rel', 'id', 'class', 'dir', 'lang', 'style', 'xml__lang', 'type', 'rev', 'media', 'hreflang', 'charset', 'title', 'xml__space', 'target', 'onclick', 'ondblclick', 'onmousedown', 'onmouseup', 'onmouseover', 'onmousemove', 'onmouseout', 'onkeypress', 'onkeydown', 'onkeyup'</para>
			<para><html:strong>Example:</html:strong>
			<html:code>{doc_info link="http://example.com" rel="next"}</html:code> 
			will create the following in the head of the document:
			<html:samp><![CDATA[
<link rel="next" href="http://example.com" />
]]>
</html:samp>

			</para>
			<para>Note that a link will also be created if the content type is 'text/html' and the 'css' doc_raw is used (or doc_info if 'external' pseudo-attribute is set to TRUE). (If it is 'css' and the type is 'application/xhtml+xml', an xml-stylesheet will be created instead--see the 'css' doc_raw/doc_info section for details.)</para>
		</sect1>
		<sect1>
			<title>"body" (or the "epilog" for plain XML)</title>
			<para><html:strong>Notes</html:strong>: The 'body' doc_raw and doc_info will create attributes for the 'body' element. The 'body' doc_raw will also be able to shuffle off content immediately after the body element. (To target content toward the end of the body, use 'body_post' instead.</para>
			<para>The 'body' attribute of a doc_info will become the 'onload' attribute of the resulting 'body' element.</para>

			<para><html:strong>Optional attributes</html:strong>: 'onload', 'id', 'class', 'lang', 'dir', 'xml__lang', 'title', 'style', 'onunload', 'onclick', 'ondblclick', 'onmousedown', 'onmouseup', 'onmouseover', 'onmousemove', 'onmouseout', 'onkeypress', 'onkeydown', 'onkeyup', 'xml__space', 'bgcolor', 'background', 'text', 'link', 'vlink', 'alink'</para>
			
			<para><html:code>{doc_info body="alert('Hello!')"}</html:code>
			will create the following in the head of the document:
			<html:samp><![CDATA[
<body onload="alert('Hello!')">
]]>
</html:samp></para>
			<para>If the script detects that you have set <html:var>$xml_plain</html:var> to TRUE or that you have set the document type to XHTML (via <html:var>$application_xml</html:var> being set to 'XHTML', via a doc_info 'dtd' being set to 'XHTML', or via setting the 'v' attribute of the 'html' doc_info to an XHTML version number), the body element itself will not be created but the content will be injected in the body area. Thus:
			<html:code>{doc_raw target=body"}
Content to go to the beginning of the body
{/doc_raw}</html:code>

			will simply add the following (without any 'body' element) towards the top of the document (though after any doctype, head-targeted content, etc.):
			<html:samp>Content to go to the beginning of the body</html:samp>
			</para>
		</sect1>	
	</chapter>
	
	<chapter>
		<title>Public API</title>
		<para>For now, you will need to look at the code to see how to use the public API functions and set the public class member variables. However, the most important variables have already been described in the set-up section of this document (or possibly the read-me). The code can also be examined through our <link xlink:type="simple" xlink:href="htmllib/index.html">PHPDocumentor-generated files</link>.</para>

		<!--
		<sect1>
			<title>no_prefilter()</title>
			<para>Note that the prefilter with regexps can be unregistered with a simple call to $smarty->no_prefilter(); some heavy regular expressions can be avoided.</para>
		</sect1>
		-->
	</chapter>
	<chapter>
		<title>Miscellaneous</title>
		<sect1>
			<title>Tag/tagc</title>
			<para>While the shuffling of content in SmartyDocB generally occurs one whole block at a time (as through doc_raw's), the tag/tagc functions also enable one to have style data shuffled away to the head of the document or to an external file while the style assignment itself is attached to just a single tag.</para>

			<para>This allows a person to replicate the functionality of the now-deprecrated "style" attribute in XHTML without it showing up in the source code as such. However, it goes beyond the "style" attribute in that one can decide how to treat it--whether to add the style information to the stylesheet using the element's id, or to reuse that style by assigning the style to a whole element and/or class.</para>
			<para>These functions (which can appear similar to a regular XML tag) allow for more portability, since, to make changes, one does not need, for example, to change the class name in both the head and in the document when making a class name change. And, this offers the ability to place the styles exactly where you are really using them (or where you first use them)--directly within such an element. This will thus allow you to both visualize your data with your desired styles, but let the data also be reused, and take advantage of the other benefits of external stylesheets--e.g., browser caching.</para>
			<para>Tagc functions only differ in working as a block function in which content can be placed targeted for within the element (thus 'c' for 'content'). The tag function can also include content within it, but through the attribute '_con' being set to the content (as an attribute, it is thus intended for small amounts of content).</para>
			<para>Either function can allow the element name to be set with an attribute, 'e' (for producing an entire element--opening and closing tags), 'o' (for just an opening tag), 'sc' (for a self-closing tag), or 'c' (for the closing tag). If content is added in the case of 'o' or 'sc', it will simply follow the generated element, rather than being enclosed within it. Thus for 'o', one will need to manually supply a closing tag later in the page.</para>
			<para>Any of the following:</para>
			<html:code><![CDATA[
{tagc e=h4}test{/tagc}

{tagc o=h4}test{/tagc}</h4>

{tagc o=h4}test{/tagc}{tagc c=h4} {/tagc}

{tag o=h4 _con="test"}{tag c=h4}

{tag e=h4 _con="test"}

]]>

</html:code>
			<para>... will thus produce:</para>
			<html:samp><![CDATA[
<h4>test</h4>
]]>
</html:samp>
			<para>(Note: there must be at least a space in the tagc (or doc_raw) functions to get processed at all--however, as long as something is there, a tagc with a 'c' (close tag) attribute will have its contents ignored anyways (it is probably easier to instead use a tag function or enclose all contents within a tagc with an 'e' attribute).)</para>
			<para>For self-closing tags, the following:</para>
<html:code><![CDATA[
{tagc sc=br}test2{/tagc}

{tag sc=br}test2

]]>
</html:code>
<para> will each produce:</para>

<html:samp><![CDATA[
<br />test2
]]>
</html:samp>
			<para>However, since it is clearly a bit cumbersome to need to write out any of the above choices just to produce one tag or element, there is a shorthand syntax available for the tag and tagc functions.</para>
			<para>This shorthand syntax is specified by <html:var>$left_tagcdelim</html:var>, <html:var>$right_tagcdelim</html:var>, <html:var>$left_tagcclose</html:var>, and <html:var>$right_tagcclose</html:var> for the tagc function (by default, '&lt;&lt;', '&gt;&gt;', '&lt;&lt;/', and '&gt;&gt;' respectively) and <html:var>$left_tagdelim</html:var>, <html:var>$right_tagdelim</html:var>, and <html:var>$right_tagdelim2</html:var> for the tag function (by default, '&#x007B;&#x007B;', '&#x007D;&#x007D;', and '/&#x007D;&#x007D;', respectively). In the former case (tagc), the shorthand will always produce the 'e' attribute (since you probably wish to use a block function to enclose content between tags) while for the latter (tag), the shorthand will always produce the 'sc' (self-closing) attribute (since you don't want to enclose any content).</para>

			<para>Thus, the following tagc function</para>
			<html:code>{tagc e=h2 style="color:green;"}heading{/tagc}</html:code>
			<para>can, by default, be represented by:</para>
			<html:code>&lt;&lt;h2 style="color:green;"&gt;&gt;heading&lt;&lt;/h2&gt;&gt;</html:code>
			<para>producing:</para>

			<html:samp><![CDATA[
<h2 style="color:green;">heading</h2>
]]>
</html:samp>
			<para>whereas, the following tag function</para>
			<html:code>{tag sc=br style="clear:both;"}</html:code>
			<para>can, by default, be represented by:</para>
			<html:code>&#x007B;&#x007B;br style="clear:both;"&#x007D;&#x007D; OR
&#x007B;&#x007B;br style="clear:both;"/&#x007D;&#x007D;</html:code>

			<para>producing:</para>
			<html:samp><![CDATA[
<br style="clear:both;"/>
]]>
</html:samp>
			
			<para>All of the above, however, does nothing to demonstrate why we are using the functions in the first place--for shuffling off styles.</para>
			<para>You can instead use the estyle, eclstyle, clstyle, or istyle attributes to shuffle away the style into the head, or use ecss, eclcss, clcss, or icss to shuffle off into an external file (use the 'file' attribute if you want to specify a file other than the default site-wide file specified by <html:var>$dr_css_file_src</html:var>). The prefixes refer to how the style will be referenced--whether by element ('e'), by element and class ('ecl'), by class alone ('cl'), or by id ('i'). For example,
			</para>
			<html:code>&lt;&lt;h2 estyle="color:blue;"&gt;&gt;heading&lt;&lt;/h2&gt;&gt;</html:code>

			<para>will produce:</para>
			<html:samp>&lt;h2>heading&lt;/h2>

AND

&lt;style type="text/css">
&lt;!--/*-->&lt;![CDATA[/*>&lt;!--*/
h2 {color:blue;}
/*]]&gt;*/-->&lt;/style></html:samp>

			<para>An id or class will even be auto-created (using the default prefix of "id" or "cl", respectively) if no id or class were specified. For example:</para>

			<html:code>&lt;&lt;h2 clstyle="color:green;"&gt;&gt;heading&lt;&lt;/h2&gt;&gt;</html:code>
			<para>will produce:</para>
			<html:samp>&lt;h2 class="cl1">heading&lt;/h2>

AND

&lt;style type="text/css">
&lt;!--/*-->&lt;![CDATA[/*>&lt;!--*/
.cl1 {color:green;}
/*]]&gt;*/-->&lt;/style></html:samp>

			<para>To offer an external file equivalent example:</para>

<html:code>&lt;&lt;h2 file="mycss.css" clcss="color:green;"&gt;&gt;heading&lt;&lt;/h2&gt;&gt;</html:code>
			<para>will produce:</para>
			<html:samp>&lt;h2 class="cl1">heading&lt;/h2>

and save the following in mycss.css:

.cl1 {color:green;}
</html:samp>

			<para>As mentioned above, if the class had been specified, then that would be reflected in the style reference instead of the automated variety:</para>

<html:code>&lt;&lt;h2 file="mycss.css" class="myclass" clcss="color:green;"&gt;&gt;heading&lt;&lt;/h2&gt;&gt;</html:code>
			<para>will produce:</para>
			<html:samp>&lt;h2>heading&lt;/h2>

and save the following in mycss.css:

.myclass {color:green;}
</html:samp>

			<para>For even greater portability, you can set <html:var>$styles_to_css</html:var> to TRUE and just use the "style" attribute, and the id of the element will be relied upon (or an id will be auto-created) in order to create an appropriate reference in the external stylesheet as when using an "icss" attribute. This attribute will also convert the other head-targeted style attributes (e.g., "clstyle") into their corresponding "css" (external file) counterparts.</para>

			<para>'pseudo' can be used to specify a CSS pseudo-attribute to be added along with the class:</para>
			<html:code>&lt;&lt;a href="test.html" pseudo="visited" clcss="color:green;"&gt;&gt;link&lt;&lt;/a&gt;&gt;</html:code>
			<para>will produce:</para>
			<html:samp>&lt;a href="test.html" class="cl1">link&lt;/a>

.cl1:visited {color:green;}
</html:samp>
			<para>'Key' has been reserved for possibly allowing overwriting, but this feature is not so far been implemented.</para>

			<para>Tagc/tag functions can also process any attributes not otherwise reserved by the function (useful if you want to write plain XML but with styles).
			</para>
			
		</sect1>
		
		<sect1>
			<title>XSL functions</title>
			<para>SmartyDocB comes packaged with some XSL functions that can be used to transform XML documents server-side and then include the resulting content within the template. Note that these only provide the results of a transformation of some XML and XSL strings or files which are independent of the current document and thus do not actually create an xml-stylesheet processing instruction for the output. To transform the entire document instead, see the XSL section under doc_raw.</para>
			<para>One can use the XSL variable modifier to transform an XML document in any of the following manners:</para>
			<html:code>{$xmlfilename|xsl:$xslfilename}</html:code>

			<html:code>{$xmlfilename|xsl:'xslfile.xsl'}</html:code>
			<html:code>{$xmlfilename|xsl:$xslstring}</html:code>
			<html:code>{$xmlstring|xsl:$xslfilename}</html:code>
			<html:code>{$xmlstring|xsl:'xslfile.xsl'}</html:code>
			<html:code>{$xmlstring|xsl:$xslstring}</html:code>
			
			<para>This modifier is also available using the XML variable modifier to transform an XML document with the given XSL stylesheet (starting instead with the XSL file):</para>

			<html:code>{$xslfilename|xml:$xmlfilename}</html:code>
			<html:code>{$xslfilename|xml:'xmlfile.xml'}</html:code>
			<html:code>{$xslfilename|xml:$xmlstring}</html:code>
			<html:code>{$xslstring|xml:$xmlfilename}</html:code>
			<html:code>{$xslstring|xml:'xmlfile.xml'}</html:code>
			<html:code>{$xslstring|xml:$xmlstring}</html:code>

			<para>The XSLT function (so-named so as to avoid a name-conflict with the XSL block function below), works similarly to the variable modifiers:</para>
			<html:code>{xslt xml=$xml xsl=$xsl}</html:code>
			<para>However, the XSLT function can also accept a number of attributes which may be useful, for example, if one does not wish to tamper with the source XML or XSL files to change prefixes and namespaces:</para>
			<html:code>{xslt xml=$xml xsl=$xsl prefix="svg" xmlns="http://www.w3.org/2000/svg" xsisl="http://www.w3.org/2000/svg svg.xsd"}</html:code>
			<para>The "xsisl" attribute represents schemaLocations which will be added to the root of the document (if one were specified by an 'xsd' doc_raw/doc_info or 'html'/'root' doc_info).</para>
			<para>The use of a single prefix attribute (i.e., not space delimited) will both manually add the prefix with its specified namespace (xmlns) to the root element as well as add the prefix (with a colon) to every element in the XSL output. The above might be useful if your XSL stylesheet is bare of the prefix you want to add to the current document (and if you don't want to tamper with the stylesheet itself):</para>

			
			<html:code><![CDATA[
{capture assign=xml}
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg:svg width="100%" height="100%" version="1.1" xmlns:svg="http://www.w3.org/2000/svg">
<svg:circle cx="80" cy="100" r="60" stroke="red" stroke-width="4" fill="blue"/>
</svg:svg>
{/capture}

{capture assign=xsl}
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svg="http://www.w3.org/2000/svg">
<xsl:output method="xml" version="1.0"/>
<xsl:template match="/">
<xsl:apply-templates select="//svg:circle"/>
</xsl:template>
<xsl:template match="svg:circle">
<svg>
<xsl:element name="circle">
<xsl:attribute name="cx"><xsl:value-of select="@cx"/></xsl:attribute>
<xsl:attribute name="cy"><xsl:value-of select="@cy"/></xsl:attribute>
<xsl:attribute name="r"><xsl:value-of select="5*@r"/></xsl:attribute>
</xsl:element>
</svg>
</xsl:template>
</xsl:stylesheet>
{/capture}
]]>
</html:code>

			<para>The prefix attribute can also allow space-delimited additional prefixes (with corresponding space-delimited xmlns') to be added to the root, but in such a case, the prefix will not be force-added to the result.</para>
			<para>If you wanted to manually add a namespace for a single prefix, but didn't wanted to force add the prefix to all of the resulting elements (e.g., in case the XSL doesn't itself add a namespace to the included element for some reason), you can add a blank space at the end of the prefix attribute value: <html:code>prefix="svg "</html:code></para>			
			<para>If on the other hand, we have an XML document without the necessary prefixed namespace on its elements (assuming they have all one same namespace) to match the namespace expected by the XSL stylesheet, we can set the "preadd" attribute to true. So, if, for example, we used a stylesheet again, but with the namespaced prefixes, and had this time a source document without the prefix needed by the stylesheet, e.g.: </para>
			<html:code><![CDATA[
{capture assign=xml}
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1">
<circle cx="80" cy="100" r="60" stroke="red" stroke-width="4" fill="blue"/>
</svg>
{/capture}

{capture assign=xsl}
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svg="http://www.w3.org/2000/svg">
<xsl:output method="xml" version="1.0"/>
<xsl:template match="/">
<xsl:apply-templates select="//svg:circle"/>
</xsl:template>
<xsl:template match="svg:circle">
<svg:svg>
<xsl:element name="svg:circle">
<xsl:attribute name="cx"><xsl:value-of select="@cx"/></xsl:attribute>
<xsl:attribute name="cy"><xsl:value-of select="@cy"/></xsl:attribute>
<xsl:attribute name="r"><xsl:value-of select="5*@r"/></xsl:attribute>
</xsl:element>
</svg:svg>
</xsl:template>
</xsl:stylesheet>
{/capture}
]]>
</html:code>
			<para>... we could set the "preadd" attribute to true: So, using <html:code>{xslt xml=$xml xsl=$xsl preadd="true" prefix="svg" xmlns="http://www.w3.org/2000/svg"}</html:code> against the previous XML code would work as intended.</para>

		<para>Note that the above will only work if there is one prefix being added. If additional prefixes (i.e., additional spaces) are present, the pre-addition of a prefix will not take place.</para>
		
		<para>Lastly, there is an "xsl" block function which contains raw XSL and references an XML file (and, if you prefer, an "xml" block function which can contain raw XML while referencing an XSL file). To attach to the same <html:var>$xml</html:var> file as above (or to assign $xml to a file containing the XML (SVG) in question).</para>
<html:code><![CDATA[

{xsl xml=$xml}
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svg="http://www.w3.org/2000/svg">
<xsl:output method="xml" version="1.0"/>
<xsl:template match="/">
<xsl:apply-templates select="//svg:circle"/>
</xsl:template>
<xsl:template match="svg:circle">
<svg:svg>
<xsl:element name="svg:circle">
<xsl:attribute name="cx"><xsl:value-of select="@cx"/></xsl:attribute>
<xsl:attribute name="cy"><xsl:value-of select="@cy"/></xsl:attribute>
<xsl:attribute name="r"><xsl:value-of select="5*@r"/></xsl:attribute>
</xsl:element>
</svg:svg>
</xsl:template>
</xsl:stylesheet>
{/xsl}

]]>
</html:code>
		<para>These functions can also accept the same attributes as above for prefix, xmlns, preadd, and xsisl.</para>
		</sect1>
		
		<sect1>

			<title>cdata</title>
			<para>This block function will simply enclose the included contents within "&lt;![CDATA[" and "]]&gt;". CDATA is used by XML to allow one to avoid the need to escape characters such as &lt; or &amp; which normally have another meaning to XML and as such would otherwise need to have each instance escaped (e.g., all &lt; coded as &amp;lt; and &amp; as &amp;amp;). Within CDATA sections, no such escaping is necessary. These sections cannot be used within a tag, however (e.g., they cannot be used to escape text within attributes).</para>

			<html:code>{cdata}x > y &amp;&amp; z &lt; 5{/cdata}</html:code>
			<para>produces the XML-safe:</para>
			<html:samp>&lt;![CDATA[
x > y &amp;&amp; z &lt; 5
]]&gt;</html:samp>

			<para>This is nothing fancy but is probably easier to remember than directly typing the CDATA construct.</para>
		</sect1>
		
		<sect1>
			<title>XInclude</title>
			<para>By using this function, any encapsulated data will be saved directly into another file. Unlike the externally targeted doc_raw functions, this file will rewrite the entire file, so be sure that you are writing to the correct file and that you want to replace its existing contents.</para>
			<html:code>{xinclude href="myinc.xml" parse=xml xpointer="//inc-element" 
   encoding="UTF-8" accept="application/xml" accept_language=en}
...some file contents...
{/xinclude}</html:code>
			<para>will produce:</para>

			<html:samp><![CDATA[
<xi:include href="myinc.xml" parse="xml" xpointer="//inc-element" 
   encoding="UTF-8" accept="application/xml" accept-language="en"/>
]]>
</html:samp>
			<para>and will write the encapsulated contents to the specified file, using <html:var>$site_public_root_dir</html:var> for the base.</para>
			<para>The attribute "file" can also be used in place of "href" (the result will be the same).</para>
			<para>By using this function, the XInclude namespace will also be added to the root element of the document.</para>
			<para>Please note that at the time of this writing, XInclude is not yet supported by any major browser (including Firefox), so at this time, the function will probably be of minimal use.</para>

		</sect1>
		
		<sect1>
			<title>Content Type</title>
			<para>If <html:var>$xml_plain</html:var> is set to true, SmartyDocB attempts to perform "content negotiation" in order to serve the user a MIME Type header which his or her browser can process. If the user has set the type of the document as 'XHTML', whether through a DTD.... <html:code>{doc_info dtd="XHTML"}</html:code> or through the SmartyDocB shortcut "v" (note this is not printed as "v" anywhere in the output, it is just a shorthand for adding the XHTML version information):<html:code>{doc_info html="" v="1.1"}</html:code>, it will first try to serve as type 'application/xhtml+xml', and if this doesn't work, then it will try to serve it as 'application/xml' or 'text/xml'. If these fail, then it will serve 'text/html'.</para>

			<para>If <html:var>$xml_plain</html:var> is set to TRUE and <html:var>$application_xml</html:var> has also been set to true (instead of to 'XHTML' or to FALSE)--i.e., if plain non-XHTML XML is intended, then the content type 'application/xml' will be served. If <html:var>$xml_plain</html:var> is set to TRUE but <html:var>$application_xml</html:var> is FALSE, then 'text/xml' will be served.</para>
			<para>And lastly, if <html:var>$xml_plain</html:var> is set to FALSE (the default), then 'text/html' will be served.</para>

			<para>Note that for those new to XHTML-treated-fully-as-XML, it is recommended when serving files as application/xhtml+xml (attempted if the <html:var>$xml_plain</html:var> attribute is true and the file is specified as XHTML) it is recommended to avoid inline scripts/styles.</para>
		</sect1>
		
		<sect1>
			<title>Tidy</title>
			<para>If one has the Tidy extension installed, one can choose to Tidy the output (usually from HTML to well-formed XHTML). Set <html:var>$tidy_on</html:var> to true to do so.</para>

			<para><html:var>$tidy_for_xslt</html:var>, when set to TRUE (the default), will cause the document to be automatically tidied before performing any doc_raw XSL server-side transforms, even if <html:var>$tidy_on</html:var> is set to FALSE. This is especially useful if one is serving one's XHTML as text/html (and as a result well-formedness errors could be creeping by you as they may be ignored by the browser), but where one must transform into valid XHTML in order to be able to perform a server-side transform.</para>
			<para>If the document is genuine plain XML (<html:var>$xml_plain</html:var> is TRUE and the document has not been defined as XHTML (via a doc_info dtd or <html:var>$application_xml</html:var> being set to 'XHTML')), then the Tidy output will be tidied as XML as opposed to the default as XHTML.</para>
		</sect1>

		<sect1>
			<title>mobile phones</title>
			<para><html:var>$auto_xform_mobile</html:var>, when set to TRUE, will attempt to detect the browser type of the user, and if it is detected as a mobile phone type, the script will server-side transform your XHTML document into XHTML Basic, so that more cell phones can read it. Note that XHTML Basic does not allow nested tables as well as some other less commonly used XHTML elements (it also allows an "inputmode" attribute (for 'input' and 'textarea' elements) that regular XHTML does not use by default: see the <link xlink:type="simple" xlink:href="http://www.w3.org/TR/xhtml-basic/">XHTML Basic specification</link>).</para>
			<para>There are two methods by which you can auto-detect browser type: via a <link xlink:type="simple" xlink:href="http://garetjax.info/projects/browscap/">Browscap class</link>, or via <link xlink:type="simple" xlink:href="http://browsers.garykeith.com/downloads.asp">Browscap in the ini</link>. The former is useful if you are in a shared host setting and don't have access to the php.ini file.</para>

			<para>If you are using the class, <html:var>Browscap_file</html:var> should point to the Browscap class file that you must require while <html:var>Browscap_cache_dir</html:var> should point to your Browscap's cache directory.</para>
			<para>If a file location is set for 'browscap' in your php.ini file (this is not present in PHP by default) and you have this above-mentioned <link xlink:type="simple" xlink:href="http://browsers.garykeith.com/downloads.asp">PHP version</link> of the up-to-date browscap file, browser detection and transformation into XHTML Basic can also be performed (I haven't been able to test this latter feature, however, to be sure).</para>
		</sect1>

		
		<sect1>
			<title>gzipped output</title>
			<para>If the browser will support it and if <html:var>$gzip_output</html:var> is set to TRUE, PHP will use 'ob_gzhandler' with output buffering (ob_start) to compress the output when sent to the user's browser. If the ZLib extension is installed (and <html:var>zlib.output_compression</html:var> is set in the php.ini file), PHP's ob_gzhandler will not be called since the extension and PHP will not work correctly together.</para>
		<para>Note however that SmartyDocB does not currently package the files it exports from doc_raws into gzipped form.</para>

		</sect1>

	</chapter>
	
	<chapter>
		<title>FAQ/Trouble-shooting</title>
	
		<qandaset>
			<qandadiv><title>Questions</title>

			<para>Here are some frequently asked questions:</para>

			<qandadiv><title>General questions</title>
		
			<qandaentry>
				<question><para>Why are my HTML head elements showing up inside of the body?</para></question>
				<answer><para>Unless you explicitly paste head elements (e.g., meta, link, etc.) into the head (e.g., via a doc_raw targeted for ), SmartyDocB does not detect that manual additions should be added into the head. Using the automation of </para></answer>
			</qandaentry>
			<qandaentry>
				<question><para>What's the deal with doc_raw and moveto? Which should I use?</para></question>

				<answer><para>For historical reasons, the script uses "doc_raw". However, "moveto" is a more accurate and descriptive term, so that is what is recommended to be used as the block function within templates for encapsulating data that will be shuffled off into the head of the document, into external files, etc. However, the API at present still uses "docraw" or "doc_raw" within the class. For backwards compatibility 'doc_raw' can be added as one of the arguments to the constructor.</para></answer>
			</qandaentry>
		</qandadiv>
		</qandadiv>
	</qandaset>
	</chapter>
	
	<!--
	<index>
		<indexentry>
			<primaryie></primaryie>
			<seeie></seeie>
		</indexentry>
	</index>
	-->





</book>
