-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eml-kieslijst.xslt
105 lines (105 loc) · 4.28 KB
/
eml-kieslijst.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
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
<?xml version="1.0" encoding="UTF-8"?>
<!--Author: Benjamin W. Broersma <[email protected]> -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:eml="urn:oasis:names:tc:evs:schema:eml"
xmlns="urn:oasis:names:tc:evs:schema:eml"
xmlns:ns2="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"
xmlns:ns3="urn:oasis:names:tc:ciq:xsdschema:xNL:2.0"
xmlns:ns4="http://www.w3.org/2000/09/xmldsig#"
xmlns:ns5="urn:oasis:names:tc:evs:schema:eml:ts"
xmlns:ns6="http://www.kiesraad.nl/extensions"
xmlns:ns7="http://www.kiesraad.nl/reportgenerator"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:oasis:names:tc:evs:schema:eml 230-candidatelist-v5-0.xsd http://www.kiesraad.nl/extensions kiesraad-eml-extensions.xsd">
<xsl:output omit-xml-declaration="yes" encoding="UTF-8"/>
<!--http://stackoverflow.com/a/7523245-->
<!--how this works: it checks if the text contains the replace search value, if not return text, else get substring-before+replacement+recursive call self with substring-after as text-->
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text"
select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="eml:EML">
{
<xsl:apply-templates select="eml:CandidateList/eml:Election"/>
}
</xsl:template>
<xsl:template match="eml:Election">
<xsl:apply-templates select="eml:ElectionIdentifier"/>
<xsl:apply-templates select="eml:Contest"/>
</xsl:template>
<xsl:template match="eml:ElectionIdentifier">
"code": "<xsl:value-of select="@Id"/>",
"naam": "<xsl:value-of select="eml:ElectionName"/>",
"categorie": "<xsl:value-of select="eml:ElectionCategory"/>",
"datum": "<xsl:value-of select="ns6:ElectionDate"/>",
</xsl:template>
<xsl:template match="eml:Contest">
<xsl:if test="eml:ContestIdentifier/@Id != 'geen'">
"kieskring": "<xsl:value-of select="eml:ContestIdentifier/@Id"/>",
</xsl:if>
"lijsten": [<xsl:apply-templates select="eml:Affiliation"/>]
</xsl:template>
<xsl:template match="eml:Affiliation">
{
"lijstnummer": <xsl:value-of select="eml:AffiliationIdentifier/@Id"/>,
"lijstnaam": "<xsl:call-template name="replace-string"><!--Yes this is needed!-->
<xsl:with-param name="text" select="eml:AffiliationIdentifier/eml:RegisteredName/text()"/>
<xsl:with-param name="replace" select="'"'" />
<xsl:with-param name="with" select="'\"'"/>
</xsl:call-template>",
<xsl:if test="ns6:ListData[@BelongsToCombination]">
"lijstverbinding": "<xsl:value-of select="ns6:ListData/@BelongsToCombination"/>",</xsl:if>
"kandidaten": [<xsl:apply-templates select="eml:Candidate"/>]
}<xsl:if test="position() != last()">,
</xsl:if>
</xsl:template>
<xsl:template match="eml:Candidate">
{
"kandidaatnummer": <xsl:value-of select="eml:CandidateIdentifier/@Id"/>,
<!-- "naam": { -->
<xsl:apply-templates select="eml:CandidateFullName/ns3:PersonName"/>
<!-- } -->,
"geslacht":
<xsl:choose>
<xsl:when test="eml:Gender/text() = 'male'">
"man"
</xsl:when>
<xsl:when test="eml:Gender/text() = 'female'">
"vrouw"
</xsl:when>
<xsl:otherwise>
"<xsl:value-of select="eml:Gender"/>"
</xsl:otherwise>
</xsl:choose>,
"woonplaats": "<xsl:value-of select="eml:QualifyingAddress/ns2:Locality/ns2:LocalityName"/>"
}<xsl:if test="position() != last()">,</xsl:if>
</xsl:template>
<xsl:template match="ns3:NameLine[@NameType='Initials']">
"initialen": "<xsl:value-of select="." />",
</xsl:template>
<xsl:template match="ns3:FirstName">
"voornaam": "<xsl:value-of select="." />",
</xsl:template>
<xsl:template match="ns3:NamePrefix">
"tussenvoegsel": "<xsl:value-of select="." />",
</xsl:template>
<xsl:template match="ns3:LastName">
"achternaam": "<xsl:value-of select="." />"
</xsl:template>
</xsl:stylesheet>