Skip to main content

Posts

Showing posts with the label xml

Simple XSL transformation test tool

I know, I know. There's a lot of tools out there to help with editing XML and XSL files and a whole lot of other mess. While creating an XML-based web site system in my current role, I wanted to be able to just test my XSL before plugging it in to my code in case it started causing any difficulties. Basically, all I need was a transformation tool that works like in Altova XMLSpy. I couldn't find many, and when I did, in some cases it wasn't presented in an obvious way where the general interface complicated things. Almost giving up, I decided to hack together a simple tool myself. Since the required system is in ASP.NET and I haven't done application development in a long time, I gave C# a shot. For me the tool worked like a charm and does "exactly what it says on the tin". My colleagues even took a liking to it. So I would like to share it with you. I've simply called it XML Transformer and you can get hold of it from here . Features There's not much...

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....