-
Notifications
You must be signed in to change notification settings - Fork 7
/
nike+totcx.xsl
113 lines (87 loc) · 3.99 KB
/
nike+totcx.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd"
xmlns:ns5="http://www.garmin.com/xmlschemas/ActivityGoals/v1"
xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2"
xmlns:ns2="http://www.garmin.com/xmlschemas/UserProfile/v2"
xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns4="http://www.garmin.com/xmlschemas/ProfileExtension/v1"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date"
>
<!-- EXSLT (http://www.exslt.org/) template is needed for date-time calculations and can be downloaded from
http://www.exslt.org/date/functions/add/date.add.template.xsl -->
<xsl:import href="date.add.template.xsl"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="plusService">
<xsl:apply-templates select="sportsData"/>
</xsl:template>
<xsl:template match="sportsData">
<TrainingCenterDatabase>
<Activities>
<Activity Sport="Running">
<Id>
<xsl:value-of select="startTime"/>
</Id>
<Lap>
<xsl:attribute name="StartTime">
<xsl:value-of select="startTime"/>
</xsl:attribute>
<xsl:variable name="st">
<xsl:value-of select="startTime"/>
</xsl:variable>
<TotalTimeSeconds><xsl:value-of select="runSummary/duration div 1000"/> </TotalTimeSeconds>
<DistanceMeters><xsl:value-of select="runSummary/distance * 1000"/></DistanceMeters>
<Calories><xsl:value-of select="runSummary/calories"/></Calories>
<Track>
<xsl:choose>
<xsl:when test="extendedDataList/extendedData[@dataType='distance' and @intervalType='time' and @intervalUnit='s']">
<xsl:variable name="formatted_interval">PT10S</xsl:variable>
<xsl:call-template name="distance_point">
<xsl:with-param name="csvdata" select="extendedDataList/extendedData[@dataType='distance' and @intervalType='time' and @intervalUnit='s']"/>
<xsl:with-param name="interval" select="$formatted_interval"/>
<xsl:with-param name="time" select="$st"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</Track>
</Lap>
</Activity>
</Activities>
</TrainingCenterDatabase>
</xsl:template>
<!-- Recursive template to extract sample data -->
<xsl:template name="distance_point">
<xsl:param name="csvdata"/>
<xsl:param name="interval"/>
<xsl:param name="time" select="."/>
<xsl:choose>
<xsl:when test="contains($csvdata, ',')">
<Trackpoint>
<DistanceMeters><xsl:value-of select="number(substring-before($csvdata, ',')) * 1000"/></DistanceMeters>
<Time><xsl:value-of select="$time"/></Time>
</Trackpoint>
<xsl:variable name="new_time" >
<xsl:call-template name="date:add">
<xsl:with-param name="date-time" select="$time" />
<xsl:with-param name="duration" select="$interval" />
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="distance_point">
<xsl:with-param name="csvdata" select="substring-after($csvdata, ',')"/>
<xsl:with-param name="interval" select="$interval"/>
<xsl:with-param name="time" select="$new_time"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<Trackpoint>
<DistanceMeters><xsl:value-of select="number($csvdata)*1000"/></DistanceMeters>
<Time><xsl:value-of select="$time"/></Time>
</Trackpoint>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>