<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ryan Morr &#187; XML</title>
	<atom:link href="http://ryanmorr.com/archives/category/xml/feed" rel="self" type="application/rss+xml" />
	<link>http://ryanmorr.com</link>
	<description>JavaScript, CSS, and Web Apps</description>
	<lastBuildDate>Fri, 27 Aug 2010 13:28:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Cross-Browser XML and XSLT Processing</title>
		<link>http://ryanmorr.com/archives/cross-browser-xml-and-xslt-processing</link>
		<comments>http://ryanmorr.com/archives/cross-browser-xml-and-xslt-processing#comments</comments>
		<pubDate>Wed, 07 Jan 2009 05:06:16 +0000</pubDate>
		<dc:creator>Ryan Morr</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://ryanmorr.com/?p=69</guid>
		<description><![CDATA[There is something inherently powerful about what direct data interaction and manipulation is capable of and the ease at which it performs. XSLT may be called a stylesheet but it is nothing like CSS, it deals directly in data management and presentation, utilizing advanced functionality typically reserved for a scripting language. Similar to what Smarty [...]]]></description>
			<content:encoded><![CDATA[<p>There is something inherently powerful about what direct data interaction and manipulation is capable of and the ease at which it performs. XSLT may be called a stylesheet but it is nothing like CSS, it deals directly in data management and presentation, utilizing advanced functionality typically reserved for a scripting language. Similar to what Smarty is to PHP templates, XSLT basically defines the rules for rendering an XML file, with one important distinction &#8211; the data is live. The data is subject to further XSL manipulation after the XML document has been initially transformed, facilitating many dynamic features. This has great implications on the web applications of the future; loading a widget could be as simple as dynamically loading an XML document which contains all settings and instructions, performing an XSLT transformation and appending the result document to the DOM. With those kind of capabilities the potential for such an application is limitless. <span id="more-69"></span></p>
<p>The promise of both XML and XSLT or its greater implications may not be well known but it&#8217;s also not new. For a while now it has been speculated to be the next &#8220;big thing&#8221; in web development, some even went so far as to claim XML would replace HTML as the dominant markup language (I suppose XHTML is the first step, albeit a small one). However, aside from simple data transfer its popularity is far from it&#8217;s anticipated potential due in large part to a lack of browser support. I should however mention some of the great work I&#8217;ve seen out of <a href="http://www.backbase.com/" target="_blank">Backbase</a> with their various UI widgets, but nevertheless XML really hasn&#8217;t caught on the way I hoped it would.</p>
<p>In light of my new found appreciation of XML and XSLT I decided to put a little script together for your basic XML and XSLT importation and manipulation. Hopefully we can get those wheels turning again, maybe one day I can see that potential and not just read about it.</p>
<p>The script itself is fairly lightweight and handles the basic functions associated with XML and XSLT manipulation in Javascript as I&#8217;ve outlined below. If your looking for something a little more full featured, Sarissa is a great option as it can handle just about everything including the kitchen sink, you can find it here; <a href="http://dev.abiss.gr/sarissa/" target="_blank">http://dev.abiss.gr/sarissa/</a>.</p>
<h3>Features</h3>
<ul>
<li>Load local XML and XLST files</li>
<li>Encode and decode an XML string</li>
<li>Serialize an XML string into a document</li>
<li>Parse XML document into a string</li>
<li>Transform an XML file with an XSLT stylesheet and apply to element</li>
<li>Perform an XPath query on an XML document</li>
<li>Supports IE6+, FF, Opera, Safari, and Chrome</li>
<li>No browser detection</li>
</ul>
<h3>Example</h3>
<p>The following example illustrates a simple transformation involving an XML document, XSLT stylesheet, and an element (container) that will house the results of the transformation. See it in action <a href="http://ryanmorr.com/tests/xml/">here</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> processor <span style="color: #000000;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLProcessor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> container <span style="color: #000000;">=</span> document.<span style="color: #006600;">getElementById</span><span style="color: #000000;">&#40;</span><span style="color: #3366CC;">'container'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
processor.<span style="color: #006600;">loadXML</span><span style="color: #000000;">&#40;</span><span style="color: #3366CC;">'xml.xml'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
processor.<span style="color: #006600;">loadXSLT</span><span style="color: #000000;">&#40;</span><span style="color: #3366CC;">'xslt.xsl'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
processor.<span style="color: #006600;">transform</span><span style="color: #000000;">&#40;</span>container<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span></pre></div></div>

<p>The topic of XML and XSLT and their use within a web application deserves its own post, there is a lot more to it then what I&#8217;ve discussed here. For now you can find more information on XML, XSLT, and their various elements and functions at the  <a href="http://www.w3.org/TR/xslt" target="_blank">W3C</a> and <a href="http://www.w3schools.com/xsl/default.asp" target="_blank">W3 Schools</a>, two resources that I referred to in preparation for this article.</p>
<h3>Download</h3>
<ul>
<li><a href="http://ryanmorr.com/modules/xmlprocessor-compressed.js">Compressed (3kb)</a></li>
<li><a href="http://ryanmorr.com/modules/xmlprocessor.js">Fully Documented (6kb)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://ryanmorr.com/archives/cross-browser-xml-and-xslt-processing/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
