-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdependencies.xsl
62 lines (52 loc) · 2.02 KB
/
dependencies.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
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:p="http://maven.apache.org/POM/4.0.0" xmlns:csv="csv:csv">
<xsl:output method="text"/>
<xsl:param name="delim" select="','" />
<xsl:param name="break" select="'
'" />
<csv:columns>
<column>groupId</column>
<column>artifactId</column>
<column>version</column>
<column>scope</column>
</csv:columns>
<xsl:template match="/">
<!-- Output the CSV header -->
<xsl:for-each select="document('')/*/csv:columns/*">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<xsl:value-of select="$delim"/>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="$break"/>
<xsl:apply-templates select="p:project/p:dependencies/p:dependency" />
</xsl:template>
<!-- Dependency Block -->
<xsl:template match="p:dependency">
<xsl:variable name="dependency" select="."/>
<!-- Loop csv columns -->
<xsl:for-each select="document('')/*/csv:columns/*">
<!-- get column -->
<xsl:variable name="column" select="."/>
<xsl:variable name="value" select="$dependency/*[name() = $column]"/>
<!-- Quote the value if required -->
<xsl:choose>
<xsl:when test="contains($value, '"')">
<xsl:variable name="x" select="replace($value, '"', '""')"/>
<xsl:value-of select="concat('"', $x, '"')"/>
</xsl:when>
<xsl:when test="contains($value, $delim)">
<xsl:value-of select="concat('"', $value, '"')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
<!-- Add the delimiter unless we are the last expression -->
<xsl:if test="position() != last()">
<xsl:value-of select="$delim"/>
</xsl:if>
</xsl:for-each>
<!-- Add a newline at the end -->
<xsl:value-of select="$break"/>
</xsl:template>
</xsl:stylesheet>