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

<channel>
	<title>Expressing IT &#187; XSL</title>
	<atom:link href="http://developer.expressionz.in/blogs/category/user_interface_developers/xsl/feed/" rel="self" type="application/rss+xml" />
	<link>http://developer.expressionz.in/blogs</link>
	<description>User Interface : just another, but a serious developers weblog</description>
	<lastBuildDate>Tue, 16 Aug 2011 05:23:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Calling Multiple Windows Onload Functions In Javascript</title>
		<link>http://developer.expressionz.in/blogs/2009/03/07/calling-multiple-windows-onload-functions-in-javascript/</link>
		<comments>http://developer.expressionz.in/blogs/2009/03/07/calling-multiple-windows-onload-functions-in-javascript/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 10:08:50 +0000</pubDate>
		<dc:creator>Nikhil</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[JavasScript]]></category>
		<category><![CDATA[Web Developer]]></category>
		<category><![CDATA[XSL]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://developer.expressionz.in/blogs/?p=88</guid>
		<description><![CDATA[Heres another little piece of Javascript trickery that I had to dig around because the situation commanded it. In one of my web sites, I had this situation where I had to implement "windows.onload" twice. The first thing that would came to an inexpeienced mind like mine ( I  have to say that, since I have been using javascript Frameworks and libraries, I have forgotton to simple things on my own... sad but true), is the following method]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2009%2F03%2F07%2Fcalling-multiple-windows-onload-functions-in-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2009%2F03%2F07%2Fcalling-multiple-windows-onload-functions-in-javascript%2F&amp;source=nikhild&amp;style=normal&amp;hashtags=Tips+%26amp%3B+Tricks&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Heres another little peice of Javascript trickery that I had to dig around because the situation commaned it. In one of my web sites, I had this situation where I had to implement &#8220;windows.onload&#8221; twice. The first thing that would came to an inexperienced mind like mine ( I  have to honestly say that, since I have been using  javascript Frameworks and libraries, I have forgotton to do simple things on my own&#8230; sad but true), is the  following method&#8230;</p>
<blockquote><pre class=""javascript"">
window.onload=onloadfn1;
window.onload=onloadfn2;
window.onload=onloadfn3;
etc...
</pre>
</blockquote>
<p>Sorry to say but, this wont work&#8230; dont want to discuss the execution science of Javascript much &#8230; but according to my recent experience, only the last function (onloadfn3) will ill actually get executed.</p>
<p>In normal situations, unlike mine (which I&#8217;ll talk about a little later)&#8230; you could do one of the following to execute mutliple onload functions &#8230;.</p>
<blockquote><p><strong>OR something like this</strong></p>
<pre class=""javascript"">
function doOnLoad() {
        onloadfn1();
        onloadfn2();
        onloadfn3();
}
window.onload = doOnLoad;
</pre>
</blockquote>
<p>For my current situation , I cannot use either  of the above&#8230;<br />
Why did I need to call windows.onload twice, rather that calling two functions within a single onload function? Here is quick look at my problem statement&#8230;</p>
<p><em>&#8220;My Site pages are  structured like the WORDPRESS theme&#8230;. i.e. there is a common Header.php and Footer.php that gets included into all the site pages. There is an onload function implementaion in the Footer.php to do some common onload functions. AND there are few pages that need to something of their own ONLOAD , apart from those done by the common onload function. If I assign callback function directly to the window.onload handler, it will over-ride previously assigned callbacks in the Footer.php&#8221;</em></p>
<p>&#8230;. Is my problem understood <img src='http://developer.expressionz.in/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ?</p>
<p>Well! there are few solutions that I did find. They all are very similar and mainly implementions of a solution given by Simon Willison  (<a href="http://simonwillison.net/2004/May/26/addLoadEvent/" target="_new">http://simonwillison.net/2004/May/26/addLoadEvent/</a>)&#8230;</p>
<p><strong>Solution :</strong></p>
<blockquote><p><strong>Simply add this javascript code to site &#8230;</strong></p>
<pre class="css">
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != <span class="cssString">&#039;function&#039;</span>) {
       window.onload = func
    <span class="cssMedia">}</span> else {
       window.onload = function() {
           if (oldonload) {
                  oldonload()
          <span class="cssMedia">}</span>
          func()
       <span class="cssMedia">}</span>
   <span class="cssMedia">}</span>
<span class="cssMedia">}</span>
</pre>
<p>And call it instead of the usual &#8220;windows.onload&#8221;</p>
<pre class="css">
addLoadEvent(FunctionToRunOnPageLoad);
addLoadEvent(function() {
/* more code to run on page load *
<span class="cssMedia">}</span>); </pre>
</blockquote>
<p><strong>Advantages of this code snippet &#8230;</strong><br />
1.  Primarily, It lets you have multiple windows.onload events, called from seperate parts of your code,   without overridding the previous definition<br />
2. It is really unobtrusive. It can be placed in a file with your other scripts or in a separate file.<br />
3. It works even if window.onload has already been set.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.expressionz.in/blogs/2009/03/07/calling-multiple-windows-onload-functions-in-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>TEXTAREA Collapse problem in XSL/XSLT</title>
		<link>http://developer.expressionz.in/blogs/2008/09/20/textarea-collapse-problem-in-xslxslt/</link>
		<comments>http://developer.expressionz.in/blogs/2008/09/20/textarea-collapse-problem-in-xslxslt/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 07:26:12 +0000</pubDate>
		<dc:creator>Nikhil</dc:creator>
				<category><![CDATA[XSL]]></category>
		<category><![CDATA[XSL Quirks]]></category>

		<guid isPermaLink="false">http://developer.expressionz.in/blogs/?p=36</guid>
		<description><![CDATA[PROBLEM STATEMENT: I ran into this a problem regarding textareas in XSLs.  In simple words, the problem arises when you have a blank &#60;textarea&#62; tag, then it will collapse it to &#60;textarea /&#62;. i.e. if you had something like the following in your XSL and the XML data for the TEXTAREA value, returns nothing… &#60;textarea [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F09%2F20%2Ftextarea-collapse-problem-in-xslxslt%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F09%2F20%2Ftextarea-collapse-problem-in-xslxslt%2F&amp;source=nikhild&amp;style=normal&amp;hashtags=XSL+Quirks&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><strong><br />
PROBLEM STATEMENT:</strong><br />
I ran into this a problem regarding textareas in XSLs.  In simple words, the problem arises when you have a blank &lt;textarea&gt; tag, then it will collapse it to &lt;textarea /&gt;.<br />
i.e. if you had something like the following in your XSL and the XML data for the TEXTAREA value, returns nothing…</p>
<blockquote><p>&lt;textarea name=&#8217;description&#8217; &gt;&lt;xsl:value-of select=&#8221;DESCRIPTION&#8221;/&gt;&lt;/textarea&gt;</p></blockquote>
<p>As browsers don’t recognise this, it will cause the rest of the form HTML to run into the text area.</p>
<p><strong>POSSIBLE SOLUTIONS:</strong></p>
<blockquote><p>In the XSL, add a non-breaking-space ( ) after the xsl:value tag.BEWARE, to take care of this extra space you added, during client side validations of this field.</p>
<p>&lt;textarea  name=&#8217;description&#8217; &gt;&lt;xsl:value-of select=&#8221;DESCRIPTION&#8221;/&gt; &lt;/textarea&gt;</p>
<p><strong>Or</strong><br />
&lt;xsl:value-of select=&#8221;concat (DESCRIPTION,&#8217; &#8216;)&#8221;/&gt;</p>
<p><strong>Or</strong><br />
Insert a &lt;xsl:value-of select=”@unknown&#8221; /&gt; tag pointing to an unknown attribute. This will force the PHP XSLT parser to generate an opening and closing text area tag, even if it has nothing in between.</p>
<p><strong>Or</strong><br />
Insert a &lt;xsl:text&gt; field containing a space to force a closing tag.</p></blockquote>
<p>However, though the above mentioned solutions might seem to fix the problem, I am still not convinced that they are right and best ways to fix it. If there is any other better way of fixing this quirk, Please do let us know.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.expressionz.in/blogs/2008/09/20/textarea-collapse-problem-in-xslxslt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Variety of XSL Test Conditions (Collection of XSL:IF and XSL:WHEN TEST Conditions)</title>
		<link>http://developer.expressionz.in/blogs/2008/09/14/a-variety-of-xsl-test-conditions-collection-of-xslif-and-xslwhen-test-conditions/</link>
		<comments>http://developer.expressionz.in/blogs/2008/09/14/a-variety-of-xsl-test-conditions-collection-of-xslif-and-xslwhen-test-conditions/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 07:11:46 +0000</pubDate>
		<dc:creator>Nikhil</dc:creator>
				<category><![CDATA[XSL]]></category>
		<category><![CDATA[XSL:IF]]></category>
		<category><![CDATA[XSL:WHEN]]></category>

		<guid isPermaLink="false">http://developer.expressionz.in/blogs/?p=34</guid>
		<description><![CDATA[Every time I have to do a XSL:IF or XSL:WHEN test, I have go back to the reference books. I never seem to remember them. Thought there would be more out there, just like me, who would rather prefer to have all of them, possible, at one place, ready to be referred when needed. For [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F09%2F14%2Fa-variety-of-xsl-test-conditions-collection-of-xslif-and-xslwhen-test-conditions%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F09%2F14%2Fa-variety-of-xsl-test-conditions-collection-of-xslif-and-xslwhen-test-conditions%2F&amp;source=nikhild&amp;style=normal&amp;hashtags=XSL%3AIF,XSL%3AWHEN&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Every time I have to do a XSL:IF or XSL:WHEN test, I have go back to the reference books. I never seem to remember them. Thought there would be more out there, just like me, who would rather prefer to have all of them, possible, at one place, ready to be referred when needed.</p>
<p>For those who are new … Syntax for XSL:IF</p>
<blockquote><p>&lt;xsl:if test=&#8221;expression&#8221;&gt;<br />
&lt;!&#8211; Content: template &#8211;&gt;<br />
&lt;/xsl:if&gt;</p></blockquote>
<p><strong>The xsl:if/xsl:when Test Collection</strong><br />
The conditions below are all simple and self explanatory. So I believe it won’t need much explanation</p>
<blockquote><p>&lt;xsl:if test=&#8221;position()=last()-1&#8243;&gt;<br />
This if the last but one element in the list!<br />
&lt;/xsl:if&gt;</p>
<p>&lt;xsl:if test=&#8221;SALARY &gt; 5000&#8243;&gt;<br />
The salary of this person is greater than Rs. 5000<br />
&lt;/xsl:if&gt;</p>
<p>&lt;xsl:if test=&#8221;count(JOBS) &gt; 3&#8243;&gt;<br />
There are more than 3 jobs in this list!<br />
&lt;/xsl:if&gt;</p>
<p>&lt;xsl:if test=&#8221;(@DEPT = &#8216;SALES&#8217;) or (@JOINYEAR = &#8217;1997&#8242;)&#8221;&gt;<br />
       This person is from sales department OR his Year of Joining is 1997<br />
&lt;/xsl:if&gt;</p>
<p>&lt;xsl:if test=&#8221;EXPERIENCE&#8221;&gt;<br />
       This person have atleast one EXPERIENCE child element.<br />
&lt;/xsl:if&gt;</p>
<p>&lt;xsl:if test=&#8221;@HOBBY&#8221;&gt;<br />
    The person has a hobby attribute.<br />
&lt;/xsl:if&gt;</p></blockquote>
<p><strong>The same text conditions could be used for XSL:CHOOSE/XSL:WHEN as well</strong></p>
<h3>xsl:choose</h3>
<p>XSLT&#8217;s  xsl:choose instruction is similar to xsl:if but has a few key differences:<br />
• One xsl:choose element can test for more than one condition and add different nodes to the result tree based on which condition is true. <br />
• An xsl:choose element can have a default template to add to the result tree if none of the conditions are true. (Compare xsl:if, which has no equivalent of an &#8220;else&#8221; condition.)<br />
• The xsl:choose element has specific subelements that are necessary for it to work, while you can put any well-formed elements you want inside of an xsl:if element.</p>
<blockquote><p>&lt;xsl:choose&gt;<br />
&lt;xsl:when test=&#8221;boolean-expression&#8221;&gt;<br />
   Do something when this boolean-expression is TURE<br />
&lt;/xsl:when&gt;<br />
&lt;xsl:otherwise&gt; Do something else &lt;/xsl:otherwise&gt;<br />
&lt;/xsl:choose&gt;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://developer.expressionz.in/blogs/2008/09/14/a-variety-of-xsl-test-conditions-collection-of-xslif-and-xslwhen-test-conditions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tokenizing Delimited String inside an XSL</title>
		<link>http://developer.expressionz.in/blogs/2008/08/13/tokenizing-delimited-string-inside-an-xsl/</link>
		<comments>http://developer.expressionz.in/blogs/2008/08/13/tokenizing-delimited-string-inside-an-xsl/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 10:15:09 +0000</pubDate>
		<dc:creator>Nikhil</dc:creator>
				<category><![CDATA[XSL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://developer.expressionz.in/blogs/?p=30</guid>
		<description><![CDATA[If your requirement is to split a node value in an XML, that contains a delimited string of value, into individual items, then you have reached the right place … have a look at the example below. If you are familiar with a little bit of XML and XSL … I don’t think you would need any explanation.
Also, this example includes usage of XSL functions like xsl:call-template , xsl:substring-before, xsl:substring-after, if that’s what you are after.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F08%2F13%2Ftokenizing-delimited-string-inside-an-xsl%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F08%2F13%2Ftokenizing-delimited-string-inside-an-xsl%2F&amp;source=nikhild&amp;style=normal&amp;hashtags=Tutorials,XSLT&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>If your requirement is to split a node value in an XML, that contains a delimited string of value, into individual items, then you have reached the right place … have a look at the example below. If you are familiar with a little bit of XML and XSL … I don’t think you would need any explanation.<br />
Also, this example includes usage of XSL functions like xsl:call-template , xsl:substring-before, xsl:substring-after, if that’s what you are after.</p>
<p><strong>XML to be transformed (food.xml):-</strong><br />
Assume the task is to tokenize the string delimited by comma, in the the tag &#8220;keywords&#8221;</p>
<blockquote><p><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;<br />
&lt;?xml-stylesheet type="text/xsl" href="food.xsl"?&gt;<br />
&lt;food&gt;<br />
&lt;date&gt;July 2008&lt;/date&gt;<br />
&lt;description&gt;All about things we eat everyday&lt;/description&gt;<br />
<strong>&lt;keywords&gt;Fruits, Vegetables, Pulses, Meat, Cereals &lt;/keywords&gt;</strong><br />
&lt;/food&gt;</code></p></blockquote>
<p><strong>XSL (food.xsl):-</strong></p>
<blockquote><p><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;<br />
&lt;xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/&gt;<br />
&lt;xsl:template match="/"&gt;<br />
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;<br />
&lt;title&gt;XSL 1.0 Delimited String Tokeniser&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;xsl:value-of select="food/meta"/&gt;<br />
&lt;div &gt;<br />
<strong>&lt;xsl:call-template name="tokenize"&gt;<br />
&lt;xsl:with-param name="string" select="food/keywords" /&gt;<br />
&lt;xsl:with-param name="delimitr" select="','" /&gt;<br />
&lt;/xsl:call-template&gt;</strong><br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
&lt;/xsl:template&gt;<br />
&lt;xsl:template name="tokenize"&gt;<br />
&lt;xsl:param name="string" /&gt;<br />
&lt;xsl:param name="delimitr" /&gt;<br />
&lt;xsl:choose&gt;<br />
&lt;xsl:when test="contains($string, $delimitr)"&gt;<br />
&lt;div style="border:1px solid red;"&gt;<br />
&lt;h3&gt;&lt;xsl:value-of select="substring-before($string,$delimitr)" /&gt;&lt;/h3&gt;<br />
&lt;xsl:variable name="data" select="substring-before($string,$delimitr)"/&gt;<br />
&lt;/div&gt;<br />
&lt;xsl:call-template name="tokenize"&gt;<br />
&lt;xsl:with-param name="string" select="substring-after($string, $delimitr)" /&gt;&lt;xsl:with-param name="delimitr" select="$delimitr" /&gt;&lt;/xsl:call-template&gt;<br />
&lt;/xsl:when&gt;<br />
&lt;xsl:otherwise&gt;<br />
&lt;div style="border:1px solid red;"&gt;<br />
&lt;h3&gt;&lt;xsl:value-of select="$string" /&gt;&lt;/h3&gt;<br />
&lt;/div&gt;<br />
&lt;/xsl:otherwise&gt;<br />
&lt;/xsl:choose&gt;<br />
&lt;/xsl:template&gt;<br />
&lt;/xsl:stylesheet&gt;</code></p></blockquote>
<p>Resultant output HTML :-</p>
<blockquote><p><code>&lt;div&gt;<br />
&lt;div style="border: 1px solid red;"&gt;<br />
&lt;h3&gt;Fruits&lt;/h3&gt;<br />
&lt;/div&gt;<br />
&lt;div style="border: 1px solid red;"&gt;<br />
&lt;h3&gt; Vegetables&lt;/h3&gt;<br />
&lt;/div&gt;<br />
&lt;div style="border: 1px solid red;"&gt;<br />
&lt;h3&gt; Pulses&lt;/h3&gt;<br />
&lt;/div&gt;<br />
&lt;div style="border: 1px solid red;"&gt;<br />
&lt;h3&gt; Meat&lt;/h3&gt;<br />
&lt;/div&gt;<br />
&lt;div style="border: 1px solid red;"&gt;<br />
&lt;h3&gt; Cereals &lt;/h3&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;</code></p></blockquote>
<p>Needless to say &#8230; just change the  parameter &#8220;delimitr&#8221; to the delimiter of your choice</p>
<div style="text-align:right;"><strong><a href="http://developer.expressionz.in/blogs/wp-content/plugins/download-monitor/download.php?id=2">Download the above sample source files here</a></strong></div>
]]></content:encoded>
			<wfw:commentRss>http://developer.expressionz.in/blogs/2008/08/13/tokenizing-delimited-string-inside-an-xsl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A problem with position() in XSL &#8230; or is it?</title>
		<link>http://developer.expressionz.in/blogs/2008/08/04/problem-with-position-in-xsl/</link>
		<comments>http://developer.expressionz.in/blogs/2008/08/04/problem-with-position-in-xsl/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 13:33:59 +0000</pubDate>
		<dc:creator>Nikhil</dc:creator>
				<category><![CDATA[XSL]]></category>
		<category><![CDATA[XSL Quirks]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://developer.expressionz.in/blogs/?p=17</guid>
		<description><![CDATA[I had this strage problem while creating a XSL today. Looked for answers throughout the net, but couldnt find any &#8230;. Actually I guess! I dint know what my problem was, so what do I look for? Anyway! Just in case you have this very same problem too and somehow by the power of the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F08%2F04%2Fproblem-with-position-in-xsl%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F08%2F04%2Fproblem-with-position-in-xsl%2F&amp;source=nikhild&amp;style=normal&amp;hashtags=XSL,XSL+Quirks,XSLT&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I had this strage problem while creating a XSL today. Looked for answers throughout the net, but couldnt find any &#8230;. Actually I guess! I dint know what my problem was, so what do I look for?</p>
<p>Anyway! Just in case you have this very same problem too and somehow by the power of the FORCE you managed to land on this page &#8230; you would thank me tons &#8230; And if you have accidently landed on this page for some strange fate and you happen to be a XSL developer , <strong>DO MAKE A NOTE OF THIS NOW, FOR THE FUTURE</strong> cause, If some day, you face this issue, then the FORCE might not be with you.</p>
<p><strong>Problem statement:</strong><br />
I have this XML , where there are two nodes with multiple items in it and the items between these two nodes have a one to one correspondence. In the example below, each item in the node <strong>&lt;array name=&#8221;PLAYURL&#8221; /&gt;</strong> relates( corresponding position) to an item in the node <strong>&lt;array name=&#8221;SITENAME&#8221; /&gt;</strong></p>
<blockquote><p><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
&lt;myplaylists&gt;<br />
&lt;playlist&gt;<br />
&lt;title&gt;Best of Rest &lt;/title&gt;<br />
&lt;array name="SITENAME"&gt;<br />
&lt;str&gt;www.musicindiaonline.com&lt;/str&gt;<br />
&lt;str&gt;www.dhingana.com&lt;/str&gt;<br />
&lt;str&gt;www.raaga.com&lt;/str&gt;<br />
&lt;str&gt;www.smashits.com&lt;/str&gt;<br />
&lt;str&gt;www.desimusic.com&lt;/str&gt;<br />
&lt;str&gt;www.musicplug.in&lt;/str&gt;<br />
&lt;/array&gt;<br />
&lt;array name="PLAYURL"&gt;<br />
&lt;str&gt;http://www.musicindiaonline.com/123/&lt;/str&gt;<br />
&lt;str&gt;http://www.dhingana.com/play/123&lt;/str&gt;<br />
&lt;str&gt;http://www.raaga.com/123&lt;/str&gt;<br />
&lt;str&gt;http://ww.smashits.com/123&lt;/str&gt;<br />
&lt;str&gt;http://www.desimusic.com/123&lt;/str&gt;<br />
&lt;str&gt;http://www.musicplug.in/123&lt;/str&gt;<br />
&lt;/array&gt;<br />
&lt;/playlist&gt;<br />
&lt;/myplaylists&gt;</code></p></blockquote>
<p>Now, I have a loop , where i loop through <strong>&lt;array name=&#8221;SITENAME&#8221;&gt;</strong>, and I want to get the related item( at the corresponding position) in <strong>&lt;array name=&#8221;PLAYURL&#8221;&gt;</strong>,</p>
<p><strong>What you would normaly try do is &#8230;</strong></p>
<blockquote><p><code>&lt;xsl:for-each select="myplaylists/playlist/array[@name='SITENAME']/str"&gt;<br />
play from : &lt;a href="{../../array[@name='PLAY']/str[position()]}"/&gt; &lt;xsl:value-of select="." /&gt;&lt;/a&gt;<br />
&lt;/xsl:for-each&gt;</code></p></blockquote>
<p><strong>SORRY!! THIS WONT WORK &#8230; Ah!!!! Surpised &#8230;</strong></p>
<p>Now you would probably want to try , something like this &#8230;</p>
<blockquote><p><code>&lt;xsl:for-each select="myplaylists/playlist/array[@name='SITENAME']/str"&gt;<br />
&lt;xsl:variable name="pos"&gt; &lt;xsl:value-of select="position()"/&gt;&lt;/xsl:variable&gt;<br />
play from : &lt;a href="{../../array[@name='PLAY']/str[$pos]}"/&gt; &lt;xsl:value-of select="." /&gt;&lt;/a&gt;<br />
&lt;/xsl:for-each&gt;<br />
</code></p></blockquote>
<p>And Again this wont work &#8230; Now you scratching your head, trying to contact everyone who you think knows some XSL and could be of any help &#8230; you try every other option &#8230; and still it wont work &#8230; Well! Thats what happened to me atleast &#8230;</p>
<p><strong>DONT DESPAIR !!! TRY THIS </strong></p>
<blockquote><p><code>&lt;xsl:for-each select="myplaylists/playlist/array[@name='SITENAME']/str"&gt;<br />
&lt;xsl:variable name="pos-int" select="position()" /&gt;<br />
play from : &lt;a href="{../../array[@name='PLAY']/str[$</code><code>pos-int</code><code>]}"/&gt; &lt;xsl:value-of select="." /&gt;&lt;/a&gt;<br />
&lt;/xsl:for-each&gt;<br />
</code></p></blockquote>
<p>DONT ASK ME WHY IT WORKS. Cause i dont have a right reason&#8230; if you do! Please do drop a comment. It might be pretty usefull. Also! if you have better TITLE for this post, do drop me a line <img src='http://developer.expressionz.in/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://developer.expressionz.in/blogs/2008/08/04/problem-with-position-in-xsl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting the DOCTYPE in XSL</title>
		<link>http://developer.expressionz.in/blogs/2008/08/02/setting-the-doctype-in-xsl/</link>
		<comments>http://developer.expressionz.in/blogs/2008/08/02/setting-the-doctype-in-xsl/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 05:28:33 +0000</pubDate>
		<dc:creator>Nikhil</dc:creator>
				<category><![CDATA[XSL]]></category>
		<category><![CDATA[Browser Quirks]]></category>
		<category><![CDATA[Doctype]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://developer.expressionz.in/blogs/?p=14</guid>
		<description><![CDATA[The PROBLEM :
You want control over the DOCTYPE, since your transformation will include a default DOCTYPE explicitly, and you layout will be out for a toss.

The Solution:
XSLT specs provides output methods to set a the DOCTYPE of choise. Also, for us UI developers, the topics of interest would be HTML output methods and XML output methods.
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F08%2F02%2Fsetting-the-doctype-in-xsl%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F08%2F02%2Fsetting-the-doctype-in-xsl%2F&amp;source=nikhild&amp;style=normal&amp;hashtags=Browser+Quirks,Doctype,XML,XSL&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Last week I created a progessive HTML/CSS layout for a client, tested it in IE6, IE7 and FF 3, seemed perfectly fine&#8230; UNTIL! the layout went further down the manufacting cycle. It failed. Page layout elements just went all over the place when the HTML layout was converted into  XSL and  XML applied to it &#8230; Bummer!!!</p>
<p>Could not sleep ok over the weekend, in anticipation of Monday morning, when I&#8217;ll have to fix this SH**. But now having a little experince in dealing with these kind of situations ( Browser Quirks, I mean), I knew it had to do with nothing else but DOCTYPE&#8230;. and It WAS&#8230;</p>
<p><strong>The Problem:</strong><br />
You want control over the DOCTYPE, since your transformation will include a default DOCTYPE explicitly, and you layout will be out for a toss.</p>
<p><strong>The Solution:</strong><br />
<a title="XSL Specs" href="http://www.w3.org/TR/xslt" target="_blank">XSLT specs</a> provides output methods to set a the DOCTYPE of choise. Also, for us UI developers, the topics of interest would be <a title="XSl Specs : HTMl Output" href="http://www.w3.org/TR/xslt#section-HTML-Output-Method" target="_blank">HTML output methods </a>and <a title="XSl Specs : XSl Output" href="http://www.w3.org/TR/xslt#section-XML-Output-Method" target="_blank">XML output methods</a>.</p>
<p>Well! before you get bored , here is the fix.</p>
<p>For eg., if you had the following DOCTYPE in your HTML version :-</p>
<blockquote><p><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;</code></p></blockquote>
<p>Then in the XSL you would have to have the following :-</p>
<blockquote><p><code>&lt;xsl:output method="html" doctype-system="http://www.w3.org/TR/html4/loose.dtd" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" indent="yes" /&gt;<br />
</code></p></blockquote>
<p>and Finally! do make sure your XSLT output obeys the DOCTYPE  you have chosen.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.expressionz.in/blogs/2008/08/02/setting-the-doctype-in-xsl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Include XSL inside XSL</title>
		<link>http://developer.expressionz.in/blogs/2008/05/04/include-xsl-inside-xsl/</link>
		<comments>http://developer.expressionz.in/blogs/2008/05/04/include-xsl-inside-xsl/#comments</comments>
		<pubDate>Sun, 04 May 2008 09:48:51 +0000</pubDate>
		<dc:creator>Nikhil</dc:creator>
				<category><![CDATA[XSL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL Includes]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://developer.expressionz.in/blogs/?p=16</guid>
		<description><![CDATA[Imagine you are creating a website (and using XML, XSL transfroms ofcourse) and most of the pages would have a <strong>Comments Module </strong>. Well! then either you copy or paste this code into every page template or even better you create an INCLUDE file can call it where ever you want it in your main page template...<strong>So HOW DO WE INCLUDE a XSL file inside another XSL file</strong>? Here is how...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F05%2F04%2Finclude-xsl-inside-xsl%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F05%2F04%2Finclude-xsl-inside-xsl%2F&amp;source=nikhild&amp;style=normal&amp;hashtags=Tutorials,XML,XSL,XSL+Includes,XSLT&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>If XML/XSL Transforms is your domian, then there are times when we want a peice of Dynamic code to be used library item(to be made re-usable). What I mean , probably could be made more clear with this example scenario.</p>
<p>Imagine you are creating a website (and using XML, XSL transfroms ofcourse) and most of the pages would have a <strong>Comments Module </strong>. Well! then either you copy or paste this code into every page template (which I dont have say, but make maintenance and rework a nightmare) or even better, you create an INCLUDE file which could be pulled in where ever you want it in your page(s)&#8230;<br />
<strong>So HOW DO WE CREATE a XSL INCLUDE file and include it inside another XSL file</strong>? Here is how&#8230;</p>
<p>Just to make things clear &#8230; here is quick list of files that you would create &#8230; here , we will be including info about fruits and vegetables into a parent page called food.</p>
<p>1. food.xml &#8211; xml data file on which the transformation will be applied<br />
2. food.xsl  -  main XSL file, which will transform our food.xml<br />
3. inc_fruits.xsl &#8211; XSL include file that will render fruits data<br />
4. inc_vegtables.xsl &#8211; XSL include file that will render vetetables data</p>
<p>I dont think I have explain much , the codes for above elements , will be self explanatory&#8230;</p>
<p><strong>FOOD.XML</strong></p>
<blockquote>
<div><code><br />
&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;<br />
&lt;?xml-stylesheet type="text/xsl" href="food.xsl"?&gt;<br />
&lt;food&gt;<br />
&lt;date&gt;July 2008&lt;/date&gt;<br />
&lt;description&gt;All about things we eat everyday&lt;/description&gt;<br />
&lt;fruits type="tropical"&gt;<br />
&lt;item name="mango" moreinfo="http://www.mango.com"&gt;Mango is the king of fruits&lt;/item&gt;<br />
&lt;item name="banana" moreinfo="http://www.banana.com"&gt;Banana once a day , keeps the doctor away&lt;/item&gt;<br />
&lt;item name="orange" moreinfo="http://www.orange.com"&gt;Orange is the color and rich in vitamin C&lt;/item&gt;<br />
&lt;item name="Papaya" moreinfo="http://www.papaya.com"&gt;Papaya - Hot when raw, cold when ripe&lt;/item&gt;<br />
&lt;/fruits&gt; </code></div>
<p><code>&lt;vegetables&gt;<br />
&lt;item name="spinach" moreinfo="http://www.spinach.com"&gt;Spinach is full of iron&lt;/item&gt;<br />
&lt;item name="asparagus" moreinfo="http://www.asparagus.com"&gt;Asparagus contains loads of vitamin D &lt;/item&gt;<br />
&lt;item name="fenugreek" moreinfo="http://www.fenugreek.com"&gt;Fenugreek is rich in vitamin C&lt;/item&gt;<br />
&lt;/vegetables&gt;<br />
&lt;/food&gt;</p>
<p></code></p></blockquote>
<hr />
<strong>FOOD.XSL</strong></p>
<blockquote>
<div><code><br />
&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;<br />
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;<br />
&lt;xsl:include href="inc_fruits.xsl" /&gt;<br />
&lt;xsl:include href="inc_vegetables.xsl" /&gt;<br />
&lt;xsl:template match="/"&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Title&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h3&gt;&lt;xsl:value-of select="/food/description" /&gt;&lt;/h3&gt;<br />
Modification Date : &lt;xsl:value-of select="/food/date" /&gt;<br />
&lt;hr/&gt;<br />
&lt;h5&gt; About Fruits&lt;/h5&gt;<br />
&lt;xsl:call-template name="about_fruits"/&gt;</code></div>
<p><code>&lt;hr/&gt;<br />
&lt;h5&gt; About Vegetables&lt;/h5&gt;<br />
&lt;xsl:call-template name="about_vegetables"/&gt;</p>
<p>&lt;hr/&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
&lt;/xsl:template&gt;<br />
&lt;/xsl:stylesheet&gt;</p>
<p> </p>
<p></code></p></blockquote>
<hr />
<strong>INC_FRUITS.XSL</strong></p>
<blockquote><p><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;<br />
&lt;xsl:output method="html" encoding="iso-8859-1" /&gt;<br />
&lt;xsl:template name="about_fruits"&gt;<br />
&lt;xsl:for-each select="/food/fruits/item/@*"&gt;<br />
attribute name : &lt;xsl:value-of select="name()"/&gt; <br />
attribute value : &lt;xsl:value-of select="."/&gt; &lt;br /&gt;<br />
&lt;/xsl:for-each&gt;<br />
&lt;/xsl:template&gt;<br />
&lt;/xsl:stylesheet&gt;</code></p></blockquote>
<hr />
<strong>INC_VEGETABLES.XSL</strong></p>
<blockquote><p><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;<br />
&lt;xsl:output method="html" encoding="iso-8859-1" /&gt;<br />
&lt;xsl:template name="about_vegetables"&gt;<br />
&lt;xsl:for-each select="/food/vegetables/item/@*"&gt;<br />
attribute name : &lt;xsl:value-of select="name()"/&gt; <br />
attribute value : &lt;xsl:value-of select="."/&gt; &lt;br/&gt;<br />
&lt;/xsl:for-each&gt;<br />
&lt;/xsl:template&gt;<br />
&lt;/xsl:stylesheet&gt;</code></p></blockquote>
<p><strong><a title="download" href="http://developer.expressionz.in/blogs/wp-content/plugins/download-monitor/download.php?id=5" target="_blank">Download all the above files here (235 downloads)</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://developer.expressionz.in/blogs/2008/05/04/include-xsl-inside-xsl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with XML Node Attributes in XSLT</title>
		<link>http://developer.expressionz.in/blogs/2008/04/04/working-with-xml-node-attributes-in-xslt/</link>
		<comments>http://developer.expressionz.in/blogs/2008/04/04/working-with-xml-node-attributes-in-xslt/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 08:17:25 +0000</pubDate>
		<dc:creator>Nikhil</dc:creator>
				<category><![CDATA[XSL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XML Attributes]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://developer.expressionz.in/blogs/?p=15</guid>
		<description><![CDATA[If you use XML and XSL, then you might have come across a time , when you have to play around with attributes and values of XML nodes in you XSL. They are loads of sites with long winded info about this, but none I found were brief and precise ... This is NO XML/XSL TUTORIAL,but my attempt to put-together some sort of cheat list ...
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F04%2F04%2Fworking-with-xml-node-attributes-in-xslt%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F04%2F04%2Fworking-with-xml-node-attributes-in-xslt%2F&amp;source=nikhild&amp;style=normal&amp;hashtags=Tutorials,XML,XML+Attributes,XSL,XSLT&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>If you use XML and XSL, then you might have come across a time , when you have to play around with attributes and values of XML nodes in you XSL. They are loads of sites with long winded info about this, but none I found were brief and precise &#8230; This is NO XML/XSL TUTORIAL,but my attempt to put-together some sort of cheat list &#8230;</p>
<p>The sample XML that we will working with looks like this&#8230;</p>
<blockquote><p><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;<br />
&lt;?xml-stylesheet type="text/xsl" href="food.xsl"?&gt;<br />
&lt;food&gt;<br />
&lt;fruits type="tropical"&gt;<br />
&lt;item name="mango" moreinfo="http://www.mango.com"&gt;Mango is the king of fruits&lt;/item&gt;<br />
&lt;item name="banana" moreinfo="http://www.banana.com"&gt;Banana once a day , keeps the doctor away&lt;/item&gt;<br />
&lt;item name="orange" moreinfo="http://www.orange.com"&gt;Orange is the color and rich in vitamin C&lt;/item&gt;<br />
&lt;item name="Papaya" moreinfo="http://www.papaya.com"&gt;Papaya - Hot when raw, cold when ripe&lt;/item&gt;<br />
&lt;/fruits&gt;<br />
&lt;/food&gt;</code></p></blockquote>
<p>So Lets begin transforming our above XML using XSL</p>
<p><strong>Example 1 : Displaying value at a chosen Attribute</strong></p>
<blockquote><p><code>&lt;xsl:value-of select="/food/fruits/item[@name='orange']" /&gt;&lt;br /&gt;<br />
to get more information about &lt;a href="{/food/fruits/item[@name='orange']/@moreinfo}" target="new" &gt;&lt;xsl:value-of select="/food/fruits/item[@name='orange']/@name" /&gt; &lt;/a&gt;</code></p></blockquote>
<p>HTML result will look like</p>
<blockquote><p><code>Orange is the color and rich in vitamin C,<br />
to get more information about &lt;a href="http://www.orange.com" target="new"&gt;</code></p></blockquote>
<hr/>
<p><strong>Example 2 : Looping through and displaying all XML Attribute Names and their Values</strong></p>
<blockquote><p> <code>&lt;xsl:for-each select="/food/fruits/item/@*"&gt;<br />
  attribute name : &lt;xsl:value-of select="name()"/&gt;,&#160;<br />
    attribute value : &lt;xsl:value-of select="."/&gt;&#160; &lt;br /&gt;<br />
  &lt;/xsl:for-each&gt;</code></p></blockquote>
<p>HTML result will look like</p>
<blockquote><p><code><br />
attribute name : name,  attribute value : mango<br />
attribute name : moreinfo,  attribute value : http://www.mango.com<br />
attribute name : name,  attribute value : banana<br />
attribute name : moreinfo,  attribute value : http://www.banana.com<br />
attribute name : name,  attribute value : orange<br />
attribute name : moreinfo, attribute value : http://www.orange.com<br />
attribute name : name,  attribute value : Papaya<br />
attribute name : moreinfo,  attribute value : http://www.papaya.com<br />
</code></p></blockquote>
<hr/>
<strong><a title="download" href="http://developer.expressionz.in/blogs/wp-content/plugins/download-monitor/download.php?id=4" target="_blank">Download all the above files here (228 downloads)</a></strong></p>
<p><br/><br />
Watch this space, I&#8217;ll keep updating this with new findings&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.expressionz.in/blogs/2008/04/04/working-with-xml-node-attributes-in-xslt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

