【发布时间】:2019-08-14 06:47:47
【问题描述】:
我有以下 XML/KML 文件(见下文只是整个数据的一部分)。
我想通过 XSLT 删除特定元素及其内容(我正在使用带有插件 XML 工具的 Notepad++)。文件很大,必须使用 XSLT。
我想从<description> 元素中删除<Snippet> 元素和特定标签/内容:<p> 标签。
例如,一个原始条目是这样的:
<Placemark><name>Wando</name><Snippet>Record 325</Snippet><description><![CDATA[<p>Data source: <a href="https://mrdata.usgs.gov/ofr-2005-1294/" title="">Major mineral deposits worldwide</a></p><p>[<a href="https://mrdata.usgs.gov/major-deposits/show-ofr20051294.php?gid=325">All data for record 325</a>]</p><table border='1' padding='3' cellspacing='0'><tr valign='top'><th align='right' bgcolor='#ddffee' title='Generalized type of deposit'>Deposit type</th><td>Hydrothermal</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='Country in which the site is located'>Country</th><td>Korean Peninsula</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='State in which the site is located, for US sites'>State</th><td></td></tr></table>]]></description><styleUrl>#defaultStyleMap</styleUrl><Point><altitudeMode>relativeToGround</altitudeMode><coordinates>126.6833,34.35,0</coordinates></Point></Placemark>
XSLT之后我想实现的:
<Placemark><name>Wando</name><description><![CDATA[<table border='1' padding='3' cellspacing='0'><tr valign='top'><th align='right' bgcolor='#ddffee' title='Generalized type of deposit'>Deposit type</th><td>Hydrothermal</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='Country in which the site is located'>Country</th><td>Korean Peninsula</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='State in which the site is located, for US sites'>State</th><td></td></tr></table>]]></description><styleUrl>#defaultStyleMap</styleUrl><Point><altitudeMode>relativeToGround</altitudeMode><coordinates>126.6833,34.35,0</coordinates></Point></Placemark>
附:也可以删除<![CDATA[ + 不带<table> + ]]>
我确实需要<table>,例如:
<Placemark><name>Wando</name><description><table border='1' padding='3' cellspacing='0'><tr valign='top'><th align='right' bgcolor='#ddffee' title='Generalized type of deposit'>Deposit type</th><td>Hydrothermal</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='Country in which the site is located'>Country</th><td>Korean Peninsula</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='State in which the site is located, for US sites'>State</th><td></td></tr></table></description><styleUrl>#defaultStyleMap</styleUrl><Point><altitudeMode>relativeToGround</altitudeMode><coordinates>126.6833,34.35,0</coordinates></Point></Placemark>
整个RAW数据:
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.2/"> <Document>
<name>Major mineral deposits of the world</name>
<description>Regional locations and general geologic setting of known deposits of major nonfuel mineral commodities. Originally compiled in five parts by diverse authors, combined here for convenience despite likely inconsistencies among the regional reports.</description>
<Placemark><name>Wando</name><Snippet>Record 325</Snippet><description><![CDATA[<p>Data source: <a href="https://mrdata.usgs.gov/ofr-2005-1294/" title="">Major mineral deposits worldwide</a></p><p>[<a href="https://mrdata.usgs.gov/major-deposits/show-ofr20051294.php?gid=325">All data for record 325</a>]</p><table border='1' padding='3' cellspacing='0'><tr valign='top'><th align='right' bgcolor='#ddffee' title='Generalized type of deposit'>Deposit type</th><td>Hydrothermal</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='Country in which the site is located'>Country</th><td>Korean Peninsula</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='State in which the site is located, for US sites'>State</th><td></td></tr></table>]]></description><styleUrl>#defaultStyleMap</styleUrl><Point><altitudeMode>relativeToGround</altitudeMode><coordinates>126.6833,34.35,0</coordinates></Point></Placemark>
<Placemark><name>McDonald</name><Snippet>Record 549</Snippet><description><![CDATA[<p>Data source: <a href="https://mrdata.usgs.gov/ofr-2005-1294/" title="">Major mineral deposits worldwide</a></p><p>[<a href="https://mrdata.usgs.gov/major-deposits/show-ofr20051294.php?gid=549">All data for record 549</a>]</p><table border='1' padding='3' cellspacing='0'><tr valign='top'><th align='right' bgcolor='#ddffee' title='Generalized type of deposit'>Deposit type</th><td>Hydrothermal</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='Country in which the site is located'>Country</th><td>United States</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='State in which the site is located, for US sites'>State</th><td>Montana</td></tr></table>]]></description><styleUrl>#defaultStyleMap</styleUrl><Point><altitudeMode>relativeToGround</altitudeMode><coordinates>-112.525,47,0</coordinates></Point></Placemark>
<Placemark><name>Montana Mountains</name><Snippet>Record 575</Snippet><description><![CDATA[<p>Data source: <a href="https://mrdata.usgs.gov/ofr-2005-1294/" title="">Major mineral deposits worldwide</a></p><p>[<a href="https://mrdata.usgs.gov/major-deposits/show-ofr20051294.php?gid=575">All data for record 575</a>]</p><table border='1' padding='3' cellspacing='0'><tr valign='top'><th align='right' bgcolor='#ddffee' title='Generalized type of deposit'>Deposit type</th><td>Hydrothermal</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='Country in which the site is located'>Country</th><td>United States</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='State in which the site is located, for US sites'>State</th><td>Nevada</td></tr></table>]]></description><styleUrl>#defaultStyleMap</styleUrl><Point><altitudeMode>relativeToGround</altitudeMode><coordinates>-118.108,41.767,0</coordinates></Point></Placemark>
<Placemark><name>Basay</name><Snippet>Record 429</Snippet><description><![CDATA[<p>Data source: <a href="https://mrdata.usgs.gov/ofr-2005-1294/" title="">Major mineral deposits worldwide</a></p><p>[<a href="https://mrdata.usgs.gov/major-deposits/show-ofr20051294.php?gid=429">All data for record 429</a>]</p><table border='1' padding='3' cellspacing='0'><tr valign='top'><th align='right' bgcolor='#ddffee' title='Generalized type of deposit'>Deposit type</th><td>Hydrothermal</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='Country in which the site is located'>Country</th><td>Philippines</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='State in which the site is located, for US sites'>State</th><td></td></tr></table>]]></description><styleUrl>#defaultStyleMap</styleUrl><Point><altitudeMode>relativeToGround</altitudeMode><coordinates>122.6333,9.5667,0</coordinates></Point></Placemark>
<Placemark><name>Georgina Basin</name><Snippet>Record 52</Snippet><description><![CDATA[<p>Data source: <a href="https://mrdata.usgs.gov/ofr-2005-1294/" title="">Major mineral deposits worldwide</a></p><p>[<a href="https://mrdata.usgs.gov/major-deposits/show-ofr20051294.php?gid=52">All data for record 52</a>]</p><table border='1' padding='3' cellspacing='0'><tr valign='top'><th align='right' bgcolor='#ddffee' title='Generalized type of deposit'>Deposit type</th><td>Sedimentary</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='Country in which the site is located'>Country</th><td>Australia</td></tr><tr valign='top'><th align='right' bgcolor='#ddffee' title='State in which the site is located, for US sites'>State</th><td></td></tr></table>]]></description><styleUrl>#defaultStyleMap</styleUrl><Point><altitudeMode>relativeToGround</altitudeMode><coordinates>139.9667,-21.8833,0</coordinates></Point></Placemark>
<Style id="default_highlight"><BalloonStyle><text>Major Mineral Deposits</text></BalloonStyle><IconStyle><scale>1.5</scale><Icon><href>https://mrdata.usgs.gov/images/mine-32.png</href></Icon></IconStyle><LabelStyle><color>ffffffff</color></LabelStyle></Style><Style id="default_normal"><IconStyle><scale>1</scale><Icon><href>https://mrdata.usgs.gov/images/mine-32.png</href></Icon></IconStyle><LabelStyle><color>00ffffff</color></LabelStyle></Style><StyleMap id="defaultStyleMap"><Pair><key>normal</key><styleUrl>#default_normal</styleUrl></Pair><Pair><key>highlight</key><styleUrl>#default_highlight</styleUrl></Pair></StyleMap> </Document> </kml>
【问题讨论】: