Forcing a decimal point on the first digit

Posted on 2004-11-16
Medium Priority
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
  • 2
  • 2
LVL 15

Accepted Solution

dualsoul earned 500 total points
ID: 12598620
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')" />

Expert Comment

ID: 12598674
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.


Expert Comment

ID: 12598685
beaten to the post!!

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


Author Comment

ID: 12598738
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.

Author Comment

ID: 12598811
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline

807 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