从KML到XSLT的KML xmlns属性冲突
我有一个XSLT,负责将KML重新格式化为GML从KML到XSLT的KML xmlns属性冲突,xslt,kml,google-earth,gml,opengis,Xslt,Kml,Google Earth,Gml,Opengis,我有一个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://w
<?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>
我觉得答案将是愚蠢的简单,但我还没有偶然发现它,我已经没有东西可以尝试和谷歌。你们有什么建议 理解XML名称空间前缀本身并没有意义是很重要的。它们只是名称空间名称的简写形式,名称空间是标识名称空间的URI。名称空间名称(通过名称空间声明属性绑定到前缀)实际上标识了具有名称空间意识的XML处理器(如XSLT处理器)中的名称空间和作用域名称。因此,尝试将一个前缀绑定到两个可选名称空间名称是没有意义的 所有这些都与XML模式文档的位置无关。但是,假设您正在谈论的KML2.2是由位于的模式文档描述的,其名称空间名称是
http://www.opengis.net/kml/2.2
,其模式明确规定。实例文档不能随意使用不同的名称空间名称(尽管它们可以随意将任何名称空间前缀绑定到该名称——它不必是“kml”)
一句话:只有两种可能性:
重要的是要理解XML名称空间前缀本身并没有意义。它们只是名称空间名称的简写形式,名称空间是标识名称空间的URI。名称空间名称(通过名称空间声明属性绑定到前缀)实际上标识了具有名称空间意识的XML处理器(如XSLT处理器)中的名称空间和作用域名称。因此,尝试将一个前缀绑定到两个可选名称空间名称是没有意义的 所有这些都与XML模式文档的位置无关。但是,假设您正在谈论的KML2.2是由位于的模式文档描述的,其名称空间名称是
http://www.opengis.net/kml/2.2
,其模式明确规定。实例文档不能随意使用不同的名称空间名称(尽管它们可以随意将任何名称空间前缀绑定到该名称——它不必是“kml”)
一句话:只有两种可能性:
<kml xmlns="http://www.opengis.net/kml/2.2">
<kml xmlns="http://earth.google.com/kml/2.2">...</kml>
xmlns:kml="http://www.opengis.net/kml/2.2 http://earth.google.com/kml/2.2"