這種轉變:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="lat/text() | long/text()">
<xsl:call-template name="DegreesToDecimal"/>
</xsl:template>
<xsl:template name="DegreesToDecimal">
<xsl:param name="pDegrees" select="."/>
<xsl:variable name="vDegrees" select=
"number(substring-before($pDegrees, ':'))"/>
<xsl:variable name="vMinutes" select=
"number(
substring-before(
substring-after($pDegrees, ':'),
':'
)
)"/>
<xsl:variable name="vSeconds" select=
"number(
substring-after(
substring-after($pDegrees, ':'),
':'
)
)"/>
<xsl:value-of select=
"$vDegrees
+
$vMinutes div 60
+
$vSeconds div 3600
"/>
</xsl:template>
</xsl:stylesheet>
當這個XML文檔施加:
<coordinates>
<lat>43:06:35.4779</lat>
<long>53:22:16.7890</long>
</coordinates>
產生想要的,正確的結果:
<coordinates>
<lat>43.10985497222222</lat>
<long>53.37133027777778</long>
</coordinates>
說明:正確使用的substring-before()
,substring-after()
和number()
功能。
您的意思是從度數(0到+ -180)到弧度(-pi到pi)?或者從43:06:35到43.109855? –
從43:06:35到43.109855 – mona