<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Eddie Welker.com &#187; programming</title>
	<atom:link href="http://www.eddiewelker.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eddiewelker.com</link>
	<description>Advanced web development, with a little bit about me thrown in too.</description>
	<lastBuildDate>Thu, 24 Sep 2009 13:37:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Cutting Scheme in Half</title>
		<link>http://www.eddiewelker.com/2009/08/24/cutting-scheme-in-half/</link>
		<comments>http://www.eddiewelker.com/2009/08/24/cutting-scheme-in-half/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 22:50:33 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.eddiewelker.com/?p=256</guid>
		<description><![CDATA[


Apple in Half, by LuLu Witch


The Scheme steering committee has decided to sever the Scheme language into &#8220;Large Scheme&#8221; and &#8220;Small Scheme.&#8221;  Can we expect the same from Scheme-inspired languages like JavaScript?   





]]></description>
			<content:encoded><![CDATA[<div class="mceTemp" style="text-align: left;">
<dl class="wp-caption alignright">
<dt class="wp-caption-dt"><a href="http://www.flickr.com/photos/lucy_baxter/3326839642/"><img title="Apple in Half" src="http://farm4.static.flickr.com/3331/3326839642_e7ee335dcc_m.jpg" alt="Apple in Half, by a href=" width=" mce_href=" height="180" /></a></dt>
<dd class="wp-caption-dd">Apple in Half, by <a href="http://www.flickr.com/photos/lucy_baxter/">LuLu Witch</a></dd>
</dl>
</div>
<p style="text-align: left;">The Scheme steering committee has decided to <a href="http://scheme-reports.org/2009/position-statement.html">sever the Scheme language</a> into &#8220;Large Scheme&#8221; and &#8220;Small Scheme.&#8221;  Can we expect the same from Scheme-inspired languages like JavaScript?  <img src='http://www.eddiewelker.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://www.eddiewelker.com/2009/08/24/cutting-scheme-in-half/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check-in</title>
		<link>http://www.eddiewelker.com/2009/08/03/check-in/</link>
		<comments>http://www.eddiewelker.com/2009/08/03/check-in/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 02:42:19 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[bikes]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[me]]></category>
		<category><![CDATA[photography]]></category>
		<category><![CDATA[pubmed]]></category>
		<category><![CDATA[summer]]></category>

		<guid isPermaLink="false">http://www.eddiewelker.com/?p=247</guid>
		<description><![CDATA[Not a technical post, but a personal update.  I promised over a week ago.]]></description>
			<content:encoded><![CDATA[<p>Not a technical post, but a personal update.  I promised over a week ago. <a title="Air Me by eddie.welker, on Flickr" href="http://www.flickr.com/photos/ed_welker/3753939045/"><img class="alignright" style="border: 0pt none; margin-left: 1em; margin-bottom: 1em;" src="http://farm4.static.flickr.com/3494/3753939045_227dd6b275_m.jpg" alt="Air Me" width="240" height="240" /></a></p>
<p>I&#8217;ve been exceptionally busy at work, we&#8217;re beginning to finish up a much needed, <a href="http://www.library.drexel.edu/blogs/drexelbioscience/?tag=nih">much</a> <a href="http://laikaspoetnik.wordpress.com/2009/04/01/pubmed-changes-at-the-front-door/">discussed</a> by <a href="http://eagledawg.blogspot.com/2009/05/pubmed-update-now-online-now-share-your.html">librarians</a>, redesign of <a href="http://pubmed.gov">PubMed</a>.  We&#8217;ve put a ton of user interaction effort into this project, as well as a good sprinkling of graphic design (watch out, I even did some parts!)  I think people will be really positive about these new changes.</p>
<p>[Just for the record, if someone happens to stumble upon this from the librarian community, yes, release date is still end of summer, and yes, there will be a Beta period, so no need to worry about a short timeline to update your class or instructional slides.  We do listen!]</p>
<p>It&#8217;s also been exciting that we&#8217;ve brought a few new people on board.  Always exciting to have new hires, despite the fact that it&#8217;s a lot of work&#8230; and all of the trainings I have to do.</p>
<p>What else&#8230;  I&#8217;m planning on attending the <a href="http://delvenyc.com/">DelveUI masterclasses</a> this week in Brooklyn.  It will be interesting to see what some of the heads of state have to say about the field.  I&#8217;m a little excited, this masterclass format isn&#8217;t the usual boring no-content fluff that you hear at most conferences. I get the feeling that there will actually be code present!  My thanks to the lovely <a href="http://www.sushiandrobots.com/journal/2009/07/25/free-ticket-to-delveui-in-nyc-help-me-plan-my-talk">Jina &#8220;Sushi &amp; Robots&#8221; Bolton</a> for the opportunity for the free ticket.</p>
<p>I&#8217;ve been reading&#8230; way too many things.  I&#8217;ve been reading <a href="http://www.packtpub.com/learning-jquery-1.3/book">Learning jQuery 1.3</a>, <a href="http://www.packtpub.com/user-interface-library-for-jquery/book">jQuery UI 1.6</a>, and <a href="http://www.amazon.com/gp/product/1933988355?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1933988355">jQuery in Action</a> and you&#8217;ll see the reviews of those two books very soon.  (Can you tell that we&#8217;ve switched to jQuery at NCBI?)  I&#8217;m a little behind with that reading, but I&#8217;ve been working hard on other things.  Additionally, I went on an Amazon spree, and started reading <a href="http://www.amazon.com/gp/product/0596153813?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0596153813">Programming the Semantic Web</a>, <a href="http://www.amazon.com/gp/product/0954300653?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0954300653">An Introduction to Lambda Calculi for Computer Scientists</a>, <a href="http://www.amazon.com/gp/product/0192801422?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0192801422">To Mock a Mockingbird</a>, <a href="http://www.amazon.com/gp/product/0262062666?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0262062666">101 Things I learned in Architecture School</a>, <a href="http://www.amazon.com/gp/product/0735619670?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0735619670">Code Complete 2</a>.   Last but not least, I&#8217;ve also been reading any photography book that I can get my hands on.</p>
<p>Yes, that is a lot of books, and I haven&#8217;t had much time for them.  I&#8217;ve been working hard at work, and I want to relax a bit when I come home.  Once summer ends, things will return to a slightly more regular pace.  I&#8217;ve been learning so much on the job, that I&#8217;m not very worried about falling behind in reading.</p>
<p>It&#8217;s the summer, so I have been riding&#8230; not a ton, but some.  I wish I had time to do more, but I don&#8217;t have time for everything.  I have been taking long-ish 7 mile rides home, and then going out to play some basketball with my roommates.  That&#8217;s a good time.  As soon as I finish this post, I am going to go and fix my fixie&#8230; <a href="http://www.flickr.com/photos/ed_welker/499906278/">my favorite Bianchi</a>&#8230; I somehow mashed the pedals hard enough to shear off part of the thread of both the crank and the pedal, so there go the original cranks and some lovely <a href="http://sheldonbrown.com/harris/pedals.html#platform">MKS Sylvan Track Pedals</a> that were on there. I&#8217;ve got a new, generic replacement crankset and new Sylvan&#8217;s.  Also, I&#8217;m moving from a 42&#215;15 to a 46&#215;17, but with the change in crank length (172.5 down to 165mm) I&#8217;ll have the same gear ratio as before.  I&#8217;m interested in seeing how the shorter cranks feel.</p>
<p>Not to mention <a href="http://www.letour.fr/us/homepage_horscourseTDF.html">le Tour</a> this year&#8230; I was captivated.</p>
<p><a title="Fish by eddie.welker, on Flickr" href="http://www.flickr.com/photos/ed_welker/3686013626/"><img class="alignright" style="border: 0pt none; margin: 1em 0em 1em 1em;" src="http://farm3.static.flickr.com/2670/3686013626_b14883b58f_m.jpg" alt="Fish" width="160" height="240" /></a>And then <a href="http://www.flickr.com/photos/ed_welker/">I&#8217;ve been taking some photos</a>.  Still have been good on my New Year&#8217;s resolution of taking a photo every day&#8230; with the exception of Jan 20 (yes, Inauguration Day, the day more people in my Washington DC area took photos than any other this year).</p>
<p>I also got an iPhone.  While <a href="http://www.flickr.com/photos/ed_welker/sets/72157620701884345/">I was in California</a> for <a href="http://www.flickr.com/photos/ed_welker/sets/72157620771003449/">Joel and Olga&#8217;s wedding</a>, I dropped my phone of more than 5 years on a rug, and the antenna that had been barely holding on for a few months finally fell off completely.  I had previously told myself that I would try to wait until my phone broke before getting a new one. So I was going to buy one at the first sight of antenna problems, until it was suggested that I wait for a new version.  Well, my phone&#8217;s demise and the new version&#8217;s release coincided, so now I have a 3GS.  Really the thing I like most is having my calendar with me at all times.  The only other part I really like is the speaker, so I can listen to music while on my bike for the first time.</p>
<p>Alright, so that&#8217;s about that for the moment. Go out and do something summer-y, that&#8217;s what I&#8217;m doing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eddiewelker.com/2009/08/03/check-in/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorry</title>
		<link>http://www.eddiewelker.com/2009/07/23/sorry/</link>
		<comments>http://www.eddiewelker.com/2009/07/23/sorry/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 04:42:12 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.eddiewelker.com/2009/07/23/sorry/</guid>
		<description><![CDATA[I&#8217;ve been&#8230; not away, but simply taking pictures. I should get back to writing&#8230; more JavaScript (to refresh myself), more XLST, a little Django/Python here or there.  I&#8217;ll do that soon.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been&#8230; not away, but simply taking pictures. I should get back to writing&#8230; more JavaScript (to refresh myself), more XLST, a little Django/Python here or there.  I&#8217;ll do that soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eddiewelker.com/2009/07/23/sorry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review of &#8220;Prototype-Based Programming&#8221;</title>
		<link>http://www.eddiewelker.com/2009/01/29/review-of-prototype-based-programming/</link>
		<comments>http://www.eddiewelker.com/2009/01/29/review-of-prototype-based-programming/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 01:14:56 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[books]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[prototypal]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.eddiewelker.com/?p=232</guid>
		<description><![CDATA[
I ran across a mention of &#8220;Prototype-Based Programming&#8221; back when I was first learning JavaScript.  I thought it would be an interesting read, but forgot to bookmark it, and forgot to look into it further.  Once I finally remembered it, it proved hard to find (and an expensive gamble from Amazon), until I found it [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-235 alignleft" style="margin-right: 10px; margin-bottom: 10px;" title="Prototype-Based Programming" src="http://www.eddiewelker.com/wp-content/uploads/2009/01/prototypebasedprogramming.png" alt="Prototype-Based Programming" width="225" height="356" /></p>
<p>I ran across a mention of &#8220;Prototype-Based Programming&#8221; back when I was first learning JavaScript.  I thought it would be an interesting read, but forgot to bookmark it, and forgot to look into it further.  Once I finally remembered it, it proved hard to find (and an expensive gamble from Amazon), until I found it through NIH&#8217;s interlibrary loan system.</p>
<p>I was quite excited to get my hands on a copy of this book, I was interested in learning more about the general theory that went into languages with prototypal inheritance.  I thought this would allow me a special insight into JavaScript.  However, as I found reading it&#8230; despite it&#8217;s 1999 publication date, JavaScript wasn&#8217;t even mentioned in the book!  Regardless, I found parts of it to be quite interesting and insightful.</p>
<p>The book is broken up into three sections (as mentioned on the cover), Concepts, Languages, and Applications.  Each section has 4 associated chapters which are really various papers, some of which seem to be difficult to find elsewhere.</p>
<p>The first section, &#8220;Concepts&#8221; was the most interesting. The first was titled &#8220;Classes vs. Prototypes: Some Philosophical and Historical Observations.&#8221;  This chapter provided a nice introduction to the topic, including the history of classification, going back to Aristotle and proceeding to Ludwig Wittgenstein who had an interesting example about classifying the characteristics of an item as simple as a &#8220;game&#8221;.  It goes on to transition to a programming perspective.  A point that is made repeatedly throughout many chapters that the idea of classical inheritance necessitating construction from the top (superclasses) to the bottom (subclasses) is inherently contradictory to the way humans think.  When unfamiliar with a domain, a person can more easily deal with concrete examples, and only discern the abstract general form after discovering these patterns in the concrete cases.  Though unable to put my finger on this idea, I&#8217;ve experienced it a number of times when programming myself, and couldn&#8217;t agree more.</p>
<p>The next chapter, &#8220;Classifying Prototype-based Programming Languages&#8221; sought to categorize the theoritical aspects of different prototypal languages.  This is the chapter where I most missed the reference to JavaScript, but I may look into doing that myself some other day.  &#8220;The Stripetalk Papers: Understandability as a Language Design Issue in Object-Oriented Programming Systems&#8221;, made an argument that prototype based systems could be used to enhance the learnability of languages.  Finally, the chapter &#8220;Classes versus Prototypes in Object-Oriented Languages&#8221; looked at the advantages and disadvantages of class-based and prototype-based languages.  This chapter was quite interesting, however brief.</p>
<p>The second section, &#8220;Languages&#8221;, lacking JavaScript, was less useful than I had hoped.  &#8220;Programming as an Experience: The Inspiration for Self&#8221; was interesting as it described the thought process going into creating the Self language, and expanded some of the ideas presented in the book&#8217;s second chapter.  Alas, I&#8217;ve haven&#8217;t yet gotten around to learning Self, but the ideas and history presented were interesting in the abstract.  &#8220;NewtonScript: Prototypes on the Palm&#8221; was interesting mostly because of it&#8217;s Lisp-like syntax and it&#8217;s description of internal closures, while &#8220;The Prototype-Instance Object Systems in Amulet and Garnet&#8221; took an in-depth look at the implementation of these two languages.  I only skimmed the &#8220;Omega: Statically Typed Prototypes&#8221; chapter, as it was rather brief, and I don&#8217;t feel confident enough (or have any real desire) to enter the static-typed/dynamic-typed languages argument.</p>
<p>The final section, &#8220;Applications&#8221;, was where this book showed it&#8217;s age.  &#8220;Self includes: Smalltalk&#8221; involved translating Smalltalk programs into Self, which is interesting, but I don&#8217;t see much practical application for this today (maybe if you&#8217;re translating Ruby to JavaScript? Not sure).  &#8220;Using Prototypes for Program Restructuring&#8221; demonstrated the use of an algorithm that would help to restructure code into a slot-based prototype system in a application called Guru.  &#8220;Prototype-Based Programming for Abstract Program Visualisation&#8221; ended up being skimmed, because while the topic matter seemed interesting, the demonstrations from the black-and-white mac era looked totally antiquated, and I am sure that they have been written many times in other languages since the writing.  Finally, &#8220;Agora: The Scheme of Object-Orientation, or, the Simplest MOP in the World&#8221; detailed the Agora language, a pure OO language which relied only on objects and message passing, while being implemented as a reflective language inspired by Scheme, of all things. Weird, but interesting.</p>
<p>You know as well as I do that computer technology is a moving target, and something published in 1999 will be outdated to a certain degree.  The good part of this book is that the abstract notions in it are rather timeless, as they have been built on over time.  Parts of this book may be out of date, but parts aren&#8217;t, and regardless, it&#8217;s an interesting read.  I recommend it, if you&#8217;re even slightly interested.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eddiewelker.com/2009/01/29/review-of-prototype-based-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review of &#8220;Expert Python Programming&#8221;</title>
		<link>http://www.eddiewelker.com/2009/01/25/review-of-expert-python-programming/</link>
		<comments>http://www.eddiewelker.com/2009/01/25/review-of-expert-python-programming/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 18:02:24 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[books]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.eddiewelker.com/?p=225</guid>
		<description><![CDATA[
Based on the title, Expert Python Programming, (by Tarek Ziadé) I had expected a book covering the Python language&#8230; syntax, advanced data structures, maybe some functional programming&#8230; stuff like that. This book surprised me.  Rather, it contains a hodgepodge of information about the world of Python development, from setting up editors to distributed version [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.packtpub.com/expert-python-programming/book"><img class="alignleft size-full wp-image-227" style="margin-right: 10px; margin-bottom: 10px;" title="Expert Python Programming" src="http://www.eddiewelker.com/wp-content/uploads/2009/01/expertpythonprogramming.jpg" alt="Expert Python Programming" width="225" height="278" /></a></p>
<p>Based on the title, <a href="http://www.packtpub.com/expert-python-programming/book">Expert Python Programming</a>, (by <a href="http://tarekziade.wordpress.com/">Tarek Ziadé</a>) I had expected a book covering the Python language&#8230; syntax, advanced data structures, maybe some functional programming&#8230; stuff like that. This book surprised me.  Rather, it contains a hodgepodge of information about the world of Python development, from setting up editors to distributed version control to application distribution.  &#8220;Expert Python Programming&#8221; does contain some information on the Python language itself, but not as much as I would have hoped.  While it does contain a good amount of useful information, overall, I&#8217;d have to say that it misses the target.</p>
<p>Quickly summarized, the book contains 3 chapters on package management and distribution, 2 on syntax, 2 on optimization, and one each on language setup, naming conventions (style guide), version control, project management, documentation, test-driven development, and design patterns.  Based on the content, I might have titled this book &#8220;Expert Python Development Practices&#8221;, and think I would have been happier reading it in that case.  The discrepancy between the title and the content is especially bothersome to me, since it would be easy to assume this book focused specifically on programming, rather than code management.</p>
<p>Expert Python Programming&#8217;s greatest asset is the number of tools and utilities that it covers.  As a mostly casual Python programmer, there were a number of things that I learned, especially with regard to  package management and distribution.  I&#8217;ve never needed to build a package, and never used Atomisator or zc.buildout before, so I found these chapters rather interesting (though not personally useful at the moment). To be sure, when I need to use these, this book will the be the first place I come.</p>
<p>I was familiar with a decent amount of the information in the documentation, test-driven development, and style-guide chapters from reading some of the <a href="http://www.python.org/doc/">Python Documentation</a> and a few of the <a href="http://www.python.org/dev/peps/">PEPs (Python Enahncement Proposals)</a>.  These chapters would be good for anyone who doesn&#8217;t want to have to go and search for this information on their own, and I think it would be rather handy to have all of this information in one place.</p>
<p>The weakest part of the book were the chapters focusing on Python itself. The majority wasn&#8217;t anything particularly groundbreaking here that I haven&#8217;t read elsewhere, while the interesting sections, such as &#8220;How Python Deals with Memory&#8221; and &#8220;Multithreading&#8221; were short and not particularly detailed.  The sections on optimization were nice, but limited.</p>
<p>My only other observations were that the Mr. Ziadé at times made statements of opinions that he presented as fact.  I would have preferred him presenting code as evidence towards these opinions and leaving the reader to decide for themselves.  To be fair, these moments were infrequent enough that they weren&#8217;t that bothersome.</p>
<p>Through no fault of the author, <a href="http://www.packtpub.com/">Packt Publishing</a> did let a number of small editorial mistakes slip through.  Additionally, I found myself often wanting a better presentation of code samples. The overall design of the code examples and body text of the book ended up being quite similar, and I wish that they had made a bigger differential between the two.</p>
<p>Personally, I was disappointed that the Expert Python Programming&#8217;s didn&#8217;t feature aspects about the language as prominently as the everything else.   I can only recommend that any potential buyers of this book borrow a copy, or make a trip to the local bookstore to flip through it first.  Otherwise, this may not be the book that you were looking for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eddiewelker.com/2009/01/25/review-of-expert-python-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My XSLT Toolbox &#8211; 5 Favorite XSLT Books</title>
		<link>http://www.eddiewelker.com/2009/01/08/top-5-xslt-books/</link>
		<comments>http://www.eddiewelker.com/2009/01/08/top-5-xslt-books/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 04:42:00 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[xslt]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://www.eddiewelker.com/?p=214</guid>
		<description><![CDATA[I love reading programming books, especially to learn a new programming language.  Learning XSLT, I read a large number of books, as there are quite a few available.  The quality of the XSLT books struck me as particularly all over the place, some were quite good while others weren&#8217;t even worth the time to skim.  [...]]]></description>
			<content:encoded><![CDATA[<p>I love reading programming books, especially to learn a new programming language.  Learning XSLT, I read a large number of books, as there are quite a few available.  The quality of the XSLT books struck me as particularly all over the place, some were quite good while others weren&#8217;t even worth the time to skim.  So I&#8217;m throwing together a simple list of my current collection of XSLT references, which happened to be my favorites of the bunch.   These books are all geared towards specific audiences&#8230; beginners, advanced, etc, so I included their audiences.</p>
<ul>
<li><strong><a href="http://www.amazon.com/gp/product/0596000537?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596000537">XSLT &#8211; Mastering XML Transformations</a>, Doug Tidwell</strong><br />
This is my favorite XSLT book.  Mr. Tidwell did a great job of combining an introduction to the language, a tutorial on how to write XSLTs, and a reference all into one book.  On top of that, I found it to be written in the clearest, most conversational style I&#8217;ve found in many a programming book.  I find this book covers 90% of my day-to-day needs, and when I forget how something works, this book usually answers my questions.  (Plus, hey, you can get the 1.0 version for about $3 used.)</li>
<li><strong><a href="http://www.amazon.com/gp/product/0470192747?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0470192747">XSLT: Programmer&#8217;s Reference</a>, Michael Kay</strong><br />
If Mr. Tidwell&#8217;s book covers 90%, this book covers all 100%, and then some.  Mr. Kay (who wrote the Saxon processor, if you weren&#8217;t aware) presents what amounts to an annotated specification in book form.  One of my co-workers calls this book the XSLT dictionary, and I can&#8217;t argue with that.  This book is probably best for advanced programmers.</li>
<li><strong><a href="http://www.amazon.com/gp/product/0764547763?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0764547763">XSLT and XPATH on the Edge</a>, Jeni Tennison</strong><br />
Once you&#8217;ve got the basics of the language down, you&#8217;ve got to use it to write real-world code.  I found this book helps to smooth down the rough edges of working with the language.  This book requires a mid-level familiarity with the language.</li>
<li><strong><a href="http://www.amazon.com/gp/product/0596009747?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596009747">XSLT Cookbook, Second Edition</a>, Salvatore Mangano</strong><br />
I reach for this book whenever I&#8217;ve got to do something weird.  I use it to find the solution to some odd edge case, or for my &#8220;can I do this with XSLT&#8221; questions.  The book covers everything from faking regular expressions, to set operations on different node-sets, to functional programming with XSLT.  I don&#8217;t use it often, but it&#8217;s like gold when I do.  This book is mostly for advanced users.</li>
<li><strong><a href="http://www.amazon.com/gp/product/0596002912?ie=UTF8&amp;tag=eddwelsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596002912">XPath and XPointer</a>, John E. Simpson</strong><br />
The content in this book is totally covered in each of the other books, and it isn&#8217;t really XSLT, because it only covers XPath.  But this book is my simple reference to 90% of the XPath questions I have.  It is a nice little book that I could live without, but it certainly makes my life easier having it around.  I think new users will likely get the most out of this book. (Another book that can be had for about $3 used.)</li>
</ul>
<p>(For disclosure, I did make the links amazon referrals. I feel kinda weird, but figured why not. I don&#8217;t expect any results, but if I got some, it&#8217;d go straight to buying a new book.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eddiewelker.com/2009/01/08/top-5-xslt-books/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My XSLT Toolbox &#8211; Recursive XSLT templates</title>
		<link>http://www.eddiewelker.com/2008/12/28/recursive-xslt-templates/</link>
		<comments>http://www.eddiewelker.com/2008/12/28/recursive-xslt-templates/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 21:21:35 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[xslt]]></category>
		<category><![CDATA[exslt]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[tokenize]]></category>
		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://www.eddiewelker.com/?p=199</guid>
		<description><![CDATA[Recursion is one of the core concepts in programming.  It&#8217;s valuable not only as a technique for writing programs, but as a general concept for solving problems.  XSLT provides many useful elements such as for-each (and apply-templates), but occasionally you will run into a problem which must be solved with recursion.  Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Recursion is one of the core concepts in programming.  It&#8217;s valuable not only as a technique for writing programs, but as a general concept for solving problems.  XSLT provides many useful elements such as for-each (and apply-templates), but occasionally you will run into a problem which must be solved with recursion.  Let&#8217;s take a look at a real-world (no Fibonacci!!) example, where we have to operate on a simple string of numbers separated by commas.  We&#8217;ll take a step-by-step approach to writing a recursive template. </p>
<p>Let&#8217;s say we have the following source document, short and sweet.  We want to take each number, and wrap it with an element.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comma<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1,2,3,4,5,6,7,88,99,100<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comma<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The easy way to do this is to use the <a href="http://www.exslt.org/str/functions/tokenize/">EXSLT str:tokenize function</a>, which takes a string and some delimiters and splits the string based on those delimiters. All we do is add the xmlns:str and extension-element-prefixes attributes to our xsl:stylesheet declaration, and then call the str:tokenize function.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> </span>
<span style="color: #009900;"><span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">xmlns:str</span>=<span style="color: #ff0000;">&quot;http://exslt.org/strings&quot;</span> </span>
<span style="color: #009900;"><span style="color: #000066;">extension-element-prefixes</span>=<span style="color: #ff0000;">&quot;str&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:for-each</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;str:tokenize( comma, ',')&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:for-each<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The result is, (new-lines added for readability):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>7<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>88<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>100<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/token<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Excellent. But let&#8217;s say that we don&#8217;t have access to the EXSLT functions, and we have to write a template to perform the same thing.  </p>
<p>So now we think up a recursive algorithm.  Let&#8217;s look at a simplified list with three numbers, such as &#8220;1,2,3&#8243;.  First, we print the &#8220;1&#8243;, the value before the first comma, and then we discard the first comma.  At that point, our list will be &#8220;2,3&#8243; and we repeat, printing the new first value, and discarding the new first comma. Finally, the list becomes only &#8220;3&#8243;.  There is no comma, so we simply print out the rest of the list, &#8220;3&#8243;.  So we will be recursing over the string printing the first number, and then popping off the first number and first comma.  This technique will work with a three number list, or a million-number list (though your processor will probably run out of memory before that).</p>
<p>XPath&#8217;s &#8220;substring-before&#8221;, &#8220;substring-after&#8221;, and &#8220;contains&#8221; functions are all of the tools that we&#8217;ll need to implement our algorithm.  &#8220;substring-before&#8221; lets us obtain the number before the first comma. &#8220;substring-after&#8221; lets us discard the first number and first comma, and &#8220;contains&#8221; allows us figure out the last, comma-less case.</p>
<p>Our function starts in the same manner as all recursive functions, dealing with the last case, and then all of the cases before it.  The last case will be the comma-less case from our algorithm. So here&#8217;s our template skeleton.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;splitcommas&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:choose<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:when</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot; not(contains($comma, ','))&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #808080; font-style: italic;">&lt;!-- do something --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:when<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:otherwise<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #808080; font-style: italic;">&lt;!-- do something --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:otherwise<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:choose<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>We use the XPath &#8220;not(contains($comma, &#8216;,&#8217;))&#8221; to, obviously, test whether our list contains a comma.  As you probably noticed, we don&#8217;t actually have a $comma variable defined, so we&#8217;ll add our xsl:param to the template.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;splitcommas&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;comma&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:choose<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:when</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot; not(contains($comma, ','))&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #808080; font-style: italic;">&lt;!-- do something --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:when<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:otherwise<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #808080; font-style: italic;">&lt;!-- do something --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:otherwise<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:choose<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now we fill in the holes in the template&#8217;s framework.  First, we&#8217;ll handle the comma-less case, simply outputting the value wrapped in a &#8220;value&#8221; element.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$comma&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Then we will deal with the otherwise case.  We&#8217;ll first print out the number before the first comma in the same manner that we printed the comma-less case.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;substring-before($comma, ',')&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Then we&#8217;ll perform the same operation on the list after discarding the first number and first comma.  We&#8217;ll call the template again, passing everything after the first comma (thus excluding both the first number and the first comma).</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:call-template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;splitcommas&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:with-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;comma&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;substring-after($comma, ',')&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:call-template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Finally, we&#8217;ll put all of these parts together, as well as adding a root template that will call our &#8220;splitcommas&#8221; template.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:call-template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;splitcommas&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:with-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;comma&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;comma&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:call-template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;splitcommas&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;comma&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:choose<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:when</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot; not(contains($comma, ','))&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$comma&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:when<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:otherwise<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;substring-before($comma, ',')&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:call-template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;splitcommas&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:with-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;comma&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;substring-after($comma, ',')&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:call-template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:otherwise<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:choose<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>When applied to our source document, we get exactly what we wanted, each number of the string, enclosed in a <value> element (I added new-lines for readability).</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>7<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>88<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>100<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>So we accomplished what we were looking to accomplish by writing a recursive template, however our template only deals with commas.  What if our list was separated by spaces instead of commas?  We&#8217;d have to either write a new template that deals with spaces, or, better yet, modify our template to be more generic and handle many cases.  I invite you to take a look at the <a href="http://www.exslt.org/str/functions/tokenize/str.tokenize.template.xsl">actual implementation of the str:tokenize  function</a>.  It isn&#8217;t that much more complicated, but does contain a few interesting wrinkles.</p>
<p>If you&#8217;re interested in the basics of recursion in general, I highly recommend <a href="http://www.amazon.com/gp/product/0262560992?ie=UTF8&#038;tag=eddwelsblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0262560992"><i>The Little Schemer</i></a> which is the most outstanding book I&#8217;ve read on the subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eddiewelker.com/2008/12/28/recursive-xslt-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My XSLT Toolbox &#8211; copy and copy-of</title>
		<link>http://www.eddiewelker.com/2008/12/27/xslt-copy-copy-of/</link>
		<comments>http://www.eddiewelker.com/2008/12/27/xslt-copy-copy-of/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 20:05:09 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[xslt]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[copy-of]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.eddiewelker.com/?p=184</guid>
		<description><![CDATA[Using XSLT to copy elements is extremely common when you&#8217;re transforming a source document of a certain type (XML, HTML, etc.) to the same type.  Often, you need an exact copy of an element verbatim, but other times you need to selectively choose certain elements to copy and others to discard.  XSLT makes [...]]]></description>
			<content:encoded><![CDATA[<p>Using XSLT to copy elements is extremely common when you&#8217;re transforming a source document of a certain type (XML, HTML, etc.) to the same type.  Often, you need an exact copy of an element verbatim, but other times you need to selectively choose certain elements to copy and others to discard.  XSLT makes this process quite elegant using it&#8217;s xsl:copy-of and xsl:copy elements.  The following is a setp-by-step tutorial on how these elements are used.</p>
<p>When you need an exact copy of an element and it&#8217;s children, you use the xsl:copy-of element, which makes an exact copy of the selected element and it&#8217;s children.  Given the following XML data, which represents a (trivial) inventory of a store, let&#8217;s say you want an exact copy of any items with the name &#8220;XSLT&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inventory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>The Little Schemer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>book<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Friedman<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Felleisen<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>29.95<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>26.99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>17.92<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>XSLT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>book<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tidwell<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>49.95<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>34.99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>22.92<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Romeo and Juliet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>compact disc<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conductor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Rostropovich<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/conductor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>18.98<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>13.99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>9.92<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inventory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You simply apply the following XSLT stylesheet to your source document:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;inventory/item[name = 'XSLT']&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Which gives you exactly what you were looking for, the &#8220;item&#8221; with the name &#8220;XSLT&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>XSLT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>book<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tidwell<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>49.95<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>34.99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>22.92<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>That was easy, so now let&#8217;s say you want to do a little more with your inventory document.  Your boss wants a copy of it to look at the numbers and do some accounting.  She doesn&#8217;t care about the authors or conductors, so she&#8217;d like that information left out.  Also, she would like an additional piece of information for each item, the amount of profit off each item sold, the difference between the sell-price and the cost.  </p>
<p>Because we are adding a piece of information and getting rid of elements that don&#8217;t affect the accounting, we can&#8217;t use a xsl:copy-of, because that would output an exact copy of the item element, it&#8217;s attribute nodes, and it&#8217;s child nodes. This exact copy is called a <i>deep copy</i>, because it not only copies the element, but all of it&#8217;s children as well.  The solution is to use xsl:copy which performs a <i>shallow copy</i>, which means it <b>only</b> copies the current node, and ignores all children or attribute nodes.</p>
<p>Since xsl:copy only copies one element at a time, you need to explicitly specify that you want to continue copying attribute nodes and child nodes.  xsl:apply-templates gives us the leverage to write a template that accomplishes that.  The following template starts by matching attribute and children nodes, then copies the node, and recursively applies itself to any attribute or child nodes found in the source tree.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- @* matches any attribute node on the current element,</span>
<span style="color: #808080; font-style: italic;">       node() matches any child nodes of the current element --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- shallow copy... </span>
<span style="color: #808080; font-style: italic;">          only copy the node you're on (be that attribute or child node) --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- apply this template to any other attribute or child nodes found --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Using this template, I can write a XSLT stylesheet that will copy the entire source document without any changes.  This isn&#8217;t quite what we were looking for, because we wanted to add and remove child elements of item, but this is the first step.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- copy all attribute or child nodes in place --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>So how do we add the profit made from each item and remove the unnecessary information?  We use the fact that our xsl:match=&#8221;@*|node()&#8221; template has a very low priority.  Determination of default XSLT priorities are an advanced topic I won&#8217;t go into right now, but feel free to <a href="http://www.w3.org/TR/xslt#conflict">explore the topic</a> if <a href="http://www.dpawson.co.uk/xsl/sect2/N7654.html#d11689e235">you are interested</a>.  Our template is essentially given a priority of -.5.  Templates such as xsl:template match=&#8221;foo&#8221;, however, are given a default priority of 0.  Because templates matching element names are higher priority, we can easily figure out how to remove the &#8220;author&#8221; and &#8220;conductor&#8221; elements, just declare templates without outputs!</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;author&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;conductor&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>We use the same technique to add an element to our &#8220;item&#8221; elements.  First we use xsl:copy to copy the item node itself.  Then we apply-templates to any attribute or children nodes found.  When an author or conductor element is found, it will match our explicit rules and produce no output, therefore they will not be copied into our result.  Finally, we create a new element named &#8220;profit&#8221; which will contain the difference between the sell-price and the cost.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;profit<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;(sell-price - cost)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/profit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>So we arrive at our final XSLT stylesheet, which looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- for each item, copy the &lt;item&gt; element, and apply-templates</span>
<span style="color: #808080; font-style: italic;">         to it's attributes and children. Finally, create a &lt;profit&gt; </span>
<span style="color: #808080; font-style: italic;">         element, the difference between the sell-price and the cost.  --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;profit<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;(sell-price - cost)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/profit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- don't copy these, when they're found, there is no output --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;author&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;conductor&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- copy all attribute or child nodes in place --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>When applied to our source document, we get the result our boss wanted, it excludes any &#8220;author&#8221; or &#8220;composer&#8221; elements, and includes a &#8220;profit&#8221; element.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inventory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>The Little Schemer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>book<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>29.95<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>26.99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>17.92<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;profit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>9.07<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/profit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>XSLT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>book<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>49.95<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>34.99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>22.92<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;profit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>12.07<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/profit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Romeo and Juliet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>compact disc<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>18.98<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>13.99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sell-price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>9.92<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;profit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>4.07<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/profit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inventory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Using this technique, we can then easily prepare another XSLT stylesheet to generate an inventory list for the customer, which will exclude the &#8220;cost&#8221; element, since we don&#8217;t want them knowing it!  All we need is to match all attribute and children nodes and copy them as normal, while providing no output when the XSLT processor encounters a &#8220;cost&#8221; element.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- don't copy the cost, the customer doesn't need to know! --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;cost&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- copy all attribute or child nodes in place --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Personally, because I end up transforming XML sources to XML output, I end up using xsl:copy-of and xsl:template match=&#8221;@*|node()&#8221; all the time.  In fact, xsl:template match=&#8221;@*|node()&#8221; just happens to be the first piece of code in my XSLT toolbox.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eddiewelker.com/2008/12/27/xslt-copy-copy-of/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Advantages of push-style XSLT over pull-style</title>
		<link>http://www.eddiewelker.com/2008/11/25/push-style-xslt-vs-pull-style/</link>
		<comments>http://www.eddiewelker.com/2008/11/25/push-style-xslt-vs-pull-style/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 04:56:24 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[xslt]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[pull]]></category>
		<category><![CDATA[push]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://www.eddiewelker.com/?p=155</guid>
		<description><![CDATA[Working with more than a few new-hires over the last few weeks, I&#8217;ve noticed that new XSLT developers often write pull-style XSLTs by default.  However, this tends to defy XSLT&#8217;s functional heritage, and is not as useful as the opposite form, push-style XSLTs.
Pull-style XSLTs reach into the source document and pull out the data [...]]]></description>
			<content:encoded><![CDATA[<p>Working with more than a few new-hires over the last few weeks, I&#8217;ve noticed that new XSLT developers often write pull-style XSLTs by default.  However, this tends to defy XSLT&#8217;s functional heritage, and is not as useful as the opposite form, push-style XSLTs.</p>
<p>Pull-style XSLTs reach into the source document and pull out the data they need to transform.  The pull-style is similar to template systems like those found in Rails or Django, or inserting PHP commands between HTML elements. For example, given the trivial input:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;books<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>The Scheme Programming Language<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>R. Kent Dybvig<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Essentials of Programming Languages<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Daniel P. Friedman<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>An Introduction to Information Theory<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>John R. Pierce<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/books<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>an XSLT novice will produce a stylesheet like the following (note lines 11 and 12 which reach into the source and grab the data):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>books<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:for-each</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;books/book&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dt<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/dt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dd<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;author&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/dd<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:for-each<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>which transforms into:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>books<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>The Scheme Programming Language<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dd<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>R. Kent Dybvig<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dd<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Essentials of Programming Languages<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dd<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Daniel P. Friedman<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dd<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>An Introduction to Information Theory<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dd<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>John R. Pierce<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dd<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<hr/>
<p>The real power of XSLT, however, is defining templates for the elements found within the source document. These are push-style XSLTs.  They have two main advantages.  First, push-style gracefully handles complex source structures, including recursively nested elements.  It would be near impossible to handle the following source document using pull-style,</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>a<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>if you didn&#8217;t know how deep the recursive divs would go. A push-style solution, though, is incredibly simple.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;div&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     * <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> *
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Will transform the previous source into the following.</p>
<pre>* * * a * * *</pre>
<p>In addition to handling complex source structures, push-style allows code reuse.  This is of course an ideal of any programming language.  Push-style XSLTs have a greater ability to be reused, because the individual templates can be reused.  When you only have one template, it is quite difficult to make it general without resorting to numerous choose-when statements.  Here is an example of code reuse, where we extend a previously written template with the xsl:apply-imports rule.</p>
<p>Given the input,</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;images<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;image<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://www.filmjunkie.com/drinks/blixa/blixa.jpg<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;alt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Blixa!<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/alt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/image<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/images<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>and the XSLTs,</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:import</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;imageformat.xsl&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;image&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;wrapper&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-imports</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>and the rule in &#8220;imageformat.xsl&#8221; (the template being extended in this case),</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;image&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;{url}&quot;</span> <span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;{alt_text}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>the processor will apply the higher-precedence template first, and then apply the imported (and lower-precedence) template to yield the following output.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;wrapper&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://www.filmjunkie.com/drinks/blixa/blixa.jpg&quot;</span> <span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;Blixa!&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Push-style XSLTs are not the most obvious thing to pick up unless you&#8217;ve been exposed to a functional programming language like Lisp or Scheme. However, considering their great value, they should be among the first disciplines studied when learning XSLT. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.eddiewelker.com/2008/11/25/push-style-xslt-vs-pull-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review of &#8220;Object-Oriented JavaScript&#8221;</title>
		<link>http://www.eddiewelker.com/2008/10/25/object-oriented-javascript-review/</link>
		<comments>http://www.eddiewelker.com/2008/10/25/object-oriented-javascript-review/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 02:02:16 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[books]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.eddiewelker.com/?p=122</guid>
		<description><![CDATA[I recently read Object Oriented JavaScript, by Stoyan Stefanov. In reviewing it, I found it was one of the most interesting books I've read in a while, for some good reasons and a few more curious reasons.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.packtpub.com/object-oriented-javascript-applications-libraries/book"><img class="size-full wp-image-125 alignleft" style="margin-right: 10px; margin-bottom: 10px;" title="Object Oriented JavaScript" src="http://www.eddiewelker.com/wp-content/uploads/2008/10/objectorientedjavascript.jpg" alt="Object Oriented JavaScript" width="225" height="286" /></a></p>
<p>I recently read <a href="http://www.packtpub.com/object-oriented-javascript-applications-libraries/book">Object-Oriented JavaScript</a>, by <a href="http://www.phpied.com/">Stoyan Stefanov</a>.  In reviewing it, I found it was one of the most interesting books I&#8217;ve read in a while, for some good reasons and a few more curious reasons.</p>
<p>Object-Oriented JavaScript was authored by Mr. Stefanov, who is a developer at Yahoo.  It features an impressive number of reviewers (twelve), among them <a href="http://www.crockford.com/">Douglas Crockford</a>, the author of <a href="http://oreilly.com/catalog/9780596517748/"><em>JavaScript: The Good Parts</em></a>, and <a href="http://techfoolery.com/">Ross Harmes</a>, author of <a href="http://www.apress.com/book/view/159059908x"><em>JavaScript Design Patterns</em></a>, both of whom are Stefanov&#8217;s Yahoo co-workers.  In a reasonable 330 pages, it features eight chapters on JavaScript&#8217;s History, Basic Syntax/Features, Functions, Objects, Prototypes, Inheritance, the DOM, and Patterns/Best Practices.</p>
<p>Readers with little to no JavaScript knowledge will be able to read this book, but I&#8217;m uncertain how much they&#8217;ll be able to glean from the meaty inner chapters (functions, objects, prototypes, and inheritance).  Readers with moderate JavaScript understanding should be able to learn a great deal from this book.  At the very least, advanced readers should be reminded of some of the language&#8217;s quirkier parts, as well as benefiting from an organized chapter on inheritance techniques.</p>
<p>It is tricky placing Object-Oriented JavaScript in context of the corpus of JavaScript literature.  This book includes more than a little introductory material (chapters 1-2), while the core chapters (3-6) are way beyond an introduction.  Only after those chapters (which I will discuss in a second) is the reader introduced briefly to the DOM and XHR before a chapter on design patterns and best practices.  At a minimum, every chapter is useful and full of hints that are difficult to <em>grep</em> from run-of-the-mill JavaScript books. The book steers clear of the murky world of browser differences unless they&#8217;re pertinent to the topic of Object-Oriented JavaScript, which seems perfectly acceptable.</p>
<p>Back to those middle chapters, they are sheer gold.  I am going force myself to make time to re-read this book, if not those chapters alone.  They present, in a clear and organized fashion, many difficult aspects of the language, including closures, prototype, and 12 different methods for inheritance.  In comparison, I believe Harmes&#8217; book isn&#8217;t as well organized, and Crockford&#8217;s book isn&#8217;t as clear. Stefanov doesn&#8217;t break much new ground here, but the clarity describing these techniques is quite valuable regardless.</p>
<p>Object-Oriented JavaScript appears occasionally try to be something to everyone.  This is kind of disappointing, since I would have <span style="text-decoration: underline;">loved</span> to have seen any additional discussion or insight the author could have offered in the core chapters.  There are tons of introductory JavaScript books, so I don&#8217;t know what a book titled Object-Oriented JavaScript gains by including more introduction. This shouldn&#8217;t detract from the book&#8217;s overall value.  All of the chapters are well written and useful.  However as a reader gains a better understanding of JavaScript, the introductory chapters will become far less useful, while the other chapters will remain an excellent reference.</p>
<p>In my mind, the three best JavaScript books are Flanagan&#8217;s <em>JavaScript The Definitive Guide</em>, Crockford&#8217;s <em>JavaScript: The Good Parts</em>, and Harmes&#8217; and [Dustin] Diaz&#8217;s <em>Pro JavaScript Design Patterns</em>.  Object-Oriented JavaScript doesn&#8217;t belong in that company for the reasons mentioned above.  However, I would easily give it fourth place, and recommend it as a clear description of JavaScript&#8217;s harder parts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eddiewelker.com/2008/10/25/object-oriented-javascript-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
