Link to home
Start Free TrialLog in
Avatar of TheTinkeringToad
TheTinkeringToad

asked on

Forcing a decimal point on the first digit

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.
ASKER CERTIFIED SOLUTION
Avatar of dualsoul
dualsoul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of metalmickey
metalmickey

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.

MM
beaten to the post!!

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

MM
Avatar of TheTinkeringToad

ASKER

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