gpx文件的XSL样式表



我有一个gpx文件,我对其中的许多"名称"做了一些编辑。当它是表格格式的时候。一切正常,只是移动了"名称"。在我的"扩展"之后进入;文件夹中。它移动了我编辑过的所有图片。我需要他们搬回正确的位置,这是在"时间"之后。有些分录是"空白"的;这是可以的。下面是一个示例文件,我将其命名为MadeUp。第一个条目是正确的,但第二个是错误的顺序。我只需要像下面这样排序。gpx文件。我有一些软件可以转换文件,只要xsl模板文件是正确的。

<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:h="http://www.humminbird.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creator="Humminbird PC 4.6.1 [Build20190411001]" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<wpt lat="32.02994571203832" lon="-97.42508814212279">
<ele />
<time>2021-08-25T20:46:53Z</time>
<name>Made Up</name>
<desc />
<sym>Fish</sym>
<extensions>
<h:uniqueid />
<h:group>My Data</h:group>
<h:edited />
<h:visible>true</h:visible>
<h:spotlock>false</h:spotlock>
<h:creator />
<h:viewas>IconOnly</h:viewas>
<h:color>Magenta</h:color>
<h:radiustoggle>false</h:radiustoggle>
<h:radiussafety>false</h:radiussafety>
<h:radius />
<h:depth />
<h:cursordepth />
<h:temperature />
<h:version>2</h:version>
</extensions>
</wpt>
<wpt lat="32.03012171740864" lon="-97.42471086455052">
<ele />
<time>2021-08-25T20:46:53Z</time>
<desc />
<sym>Fish</sym>
<extensions>
<h:uniqueid />
<h:group>My Data</h:group>
<h:edited />
<h:visible>true</h:visible>
<h:spotlock>false</h:spotlock>
<h:creator />
<h:viewas>IconOnly</h:viewas>
<h:color>Magenta</h:color>
<h:radiustoggle>false</h:radiustoggle>
<h:radiussafety>false</h:radiussafety>
<h:radius />
<h:depth />
<h:cursordepth />
<h:temperature />
<h:version>2</h:version>
</extensions>
<name>Made Up</name>
</wpt>
</gpx>

我试过根据正确的格式制作xsl模板,但当我转换文件时,它给了我一个错误,"不是一个有效的xml文件。我试着修改一些我在网上找到的例子,但没有一个工作正常。谢谢你的帮助。谢谢你的宝贵时间。下面是我的xsl文件:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:h="www.humminbird.com" version="1.0">
<xsl:output method="xml" encoding="utf-8" indent="no" />
<xsl:template match="gpx">
<xsl:text>;lat, lon,  Time, name, desc, sym, extensions, h:uniqueid, h:group, h:edited, h:visible, h:spotlock, h:creator, h:viewas, h:color, h:radiustoggle,h:radiussafety, h:radius, h:depth, h:cursordepth, h:temperature, h:version</xsl:text>
<xsl:apply-templates select="wpt" />
</xsl:template>
<xsl:template match="wpt">
<xsl:value-of select="@lat" />
<xsl:text>,</xsl:text>
<xsl:value-of select="@lon" />
<xsl:text>,</xsl:text>
<xsl:value-of select="time" />
<xsl:text>,</xsl:text>
<xsl:value-of select="name" />
<xsl:text>,</xsl:text>
<xsl:value-of select="desc" />
<xsl:text>,</xsl:text>
<xsl:value-of select="sym" />
<xsl:text>,</xsl:text>
<xsl:value-of select="extensions" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:uniqueid" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:group" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:edited" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:visible" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:spotlock" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:creator" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:viewas" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:color" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:radiustoggle" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:radiussafety" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:radius" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:depth" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:cursordepth" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:temperature" />
<xsl:text>,</xsl:text>
<xsl:value-of select="h:version" />
<xsl:text>,</xsl:text>
</xsl:template>
</xsl:stylesheet>

不确定您使用什么软件进行转换,所以我假设您仅限于XSLT 1.0。

我是这样做的:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gpx="http://www.topografix.com/GPX/1/1">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="gpx:wpt">
<xsl:copy>
<xsl:apply-templates select="@*|node()[not(self::gpx:name)]"/>
</xsl:copy>
</xsl:template>

<xsl:template match="gpx:time">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<xsl:apply-templates select="../gpx:name"/>
</xsl:template>

</xsl:stylesheet>

工作小提琴:http://xsltfiddle.liberty-development.net/gVAkJ4S

最新更新