Skip to main content

Posts

Alternative row colours in XSL

In the same project as before, my search results are being presented in a table.  The issue here, is that I want to have a different background colour for an alternate for the purpose of easy readability. Luckily, XSL saves the day with the position() function.  This is really handy for obtaining your current index when in a loop.  Just as with using any other server side language you want to mod 2 the position to identify the alternate row: <xsl:if test="position() mod 2 ='1'">     <xsl:attribute name="class">rowA</xsl:attribute> </xsl:if> For a quick reminder of the modulus operation ( mod ): when applying the arithmetic on an even number it, correctly returns 0.  When applying to an uneven number, such as 5, it will return the value 1.  1 denotes that there is a remainder. The purpose of xsl:attribute is to apply XML/XSL to an attribute of a HTML tag.  In this case I want to apply a CSS style to the table row ( tr...

XSL Calculations and Formatting

While using XSL I came across the need to perform a calculation by converting metres to some other units, and then formatting the output. number() takes the value of the selected node and treats it as an actual number.  number() div 1000 is my actual calculation to convert metres to kilometres. Notice that I am using the keyword div and not the / operator as you would with other languages such as Javascript:     <xsl:value-of select="number() div 1000"/> km Being all nice and outputting my desired output, this is flawed. When it comes to outputting in other units such as miles and yards, it shows a large nasty decimal number.  It's far too accurate and long that it's not really user friendly.  A simple presentation would be to limit the output to 2 decimal places.  The answer to this is to use the format-number() function. This was all achieved in this one-liner:     <xsl:value-of select="format-number(number() div 1000,'#0....

Test for spaces in text

When it comes to XSL you have to pay particular attention to the schema of the XML you are trying to make use of.  There are certain cases when you do not have control over the XML being produced that your XSL needs to be generic. I am currently updating a Community Portal, which I developed in the past for my current company and have just discovered a silly human error.  Yes. I made a bad mistake.  The coding for this system assumed that there would be no spaces in a post code when trying to build a list of links. The block was along the lines of: <a target="_blank">   <xsl:attribute name="href">     <xsl:value-of select="@theLink" />     <!-- Check length of string and attach post code with a space -->   </xsl:attribute>   <xsl:attribute name="title">     <!-- Attach the title of the link for accessibility-->   </xsl:attribute>   <xsl:value-of select=...

ASP Reverse For Loop

It's kind of interesting of how reverse linking does not seem so obvious in classic ASP.  You would think that it would be along the lines of: dim i for i = 30 to 2   'code comes here next but it's not.  To have a reverse For loop it's: dim i for i = 30 to 2 Step-1   'code comes here next That's right that small bit ( Step-1 ) makes all the difference.  I stumbled upon this by chance and thought that someone would benefit from this. Happy coding. Blogged with Flock

Free Microsoft Development Tools

OK, it may not be Open Source.  But, as a follow up to Microsoft's success in providing Free .Net development tools for the Windows operating system, they are gearing up for the next version. Visual Studio 2008 Express Editions Beta 2. This Beta release really wows you with the future of the development tools, which lets you develop for Windows, the Web, Games, Hardware and Databases. Check it out at: http://msdn2.microsoft.com/express/future/ Blogged with Flock

CSS Horizontal Navigation

I know that I once stated that using UL to build a list of links was not desirable, but there are times when you have no choice. It is fairly straightforward and you do not need any JavaScript to ruin your code.  So let's get started an define the menu and wrap it inside a DIV: <div id ="hovermenu" >   <ul >         <li > <a href ="#" href ="Link Number 1" > Link #1 </a > </li >         <li > <a href ="#" href ="Link Number 2" > Link #2 </a > </li >         <li > <a href ="#" href ="Link Number 3" > Link #3 </a > </li >     </ul > </div> Now for the CSS: .hovermenu ul{   font: bold 13px arial;   padding-left: 0;   margin-left: 0;   height: 40px; } .hovermenu ul li{   list-style: none;   display: inline; } .hovermenu ul li a{ ...