-
Notifications
You must be signed in to change notification settings - Fork 2
/
convert-html-report-to-json.xslt
54 lines (45 loc) · 1.35 KB
/
convert-html-report-to-json.xslt
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
<xsl:stylesheet version='2.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no" />
<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="/html">
{
"metricStatus": {
<xsl:for-each select="./table[1]">
<xsl:for-each select="./tr[./td]">
"<xsl:value-of select="./td[1]" />"
: { "status":
"<xsl:value-of select="normalize-space(./td[2])" />"
, "change":
<xsl:value-of select="number(replace(./td[3], '%', '')) div 100.0" />
}
<xsl:if test="not(position() = last())">, </xsl:if>
</xsl:for-each>
}
</xsl:for-each>
, "outliers": {
<xsl:for-each select="./table[2]">
<xsl:for-each select="./tr[./td]">
"<xsl:value-of select="./td[1]" />"
: {
<xsl:for-each select="./td[position() >= 2]">
<xsl:analyze-string regex="([^)]*)\(([^)]*)\)"
flags="ix" select=".">
<xsl:matching-substring>
"<xsl:value-of select="normalize-space(regex-group(1))" />"
:
<xsl:value-of select="regex-group(2)" />
</xsl:matching-substring>
</xsl:analyze-string>
<xsl:if test="not(position() = last())">, </xsl:if>
</xsl:for-each>
}
<xsl:if test="not(position() = last())">, </xsl:if>
</xsl:for-each>
</xsl:for-each>
}
}
</xsl:template>
</xsl:stylesheet>