<?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>the tar pit &#187; xslt</title>
	<atom:link href="http://blog.goneopen.com/tag/xslt/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.goneopen.com</link>
	<description>Thrashing around in the stickiness of software</description>
	<lastBuildDate>Wed, 25 Aug 2010 10:10:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>JQuery vs XSLT as REST client for XML resource in the browser</title>
		<link>http://blog.goneopen.com/2008/10/jquery-vs-xslt-as-rest-client-for-xml-resource-in-the-browser/</link>
		<comments>http://blog.goneopen.com/2008/10/jquery-vs-xslt-as-rest-client-for-xml-resource-in-the-browser/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 05:50:20 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[jquery]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://blog.goneopen.com/2008/10/jquery-vs-xslt-as-rest-client-for-xml-resource-in-the-browser/</guid>
		<description><![CDATA[This work is to try and help through thinking about XML results through REST in a browser. If we are going to view the results (in a browser) what are the options that treat the results as a GET resource? Here are the sample files. Conclusions: Parsing XML files is a no brainer to display [...]]]></description>
			<content:encoded><![CDATA[<p>This work is to try and help through thinking about <span class="caps">XML </span>results through <span class="caps">REST </span>in a browser. If we are going to view the results (in a browser) what are the options that treat the results as a <span class="caps">GET </span>resource?</p>

<p><a href="http://blog.goneopen.com/wp-content/uploads/2008/10/storyq-results.zip">Here</a> are the sample files.</p>

Conclusions:<br />
<ul>
<blockquote>
	<li>Parsing <span class="caps">XML </span>files is a no brainer to display in <span class="caps">HTML</span></li>
	<li> I&#8217;d probably avoid using the browser&#8217;s xslt engine though &#8211; so xslt through javascript is simplified</li>
</blockquote>
</ul>
<ul>
<blockquote>
	<li> JQuery is central to the real presentation functionality</li>
	<li> I&#8217;d start with option 2 personally and then add XPath as needed to target information and then if this display got more complex add in <span class="caps">XSLT</span></li>
</blockquote>
</ul>
<ul>
<blockquote>
	<li> You can get there either through (1) <span class="caps">XSLT, </span>(2) JQuery itself or (3) JQuery + <span class="caps">XSLT </span>+ XPath &#8211; you really should be familiar with them all anyway</li>
</blockquote>
</ul>
Here&#8217;s a couple of main options:<br />
<ol>
	<li> XML + <span class="caps">XSLT</span>/XPath -&gt; <span class="caps">HTML </span>+ JQuery =&gt; Display</li>
	<li><span class="caps">HTML </span>+ JQuery ++XML =&gt; Display</li>
	<li><span class="caps">HTML </span>+ JQuery +<acronym title="JS">XSLT</acronym> ++XML =&gt; Display</li>
	<li>Flex (+ <span class="caps">HTML</span>) ++XML =&gt; Display</li>
</ol>
I have looked at the first two. And that is what I will try and explain. I suspect the other two options are also good. I do have a concern that in using the <span class="caps">XSLT </span>parser within a JS plugin it is perhaps delegating too much work to JS (maintenance of enough functionality will probably become an issue). Also beyond that I was looking at is the hyperlinking of resources (my hunch is that JS or Flex will be the way to load and traverse hyperlinked resources)

<p>I think that the major concern:</p>


<ul>
<li>is a separation of concerns</li>
<li>keeping a resource as data that can be asked for and can ask for a service to act on it</li>
</ul>



<p>Separation of concerns:</p>


<ol>
<li>The <span class="caps">XML </span>needs to have a life of its own as a resource</li>
<li>The client needs to be able to act on the resource</li>
<li>The client needs to be in control of all of this and don&#8217;t want logic to be hiding at the server</li>
<li>On the client, I want to keep separate layout from content from skin</li>
<li>For development, I wouldn&#8217;t mind some intellisense; I want good debugging help</li>
</ol>



<p>Some findings:</p>


<ul>
<li>One thing to note is that for both approaches I bind a data source to a control. Here I read in <span class="caps">XML </span>and load it into an object and then bind this object to the control which then appends the table to the <span class="caps">DOM </span>object. This control can also be bound to an html table. In this case, you put a table into the <span class="caps">DOM </span>and then the control transforms the table. The later seemed to me to be a server-side solution rather than a late-binding to a resource.</li>
<li>I also did a sample <span class="caps">XSLT </span>of creating table in <span class="caps">HTML </span>from the results (results-as-html-table.xsl). The code was too long for me! I have include that file in the source for reference.<br />
<h2>Option One: <span class="caps">XML </span>+ <span class="caps">XSLT</span></h2><br />
This was my initial reaction as the way forward for this solution. Personally, I like <span class="caps">XSLT </span>and its declarative nature. But, in practice, I still find it a little slow to programme (I really do forget the syntax and have to relearn it each time &#8211; particularly if you start to heavily use namespaces).</li>
</ul>




<ul>
<li>The xslt on a browser has to have a reference to an xsl in the <span class="caps">XML </span>- this really isn&#8217;t that good as there is only one view per xml (although if you were working outside of the browser this need not be a problem)</li>
<li><span class="caps">XML </span>in many ways does act on itself because it puts an <span class="caps">XSLT </span>across it (although limited to one)</li>
<li>It was harder to debug the JS in the xslt mode and generally took longer to working in <span class="caps">XSLT</span></li>
<li>The key thing to remember is that the target platform is <span class="caps">HTML</span>/JS and <span class="caps">XSLT </span>is good for transformations from one structure to another. The problem is that while <span class="caps">XHTML </span>is <span class="caps">XML </span>we are really in a programming mode rather than a transformation mode. I think that the part that is best for the tranformation via XPath is taking the results and combining the bits of information together (that is this case would be in a cell).</li>
<li>I had add extra code to late-bind the data into the control as it wasn&#8217;t designed to be used in this way (you could rewrite the component to reduce code though)</li>
</ul>



In summary, as the transformations got larger, this might still work well. You will need to write a number of xsl files to allow for good modularisation (see DocBook if you have any doubt on this one). In doing, so you can keep alot of the javascript/JQuery work invisible to the main transformations. But I find that really if isn&#8217;t great for debugging so I write the JS in another context and then import it back in to the <span class="caps">XSL </span>file.<br />
<h2>Option Two: <span class="caps">HTML </span>+ JQuery ++XML</h2>
Having looked at the <span class="caps">XSLT </span>work, I was in the land of JQuery and was finding it hard to get good, flowing code from the <span class="caps">HTML</span>/JS perspective. So while what I want to see needs to be parsed declaratively, the way to display and have interactions with it needs to be procedural code.

<p>Note: I had to patch the flexigrid component to allow transforming data from an <span class="caps">XML </span>to <span class="caps">JSON </span>source. It assumes that the resource gotten is the object presented.</p>


<ul>
<li>The <span class="caps">HTML</span>/JS using an html container was quicker and cleaner to write. I was easier to use code samples to then customise and extend.</li>
<li>The browser&#8217;s debugging tools such as Firebug played a little more nicely in terms of error handling</li>
<li>Honestly, this approach took not more than a third of the time</li>
<li>JQuery gives me iterators and finders that makes my code not look dissimilar to the declarative <span class="caps">XSLT </span>(I would also be able to use XPath if I really wanted)</li>
<li>To keep it clean I will tend to use expected modularisation in Javascript (objects/functions)</li>
<li>I&#8217;m not convinced that the end result is necessarily any cleaner though</li>
<li>I will be able to put unit tests around it though</li>
<li>the <span class="caps">HTML </span>file is itself a resource<br />
<h2>Simiarilities</h2></li>
<li>I only need to load the xml once</li>
<li>both use the same libraries</li>
<li>both need to be improved to do a <span class="caps">DTD </span>(xsd) check?</li>
<li>the <span class="caps">REST </span>approach requires that the client transforms the <span class="caps">XML </span>to a format that can be bound to the control<br />
<h2>Where to?</h2></li>
<li>I probably stick with the <span class="caps">HTML </span>approach</li>
<li>I&#8217;d keep extending the JQuery plugin approach which allows for nice configuration of views</li>
<li>I can use either the each iterators with find in JS or use XPath to work out what data I want to (re)present</li>
<li>I would probably add another layer of abstraction between the model object and the data source &#8211; at the moment what required from the data source and format of the binding object are combined. A factory would easily create that separation &#8211; but was too much for this example</li>
<li>Alternatively, I would extend the column model so that you can use XPath configuration of data rather than need the pre processing callback in the first instance</li>
<li>go and look at options 3 and 4 above at some stage (3 is likely to end up as the alternative above)<br />
<h3>Appendix A: Reference Formats of <span class="caps">JSON </span>data format for server</h3><br />
<code>{
page: 1,
total: 239,
rows: [
{id:'ZW',cell:['ZW','ZIMBABWE','Zimbabwe','ZWE','716']},
}</code></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.goneopen.com/2008/10/jquery-vs-xslt-as-rest-client-for-xml-resource-in-the-browser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
