如何将十进制形式的坐标拆分为度分钟秒XSLT [英] How to split coordinates in decimal form to degrees minutes seconds XSLT

查看:49
本文介绍了如何将十进制形式的坐标拆分为度分钟秒XSLT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<gml:pos>42.171035 -2.07781</gml:pos>

我正在尝试使用xslt将坐标从十进制形式拆分和重新计算为度数分钟秒...我是xslt的新手,请您能帮我吗?谢谢

I am trying to split and recalculate coordinates from decimal form to degrees minutes seconds I am using xslt ... I am new in xslt please could you help me ? Thanks

推荐答案

在XSLT 1.0中,尝试执行以下操作:

In XSLT 1.0, try something like:

<xsl:template match="gml:pos">
    <coordinates>
        <lat>
            <xsl:call-template name="decimal-degrees-to-DMS">
                <xsl:with-param name="decimal-degrees" select="substring-before(., ' ')"/>
            </xsl:call-template>
        </lat>       
        <lon>
            <xsl:call-template name="decimal-degrees-to-DMS">
                <xsl:with-param name="decimal-degrees" select="substring-after(., ' ')"/>
            </xsl:call-template>
        </lon>   
    </coordinates>
</xsl:template>


<xsl:template name="decimal-degrees-to-DMS">
    <xsl:param name="decimal-degrees"/>

    <xsl:variable name="dec" select="translate($decimal-degrees * 3600, '-', '')" />
    <xsl:variable name="deg" select="floor($dec div 3600)" />
    <xsl:variable name="min" select="floor($dec div 60) mod 60" />
    <xsl:variable name="sec" select="$dec mod 60" />

    <xsl:value-of select="$deg" />
    <xsl:text>º </xsl:text>
    <xsl:value-of select="$min" />
    <xsl:text>' </xsl:text>
    <xsl:value-of select="format-number($sec, '0.00')" />
    <xsl:text>" </xsl:text>
    <xsl:choose>
        <xsl:when test="$decimal-degrees &lt; 0">S/W</xsl:when>
        <xsl:otherwise>N/E</xsl:otherwise>
    </xsl:choose>   
</xsl:template>

应用于您的示例,结果应为:

Applied to your example, the result should be:

<coordinates>
  <lat>42º 10' 15.73" N/E</lat>
  <lon>2º 4' 40.12" S/W</lon>
</coordinates>

这篇关于如何将十进制形式的坐标拆分为度分钟秒XSLT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆