我有一个 XSLT,它负责将 KML 重新格式化为 GML。
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.opengis.net/gml" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" exclude-result-prefixes="kml">
<xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes" />
<!-- Removes all nodes with any empty text -->
<xsl:template match="*[.='']"/>
<!-- Removes all nodes with any empty attribute -->
<xsl:template match="*[@*='']"/>
<xsl:template match="text()"/>
<xsl:template match="/">
<MultiSurface>
<surfaceMembers>
<xsl:apply-templates />
</surfaceMembers>
</MultiSurface>
</xsl:template>
<xsl:template match="kml:Placemark">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="kml:Point">
<!--<Point>
<xsl:apply-templates />
</Point>-->
</xsl:template>
<xsl:template match="kml:LineString">
<!--<LineString>
<xsl:apply-templates />
</LineString>-->
</xsl:template>
<xsl:template match="kml:Polygon">
<Polygon>
<xsl:apply-templates />
</Polygon>
</xsl:template>
<xsl:template match="kml:outerBoundaryIs">
<exterior>
<xsl:apply-templates />
</exterior>
</xsl:template>
<xsl:template match="kml:innerBoundaryIs">
<interior>
<xsl:apply-templates />
</interior>
</xsl:template>
<xsl:template match="kml:LinearRing">
<LinearRing>
<xsl:apply-templates />
</LinearRing>
</xsl:template>
<xsl:template match="kml:coordinates">
<posList>
<!--<xsl:value-of select="translate(., ',', ' ')" />-->
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="." />
</xsl:call-template>
</posList>
</xsl:template>
<xsl:template name="output-tokens">
<xsl:param name="list" />
<xsl:variable name="newlist" select="concat(normalize-space($list), ' ')" />
<xsl:variable name="first" select="substring-before($newlist, ' ')" />
<xsl:variable name="remaining" select="substring-after($newlist, ' ')" />
<!-- long, lat, alt-->
<xsl:variable name="long" select="substring-before($first, ',')" />
<xsl:choose>
<xsl:when test="contains(substring-after($first, ','), ',')">
<xsl:variable name="lat" select="substring-before(substring-after($first, ','), ',')" />
<xsl:value-of select="concat($lat, ' ', $long, ' ')" />
</xsl:when>
<xsl:otherwise>
<xsl:variable name="lat" select="substring-after($first, ',')" />
<xsl:value-of select="concat($lat, ' ', $long, ' ')" />
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$remaining">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$remaining" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
通常我们的客户给我们的 KML 文件有一个 kml 开始标签,如下所示:
<kml xmlns="http://www.opengis.net/kml/2.2">
对于这种情况,XSLT 非常适合转换该 KML 文件。然而,我们今天得到了一个...
<kml xmlns="http://earth.google.com/kml/2.2">...</kml>
这不起作用,我认为这是因为 KMLs xmlns 属性未设置为:http ://www.opengis.net/kml/2.2或者 XSLTs xmlns:kml 未设置为:http://earth。 google.com/kml/2.2
我尝试了以下但没有奏效
xmlns:kml="http://www.opengis.net/kml/2.2 http://earth.google.com/kml/2.2"
我觉得答案会非常简单,但我还没有偶然发现它,我已经没有东西可以尝试和谷歌了。你们有什么建议?