Warning: Creating default object from empty value in /home/expressionz/developer.expressionz.in/blogs/wp-content/plugins/download-monitor/classes/download_taxonomies.class.php on line 156

Warning: Creating default object from empty value in /home/expressionz/developer.expressionz.in/blogs/wp-content/plugins/download-monitor/classes/download_taxonomies.class.php on line 156

Warning: Creating default object from empty value in /home/expressionz/developer.expressionz.in/blogs/wp-content/plugins/download-monitor/classes/download_taxonomies.class.php on line 156
2008 August | Expressing IT

Archive for August, 2008

Tokenizing Delimited String inside an XSL

Wednesday, August 13th, 2008 By Nikhil

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.

XML to be transformed (food.xml):-
Assume the task is to tokenize the string delimited by comma, in the the tag “keywords”

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="food.xsl"?>
<food>
<date>July 2008</date>
<description>All about things we eat everyday</description>
<keywords>Fruits, Vegetables, Pulses, Meat, Cereals </keywords>
</food>

XSL (food.xsl):-

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<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"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>XSL 1.0 Delimited String Tokeniser</title>
</head>
<body>
<xsl:value-of select="food/meta"/>
<div >
<xsl:call-template name="tokenize">
<xsl:with-param name="string" select="food/keywords" />
<xsl:with-param name="delimitr" select="','" />
</xsl:call-template>

</div>
</body>
</html>
</xsl:template>
<xsl:template name="tokenize">
<xsl:param name="string" />
<xsl:param name="delimitr" />
<xsl:choose>
<xsl:when test="contains($string, $delimitr)">
<div style="border:1px solid red;">
<h3><xsl:value-of select="substring-before($string,$delimitr)" /></h3>
<xsl:variable name="data" select="substring-before($string,$delimitr)"/>
</div>
<xsl:call-template name="tokenize">
<xsl:with-param name="string" select="substring-after($string, $delimitr)" /><xsl:with-param name="delimitr" select="$delimitr" /></xsl:call-template>
</xsl:when>
<xsl:otherwise>
<div style="border:1px solid red;">
<h3><xsl:value-of select="$string" /></h3>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

Resultant output HTML :-

<div>
<div style="border: 1px solid red;">
<h3>Fruits</h3>
</div>
<div style="border: 1px solid red;">
<h3> Vegetables</h3>
</div>
<div style="border: 1px solid red;">
<h3> Pulses</h3>
</div>
<div style="border: 1px solid red;">
<h3> Meat</h3>
</div>
<div style="border: 1px solid red;">
<h3> Cereals </h3>
</div>
</div>

Needless to say … just change the parameter “delimitr” to the delimiter of your choice


get ExpressingIT News by Email Subscribe to ExpressingIT by Email or  Follow Me on Twitter


Download This Faux Positioned WordPress Template

Monday, August 11th, 2008 By Nikhil

If you are one of those guys (like me), who often check the CSS of well made HTML page , to get inspired or whatever, then you might have noticed that we have used FAUX Positioning (as already mentioned in my earlier article We are using Faux Absolute Positioning : A Brilliant CCS Layout)

We did some good work on this template , so thought it would nice to share it …. Download This WordPress Theme (downloaded 348 times)


get ExpressingIT News by Email Subscribe to ExpressingIT by Email or  Follow Me on Twitter


ANIMOTO : Really Nice “Rich User Interface” without Flash!

Thursday, August 7th, 2008 By Nikhil

Have you seen animoto.com? Well! this is not an AD , I really liked it! and it is Kiss ASS UI indeed

I came across this site a few weeks ago. Saw the first page, dint bother much. For me, it was just another site with some rich flash content, allowing users to upload images, choose some track and convert it into a nice picture slideshow. Download FLV, and put it on any site of your choice( YouTube, MetaCafe, Facebook and the likes)… PERIOD.

Yesterday when I saw the internal flow pages, which took the user through creation of this slideshow…. I went OH WOW! When I realized that there was not bit of FLASH used. It was indeed a Rich User Interface. All UI developers must aspire to create or at least be a part of the team that has done this interface…. Absolutely brilliant!!! And Inspiring!

HAVE A LOOK … http://animoto.com/… and register and play with it … only then can you appreciate the genius.


get ExpressingIT News by Email Subscribe to ExpressingIT by Email or  Follow Me on Twitter


A problem with position() in XSL … or is it?

Monday, August 4th, 2008 By Nikhil

I had this strage problem while creating a XSL today. Looked for answers throughout the net, but couldnt find any …. 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 FORCE you managed to land on this page … you would thank me tons … And if you have accidently landed on this page for some strange fate and you happen to be a XSL developer , DO MAKE A NOTE OF THIS NOW, FOR THE FUTURE cause, If some day, you face this issue, then the FORCE might not be with you.

Problem statement:
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 <array name=”PLAYURL” /> relates( corresponding position) to an item in the node <array name=”SITENAME” />

<?xml version="1.0" encoding="utf-8"?>
<myplaylists>
<playlist>
<title>Best of Rest </title>
<array name="SITENAME">
<str>www.musicindiaonline.com</str>
<str>www.dhingana.com</str>
<str>www.raaga.com</str>
<str>www.smashits.com</str>
<str>www.desimusic.com</str>
<str>www.musicplug.in</str>
</array>
<array name="PLAYURL">
<str>http://www.musicindiaonline.com/123/</str>
<str>http://www.dhingana.com/play/123</str>
<str>http://www.raaga.com/123</str>
<str>http://ww.smashits.com/123</str>
<str>http://www.desimusic.com/123</str>
<str>http://www.musicplug.in/123</str>
</array>
</playlist>
</myplaylists>

Now, I have a loop , where i loop through <array name=”SITENAME”>, and I want to get the related item( at the corresponding position) in <array name=”PLAYURL”>,

What you would normaly try do is …

<xsl:for-each select="myplaylists/playlist/array[@name='SITENAME']/str">
play from : <a href="{../../array[@name='PLAY']/str[position()]}"/> <xsl:value-of select="." /></a>
</xsl:for-each>

SORRY!! THIS WONT WORK … Ah!!!! Surpised …

Now you would probably want to try , something like this …

<xsl:for-each select="myplaylists/playlist/array[@name='SITENAME']/str">
<xsl:variable name="pos"> <xsl:value-of select="position()"/></xsl:variable>
play from : <a href="{../../array[@name='PLAY']/str[$pos]}"/> <xsl:value-of select="." /></a>
</xsl:for-each>

And Again this wont work … Now you scratching your head, trying to contact everyone who you think knows some XSL and could be of any help … you try every other option … and still it wont work … Well! Thats what happened to me atleast …

DONT DESPAIR !!! TRY THIS

<xsl:for-each select="myplaylists/playlist/array[@name='SITENAME']/str">
<xsl:variable name="pos-int" select="position()" />
play from : <a href="{../../array[@name='PLAY']/str[$
pos-int]}"/> <xsl:value-of select="." /></a>
</xsl:for-each>

DONT ASK ME WHY IT WORKS. Cause i dont have a right reason… 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 :)


get ExpressingIT News by Email Subscribe to ExpressingIT by Email or  Follow Me on Twitter


Setting the DOCTYPE in XSL

Saturday, August 2nd, 2008 By Nikhil

Last week I created a progessive HTML/CSS layout for a client, tested it in IE6, IE7 and FF 3, seemed perfectly fine… 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 … Bummer!!!

Could not sleep ok over the weekend, in anticipation of Monday morning, when I’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…. and It WAS…

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.

Well! before you get bored , here is the fix.

For eg., if you had the following DOCTYPE in your HTML version :-

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Then in the XSL you would have to have the following :-

<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" />

and Finally! do make sure your XSLT output obeys the DOCTYPE  you have chosen.


get ExpressingIT News by Email Subscribe to ExpressingIT by Email or  Follow Me on Twitter


 Subscribe to ExpressingIT RSS
get ExpressingIT News by Email Subscribe to ExpressingIT by Email
 Follow Me on Twitter