Frage

Is necessary for me convert this data:

Longitude 8-55,810 into Longitude 8.93016666

This transformation is obtained :

  • 8 is the integer part and remains untouched;
  • the second part after '.' is obtained dividend 55,810 by 60

In xslt 1.0 I:

<!-- Declared a variable longitudine es. 8-55,810-->
<xsl:variable name="lon" select='LONGITUDE'/>

<!-- I put in a variable the part after '-' es. 55.810 -->
<xsl:variable name="partemobilelon" select="substring-after($lon,'-')"/>

Now is necessary for me Convert '55.810'(is String) to Number and Divide by 60 (only 8 character after ',').

War es hilfreich?

Lösung

See if this helps:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:variable name="longitude" select="'8-55,810'" />

<xsl:template match="/">
    <output>
        <xsl:param name="int" select="substring-before($longitude, '-')" />
        <xsl:param name="dec" select="translate(substring-after($longitude, '-'), ',', '.')"/>
        <xsl:value-of select="$int + $dec div 60" />
    </output>
</xsl:template>

</xsl:stylesheet>

Edit:

To round the result, try:

<xsl:template match="/">
    <output>
        <xsl:param name="int" select="substring-before($longitude, '-')" />
        <xsl:param name="dec" select="translate(substring-after($longitude, '-'), ',', '.')"/>
        <xsl:param name="num" select="$int + $dec div 60" />
        <xsl:value-of select="round($num * 100000000) div 100000000" />
    </output>
</xsl:template>

or just:

<xsl:template match="/">
    <output>
        <xsl:param name="int" select="substring-before($longitude, '-')" />
        <xsl:param name="dec" select="translate(substring-after($longitude, '-'), ',', '.')"/>
        <xsl:value-of select="format-number($int + $dec div 60, '0.########')" />
    </output>
</xsl:template>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top