Forcing a decimal point on the first digit

Posted on 2004-11-16
Last Modified: 2012-06-21
Ok i have a xml file and a xsl file.
I have managed to display all the data the way i wanted with one exception.
The xml file as a numeric value of a north south west east designation by numbers.
south and west would be a negative number and a north east would be a postive number.
I can get the numbers to show correctly to a point.
As all coordinates have a decimal point in reality.
Though the xml file only gives a whole number.
Here are the two lines of code i  am talking about
First this is from the xml file.
<location NS="575" WE="-528">
This is the lines of code in the xsl file to give the proper view im looking for.
<td bgcolor="#ffffff"><xsl:value-of select="format-number(number(location/@NS),'#,N;#,S')" /></td>
<td bgcolor="#ffffff"><xsl:value-of select="format-number(number(location/@WE),'#,E;#,W')" /> </td>

What will show when you look at the html view will be
575N 528W
What im looking for is 57.5N 52.8W so im looking for a solution on how to force a decimal point one digit over.
Mind you i am more then a beginner at this meaning i have no training what so ever in xml or xsl
So please be specfic in what you say to me as so i can understand what you are telling me.
Question by:TheTinkeringToad
    LVL 15

    Accepted Solution

    i think the easiest way is to divide number on 10 :)

    <xsl:value-of select="format-number(number(location/@NS div 10),'00.0N;00.0S')" />


    <xsl:value-of select="format-number(number(location/@WE div 10),'00.0E;00.0W')" />
    LVL 6

    Expert Comment

    if the substring is always 3 digits long you can use a variable

    <!-- this selects the whole string eg 575 -->
    <xsl:variable name="wholeNumber"><xsl:value-of select="location/@WE"/></xsl:variable>
    <!-- this selects only the first 2 digits start at the first value (5) and select 2 digits -->
    <xsl:variable name="First2digits"><xsl:value-of select="substring(location/@WE,1,2 )"/></xsl:variable>
    <!-- this selects only the 3rd digit: start at the second  value (7) and select 1 digits -->
    <xsl:variable name="lastdigit"><xsl:value-of select="substring(location/@WE,2,1 )"/></xsl:variable>

    then just stick em together...

    <xsl:value-of select="First2digits"/><xsl:text>.</xsl:text><xsl:value-of select="lastdigit"/>

    i havent checked the syntax of the above but the technique should work.

    If you dont know the length of the string of numbers youll have to count em,

    <xsl:value-of select="string-lenght(location/@WE)"/> which will return a number ... if you hold that string-length as a variable as above...

    <xsl:variable name="lengthOffNumber"><xsl:value-of select="string-lenght(location/@WE)"/></xsl:variable>

    you can then subtract 1 from it to get the second to last character of the string. You can then employ the same method to get the first numbers in the co-ords and add a . and the last digit.

    If you need further assistance post your xml and xslt and ill take closer look.

    LVL 6

    Expert Comment

    beaten to the post!!

    i think dualsoul is correct and its far easier than my method..

    LVL 2

    Author Comment

    Ill give it a whirl.
    and let you know what i find out seems simple enough on the first post.
    The statement on the second post referring to if there are always 3 digits.
    No there can be a few more and one less so that would not be a constant of 3 digits.

    Anyways ill be back in a bit and let you guys know.
    LVL 2

    Author Comment

    Yes indeed it did work.
    Thx for the help guys and gals.
    I tried to figure this out for 2 days on my own i started out with just the xml file and had to put togeather the xsl file with no training on xml it was quite difficult that was the last problem i had on that file. Thx again all for your help.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now