-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteroperator.xpl
More file actions
211 lines (185 loc) · 6.83 KB
/
interoperator.xpl
File metadata and controls
211 lines (185 loc) · 6.83 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<p:declare-step version="1.0"
name="interoperator"
xmlns:p="http://www.w3.org/ns/xproc"
xmlns:iop="http://transpect.io/iop"
xmlns:mox="http://www.xml-project.com/morgana"
xmlns:mod="http://www.xml-project.com/nasp/debug"
xmlns:cx="http://xmlcalabash.com/ns/extensions"
exclude-inline-prefixes="iop mox mod cx">
<p:output port="status" />
<p:option name="pipelineuri" required="true"/>
<p:serialization port="status" indent="true" />
<p:import href="com.xml_project.morganaxproc.debugsteps.DebugSteps" mox:content-type="application/java-archive" />
<!-- IOP:MODIFY-PIPELINE -->
<p:declare-step type="iop:modify-pipeline">
<!-- Here is where the actual work is done -->
<p:input port="source" />
<p:output port="result" />
<!-- make import of XML Calabash extension library conditional, if it is not already! -->
<p:add-attribute match="p:import[@href='http://xmlcalabash.com/extension/steps/library-1.0.xpl' and not(@use-when)]"
attribute-name="use-when"
attribute-value="p:system-property('p:product-name') = 'XML Calabash'" />
<!-- add mox:depends-on for steps with cx:depends-on -->
<p:viewport match="//*[@cx:depends-on and not(@mox:depends-on)]">
<p:add-attribute match="/">
<p:with-option name="attribute-name" select="'mox:depends-on'" />
<p:with-option name="attribute-value" select="/*/@cx:depends-on" />
</p:add-attribute>
</p:viewport>
<!-- rename cx:message to iop:message -->
<p:rename match="cx:message"
new-name="message"
new-prefix="iop"
new-namespace="http://transpect.io/iop"
xmlns:cx="http://xmlcalabash.com/ns/extensions" />
<!-- rename cx:eval to iop:eval -->
<p:rename match="cx:eval"
new-name="eval"
new-prefix="iop"
new-namespace="http://transpect.io/iop"
xmlns:cx="http://xmlcalabash.com/ns/extensions" />
<!-- rename cx:zip to pxp:zip -->
<p:rename match="cx:zip"
new-name="zip"
new-prefix="pxp"
new-namespace="http://exproc.org/proposed/steps"
xmlns:cx="http://xmlcalabash.com/ns/extensions" />
<!-- Make sure, 'http://exproc.org/proposed/steps/file' is used as namespace for steps in http://exproc.org/proposed/steps/file
This is necessary, because XML Calabash uses both namespaces for EXProc.org's file utility library
-->
<p:namespace-rename from="http://xmlcalabash.com/ns/extensions/fileutils" to="http://exproc.org/proposed/steps/file" apply-to="elements" />
<!-- Now import pipelines if needed -->
<!-- First: "http://transpect.io/iop/iop.xpl" -->
<p:choose>
<p:when test="//iop:* and not(//p:import/@href='http://transpect.io/iop/iop.xpl')">
<p:insert match="p:import[last()]" position="after">
<p:input port="insertion">
<p:inline>
<p:import href="http://transpect.io/iop/iop.xpl" />
</p:inline>
</p:input>
</p:insert>
</p:when>
<p:otherwise>
<p:identity />
</p:otherwise>
</p:choose>
<!-- Second: http://exproc.org/proposed/steps/os -->
<p:choose>
<p:when test="//pos:* and not(//p:import/@href='http://exproc.org/proposed/steps/os')">
<p:insert match="p:import[last()]" position="after">
<p:input port="insertion">
<p:inline>
<p:import href="http://exproc.org/proposed/steps/os" use-when="p:system-property('p:product-name') = 'MorganaXProc'" />
</p:inline>
</p:input>
</p:insert>
</p:when>
<p:otherwise>
<p:identity />
</p:otherwise>
</p:choose>
<!-- Third: http://exproc.org/proposed/steps/file -->
<p:choose>
<p:when test="//pxf:* and not(//p:import/@href='http://exproc.org/proposed/steps/file')">
<p:insert match="p:import[last()]" position="after">
<p:input port="insertion">
<p:inline>
<p:import href="http://exproc.org/proposed/steps/file" use-when="p:system-property('p:product-name') = 'MorganaXProc'" />
</p:inline>
</p:input>
</p:insert>
</p:when>
<p:otherwise>
<p:identity />
</p:otherwise>
</p:choose>
<!-- Fourth: http://exproc.org/proposed/steps -->
<p:choose>
<p:when test="//pxp:* and not(//p:import/@href='http://exproc.org/proposed/steps')">
<p:insert match="p:import[last()]" position="after">
<p:input port="insertion">
<p:inline>
<p:import href="http://exproc.org/proposed/steps" use-when="p:system-property('p:product-name') = 'MorganaXProc'" />
</p:inline>
</p:input>
</p:insert>
</p:when>
<p:otherwise>
<p:identity />
</p:otherwise>
</p:choose>
</p:declare-step>
<!-- IOP:PROCESS-PIPELINE -->
<p:declare-step type="iop:process-pipeline">
<p:output port="status" />
<p:option name="pipelineuri" required="true" />
<p:try>
<p:group>
<mod:report>
<p:input port="source"> <p:empty /></p:input>
<p:with-option name="message" select="concat('Processing: ', $pipelineuri)" />
</mod:report>
<p:load name="pipeline-loader">
<p:with-option name="href" select="$pipelineuri" />
</p:load>
<!-- handle imports recursivly -->
<p:for-each>
<p:iteration-source select="/p:declare-step/p:import | p:pipeline/p:import | p:library/p:import">
<p:pipe step="pipeline-loader" port="result" />
</p:iteration-source>
<p:variable name="thePipelineUri" select="resolve-uri(/p:import/@href, base-uri())" />
<p:choose>
<p:when test="not(starts-with($thePipelineUri,'http://xmlcalabash.com')) and
not(starts-with($thePipelineUri,'http://exproc.org')) and
compare($thePipelineUri,'http://transpect.io/iop/iop.xpl') != 0">
<iop:process-pipeline>
<p:with-option name="pipelineuri" select="$thePipelineUri" />
</iop:process-pipeline>
</p:when>
<p:otherwise>
<p:identity>
<p:input port="source">
<p:inline>
<dummy />
</p:inline>
</p:input>
</p:identity>
</p:otherwise>
</p:choose>
</p:for-each>
<p:sink />
<!-- change the pipeline -->
<iop:modify-pipeline>
<p:input port="source">
<p:pipe step="pipeline-loader" port="result"/>
</p:input>
</iop:modify-pipeline>
<!-- now store it -->
<p:store indent="true">
<p:with-option name="href" select="./base-uri()" />
</p:store>
<!-- Successful: Create result -->
<p:identity>
<p:input port="source">
<p:inline>
<done />
</p:inline>
</p:input>
</p:identity>
</p:group>
<p:catch name="catcher">
<p:identity>
<p:input port="source">
<p:pipe step="catcher" port="error" />
</p:input>
</p:identity>
<mod:report message="error on import" write-source="true" />
</p:catch>
</p:try>
</p:declare-step>
<!-- Main subpipeline -->
<iop:process-pipeline>
<p:with-option name="pipelineuri" select="$pipelineuri" />
</iop:process-pipeline>
</p:declare-step>