XSL Whitespaces...
Remember the piece of code you put in at the head of an XSL to preserve white spaces.? Well it does preserve whites if you have any midway, say in your variables or parameters passed.But what if you wanted to add a white space, in the output HTML you are generating. The same job done by a or a VbCrLf...?
Sad for beginners like us, pampered by the abundance of such variables in most languages, XSL is devoid of one.
Has a work around though...(God bless..!)
Let us say you wanted to print:
Hoodibaba, 888, BabyMamon..in the same line...
Getting the basics done with...
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:param name = "firstString" select = "Hoodibaba">
<xsl:param name = "secondString" select = "888">
<xsl:param name = "thirdString" select = "BabyMamon">
<xsl:template match="/">
<html>
<body>
<b>I am going to print 3 strings!</b>
Now if you just selected the value of these 3 parameters and printed, say like this...
<b><xsl:value-of select = "$firstString"/></b><xsl:value-of select = "$secondString"/><xsl:value-of select = "$thirdString"/>
..your output would be something like this...
Hoodibaba888BabyMamon
Not exactly lookable right..?
Thats where the idea of white spaces comes in..
We use the <xsl:text> functionality for the same.
<xsl:text> basically adds any additional text into your template that is not covered by other features.
So rewriting the above statements as....
<b><xsl:value-of select = "$firstString"/></b><xsl:text> </xsl:text><xsl:value-of select = "$secondString"/><xsl:text> </xsl:text><xsl:value-of select = "$thirdString"/>
Would give something more liek what we want....
Hoodibaba 888 BabyMamon
It preserves white spaces, remember..?
So you could also imitate the carriage return this way...
<b><xsl:value-of select = "$firstString"/></b><xsl:text>
</xsl:text><xsl:value-of select = "$secondString"/><xsl:text>
</xsl:text><xsl:value-of select = "$thirdString"/>
Would make our output look like this...
Hoodibaba
888
BabyMamon
Problems solved..eh..?
Learnings:
1....uhmmm...its the best language to work on when you like to use every single command to its fullest, what if for a mere job like a WhiteSpace..!
