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
XSL Quirks | Expressing IT

Posts Tagged ‘ XSL Quirks ’

TEXTAREA Collapse problem in XSL/XSLT

Saturday, September 20th, 2008 By Nikhil


PROBLEM STATEMENT:

I ran into this a problem regarding textareas in XSLs.  In simple words, the problem arises when you have a blank <textarea> tag, then it will collapse it to <textarea />.
i.e. if you had something like the following in your XSL and the XML data for the TEXTAREA value, returns nothing…

<textarea name=’description’ ><xsl:value-of select=”DESCRIPTION”/></textarea>

As browsers don’t recognise this, it will cause the rest of the form HTML to run into the text area.

POSSIBLE SOLUTIONS:

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.

<textarea  name=’description’ ><xsl:value-of select=”DESCRIPTION”/> </textarea>

Or
<xsl:value-of select=”concat (DESCRIPTION,’ ‘)”/>

Or
Insert a <xsl:value-of select=”@unknown” /> 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.

Or
Insert a <xsl:text> field containing a space to force a closing tag.

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.


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


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