GPX-Tracks中的交替颜色 [英] Alternating colors in GPX-Tracks
问题描述
这个问题涉及:如何总结,将4000+ GPX Trackpoints作为每天的日期命名的轨道?
Garmin GPS轨道提供了选项为每个轨道定义一个不同的颜色。
Garmin GPS-Tracks provide the option to define a different color for each track.
作为引用问题结果的完善,我想知道如何为每个GPS轨道应用交替颜色。例如第一个。赛道(当天的所有赛道点)均为第二级的洋红色。一天是着色的'DarkGray'和第三天。日再次'洋红'。
As a perfection to the result of the referring question, I wonder how to apply alternating colors for each GPS-track. For instance the 1st. track (all trackpoints for that day) are colored 'Magenta' the 2nd. day is colored 'DarkGray' and the 3rd. day again 'Magenta'.
使用节点(日期)在奇数或偶数天之间交替使用通常会在2天内产生相同的颜色。例如:3月31日至4月1日。会收到相同的颜色。
Using the node (date) to alternate between odd or even days would often produce the same color for 2 days. For example: March 31 to April 1st. would receive the same colors.
颜色适用于节点:< gpxx:DisplayColor>
Colors apply to the node: <gpxx:DisplayColor>
如何通过代码实现在引用问题的答案中提供了什么?
How can this be achieved using the code provided in the answer of the referring question?
<trk>
<name>ACTIVE LOG</name>
<extensions>
<gpxx:TrackExtension xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3">
<gpxx:DisplayColor>Magenta</gpxx:DisplayColor>
</gpxx:TrackExtension>
</extensions>
<trkseg>
推荐答案
您可以将位置()
加2并检查是否有余数。
You can divide the position()
by 2 and check to see if there is a remainder.
<xsl:stylesheet version="1.0"
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:gpx="http://www.topografix.com/GPX/1/1"
xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="gpx">
<xsl:output indent="yes" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:key name="date" match="gpx:trkpt" use="substring(gpx:time,1,10)"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each select="//gpx:trkpt[generate-id(key('date',substring(gpx:time,1,10))[1])=generate-id()]">
<trk>
<name>Trackpoints: <xsl:value-of select="substring(gpx:time,1,10)"/></name>
<extensions>
<gpxx:TrackExtension>
<xsl:choose>
<xsl:when test="position() mod 2 = 1">
<gpxx:DisplayColor>Magenta</gpxx:DisplayColor>
</xsl:when>
<xsl:otherwise>
<gpxx:DisplayColor>DarkGray</gpxx:DisplayColor>
</xsl:otherwise>
</xsl:choose>
</gpxx:TrackExtension>
</extensions>
<trkseg>
<xsl:for-each select="key('date',substring(gpx:time,1,10))">
<xsl:copy-of select="."/>
</xsl:for-each>
</trkseg>
</trk>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这篇关于GPX-Tracks中的交替颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!