-
Notifications
You must be signed in to change notification settings - Fork 1
/
fizzbuzz.xpl
80 lines (80 loc) · 2.94 KB
/
fizzbuzz.xpl
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
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step"
xmlns:ix="http://www.innovimax.fr/ns"
version="1.0" exclude-inline-prefixes="c ix">
<p:documentation>
<p>(c) Innovimax/Mohamed ZERGAOUI 2012-2017 - The fizzbuzz XProc</p>
</p:documentation>
<p:output port="result"/>
<p:declare-step name="replicate" type="ix:replicate">
<p:input port="source" sequence="true">
<p:documentation>The sequence of document you want to replicate</p:documentation>
</p:input>
<p:output port="result" sequence="true">
<p:documentation>The output where the replicate sequence will be provided</p:documentation>
</p:output>
<p:option name="count">
<p:documentation>The number of time you want to replicate</p:documentation>
</p:option>
<p:choose>
<p:when test="$count < 1">
<p:identity>
<p:input port="source">
<p:empty/>
</p:input>
</p:identity>
</p:when>
<p:when test="$count = 1">
<p:identity>
<p:input port="source">
<p:pipe port="source" step="replicate"/>
</p:input>
</p:identity>
</p:when>
<p:otherwise>
<ix:replicate name="tail">
<p:input port="source">
<p:pipe port="source" step="replicate"/>
</p:input>
<p:with-option name="count" select="$count - 1"/>
</ix:replicate>
<p:identity>
<p:input port="source">
<p:pipe port="source" step="replicate"/>
<p:pipe port="result" step="tail"/>
</p:input>
</p:identity>
</p:otherwise>
</p:choose>
</p:declare-step>
<ix:replicate>
<p:documentation>First, we create a list of item</p:documentation>
<p:input port="source">
<p:inline><item/></p:inline>
</p:input>
<p:with-option name="count" select="100"/>
</ix:replicate>
<p:for-each name="fill">
<p:documentation>...then we fill it...</p:documentation>
<p:choose>
<p:when test="p:iteration-position() mod (3 * 5) = 0">
<p:add-attribute match="/item" attribute-name="value" attribute-value="fizzbuzz"/>
</p:when>
<p:when test="p:iteration-position() mod 5 = 0">
<p:add-attribute match="/item" attribute-name="value" attribute-value="buzz"/>
</p:when>
<p:when test="p:iteration-position() mod 3 = 0">
<p:add-attribute match="/item" attribute-name="value" attribute-value="fizz"/>
</p:when>
<p:otherwise>
<p:add-attribute match="/item" attribute-name="value">
<p:with-option name="attribute-value" select="p:iteration-position()"/>
</p:add-attribute>
</p:otherwise>
</p:choose>
</p:for-each>
<p:wrap-sequence wrapper="list">
<p:documentation>...and then we wrapp it. Done!</p:documentation>
</p:wrap-sequence>
</p:declare-step>