我在Java中使用脚本用一些统计数据填充KML模板文件。在此操作之后,KML文件运行正常,我可以在GIS或Google Earth上看到相对地图。统计数据存储在字段“描述”中。
无论如何,有时数据不可用,字段由字符串“nodata”填充。我想设置一个XSL文件,用“nodata”删除整个地标,写一个新的KML文件,只由数据可用的地标标记。 KML的结构如下。
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="doc">
<Schema name="Geographic_Placemarks">
<SimpleField name="Description" type="string" />
<SimpleField name="x" type="string" />
<SimpleField name="y" type="string" />
</Schema>
<Folder>
<name>Geographic_Placemarks</name>
<Placemark>
<name>Site 1</name>
<description>nodata</description>
<Style>
<LineStyle>
<color>ff0000ff</color>
</LineStyle>
<PolyStyle>
<fill>0</fill>
</PolyStyle>
</Style>
<ExtendedData>
<SchemaData schemaUrl="#Geographic_Placemarks">
<SimpleData name="x">571750 </SimpleData>
<SimpleData name="y">4548250 </SimpleData>
</SchemaData>
</ExtendedData>
<Polygon>
<altitudeMode>clampToGround </altitudeMode>
<outerBoundaryIs>
<LinearRing>
<altitudeMode>clampToGround </altitudeMode>
<coordinates>11.1825432433631,45.6613329598511 11.1298128785963,45.7000370530753 11.1833198656477,45.6994951268141 11.1825432433631,45.6613329598511 </coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<name>Site 2</name>
<description>10</description>
<Style>
<LineStyle>
<color>ff0000ff</color>
</LineStyle>
<PolyStyle>
<fill>0</fill>
</PolyStyle>
</Style>
<ExtendedData>
<SchemaData schemaUrl="#Geographic_Placemarks">
<SimpleData name="x">575750</SimpleData>
<SimpleData name="y">4548250</SimpleData>
</SchemaData>
</ExtendedData>
<Polygon>
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>11.1825432433631,45.6613329598511 11.1833198656477,45.6994951268141 11.2337967406582,45.6989609013362 11.2329870100429,45.6607994408117 11.1825432433631,45.6613329598511 </coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Folder>
</Document>
</kml>
我已经尝试准备一个XSL文件来复制KML文件的所有行,除了带有“nodata”字符串描述的地标,但我真的是XSL的新手,可能我犯了一个粗略的错误。
这是XSL文件:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:kml="http://www.opengis.net/kml/2.2">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@*| node()"/>
</xsl:copy>
</xsl:template>
<!--placemarks to be deleted-->
<xsl:template match="kml:Placemark[kml:description = nodata]"/>
</xsl:stylesheet>
删除地标的关键条件是
<xsl:template match="kml:Placemark[kml:description = nodata]"/>
通过这种方式,应删除地标“Site 1”,并保留地标“Site 2”。但结果是KML中的两个地标都被删除了。
请帮我解决XSL设置问题?提前谢谢。
答案 0 :(得分:0)
改变这个:
<xsl:template match="kml:Placemark[kml:description = nodata]"/>
为:
<xsl:template match="kml:Placemark[kml:description = 'nodata']"/>