4 |
## $Id$ |
## $Id$ |
5 |
## ------------------------------------------------------------------------- |
## ------------------------------------------------------------------------- |
6 |
## $Log$ |
## $Log$ |
7 |
|
## Revision 1.3 2003/04/26 01:42:39 joko |
8 |
|
## first attempt to make up a crud template |
9 |
|
## |
10 |
|
## Revision 1.2 2003/04/25 12:35:23 joko |
11 |
|
## added some pod |
12 |
|
## revamped xsl |
13 |
|
## |
14 |
## Revision 1.1 2003/04/24 21:07:36 joko |
## Revision 1.1 2003/04/24 21:07:36 joko |
15 |
## initial commit |
## initial commit |
16 |
## |
## |
38 |
access to the XPath API in libxml2. |
access to the XPath API in libxml2. |
39 |
|
|
40 |
|
|
41 |
=head3 In short: |
=head3 Yet another xupdate - facts in short: |
42 |
|
|
43 |
S: It would be nice to have a pure perl thingy which does the same stuff.... |
S: It would be nice to have a pure perl thingy which does (almost) the same stuff.... |
44 |
|
|
45 |
Q: Can we achieve compliance with its API? (just a subset ....) |
Q: Can we achieve compliance with its (XML::XUpdate::LibXML) API? (just a subset ....) |
46 |
|
|
47 |
Q: Can we achieve the processing declared as a XSL document processed using CPAN's XML::XSLT? |
Q: Can we achieve the processing declared as a XSL document processed using CPAN's XML::XSLT? |
48 |
|
|
50 |
|
|
51 |
Q: Can we mimic/use the interface of the - already established - 'xupdate' program??? |
Q: Can we mimic/use the interface of the - already established - 'xupdate' program??? |
52 |
|
|
53 |
|
Q: Should we follow the CRUD path first? |
54 |
|
|
55 |
|
|
56 |
=cut |
=cut |
57 |
|
|
109 |
|
|
110 |
<xsl:output method="raw"/> |
<xsl:output method="raw"/> |
111 |
|
|
112 |
<!-- 0. The root node dispatcher. --> |
<!-- 1. This is the passthru logic (copy all untouched nodes). --> |
113 |
<xsl:template match="*"><xsl:call-template name="passthru"/></xsl:template> |
<xsl:template name="passthru"><xsl:copy><xsl:apply-templates /></xsl:copy></xsl:template> |
114 |
<!-- <xsl:template match="source"><xsl:call-template name="insertChildNode"/></xsl:template> --> |
<!-- activate this --> |
115 |
|
<xsl:template match="*"><xsl:call-template name="passthru" /></xsl:template> |
116 |
|
<!-- override some builtin rules: see http://www.w3.org/TR/xslt#built-in-rule --> |
117 |
|
<!-- <xsl:template match="comment()"><xsl:call-template name="passthru" /></xsl:template> --> |
118 |
|
|
119 |
<!-- 1. This is the passthru logic (copy all). --> |
<!-- 2. This is the crud API. --> |
|
<xsl:template name="passthru"><xsl:copy><xsl:apply-templates/></xsl:copy></xsl:template> |
|
120 |
|
|
121 |
<!-- 2. This is the manipulation logic: insertChildNode --> |
<!-- 2.a. The context finder. --> |
122 |
|
|
123 |
<!-- 2.a. The "API" method. --> |
<!-- query part one: the node name --> |
124 |
<xsl:template name="insertChildNode"> |
<xsl:template match="source"> |
125 |
|
<xsl:choose> |
126 |
|
<!-- query part two: the attrib key and value --> |
127 |
|
<xsl:when test="@key=expekt"> |
128 |
|
<xsl:call-template name="crud" > |
129 |
|
<xsl:with-param name="action">5</xsl:with-param> |
130 |
|
<xsl:with-param name="payload">------- payload -------</xsl:with-param> |
131 |
|
</xsl:call-template> |
132 |
|
</xsl:when> |
133 |
|
<xsl:otherwise> |
134 |
|
<xsl:call-template name="passthru_kay" /> |
135 |
|
</xsl:otherwise> |
136 |
|
</xsl:choose> |
137 |
|
</xsl:template> |
138 |
|
|
139 |
|
|
140 |
|
<!-- 2.b. The node manipulators: They translate the current context. --> |
141 |
|
|
142 |
|
<!-- by Mike Kay, Software AG [http://p2p.wrox.com/archive/xslt/2001-06/98.asp] --> |
143 |
|
<!-- enhancements & comments: Andreas Motl, rotamente.de --> |
144 |
|
<!-- <xsl:template match="source"> --> |
145 |
|
<xsl:template name="passthru_kay"> |
146 |
|
<xsl:copy> |
147 |
|
<xsl:copy-of select="@*" /> |
148 |
|
<xsl:apply-templates /> |
149 |
|
</xsl:copy> |
150 |
|
</xsl:template> |
151 |
|
|
152 |
|
<xsl:template name="inject_kay_motl"> |
153 |
|
<xsl:param name="payload" /> |
154 |
|
<xsl:value-of select="$payload" /> |
155 |
|
<xsl:copy> |
156 |
|
<xsl:copy-of select="@*" /> |
157 |
|
<xsl:apply-templates /> |
158 |
|
<!-- <xsl:apply-templates select="*[3]" /> --> |
159 |
|
<!-- <xsl:value-of select="text()" /> --> |
160 |
|
<!-- Multiple handlers here now: a) create fressshhhh element, b) clone s.th. --> |
161 |
|
<!-- TODO: Do switch/case or couple of if/then statements here to be able to handle that "at runtime". --> |
162 |
|
<xsl:call-template name="create_fresh_element" /> |
163 |
|
<xsl:call-template name="clone_last_element" /> |
164 |
|
<xsl:call-template name="clone_element_nr" /> |
165 |
|
</xsl:copy> |
166 |
|
</xsl:template> |
167 |
|
|
168 |
|
<xsl:template name="crud"> |
169 |
|
<xsl:param name="action" /> |
170 |
|
<xsl:param name="payload" /> |
171 |
|
action: <xsl:value-of select="$action" /> |
172 |
|
payload: <xsl:value-of select="$payload" /> |
173 |
|
|
174 |
|
<xsl:if test="$action=5"> |
175 |
|
CRUD: CREATE |
176 |
|
</xsl:if> |
177 |
|
|
|
<!-- manipulate node --> |
|
|
<xsl:comment> node - begin </xsl:comment> |
|
|
|
|
|
<!-- <xsl:copy-of select="source" /> --> |
|
178 |
<xsl:copy> |
<xsl:copy> |
179 |
|
<xsl:copy-of select="@*" /> |
|
<!-- Pass through children 1:1. --> |
|
180 |
<xsl:apply-templates /> |
<xsl:apply-templates /> |
181 |
|
|
182 |
<!-- Call one of the manipulators - this implements injection behavior. --> |
<!-- crud action dispatcher --> |
183 |
<xsl:call-template name="clone_last_element" /> |
<xsl:choose> |
184 |
<xsl:call-template name="inject_template" /> |
<xsl:when test="{$action}=5"> |
185 |
|
<!-- <xsl:when test="blah=\'blub\'"> --> |
186 |
|
CRUD: CREATE |
187 |
|
<xsl:call-template name="clone_last_element" /> |
188 |
|
</xsl:when> |
189 |
|
<xsl:otherwise> |
190 |
|
<xsl:comment> UNKOWN CRUD ACTION! </xsl:comment> |
191 |
|
</xsl:otherwise> |
192 |
|
</xsl:choose> |
193 |
|
|
194 |
</xsl:copy> |
</xsl:copy> |
195 |
<xsl:comment> node - end </xsl:comment> |
|
|
|
|
196 |
</xsl:template> |
</xsl:template> |
197 |
|
|
198 |
|
|
|
<!-- 2.b. The context finder. --> |
|
199 |
|
|
200 |
<!-- 2.c. The node manipulators: They mungle the current context. --> |
<!-- 2.c. The element manipulators: They mungle a specific element inside the current context. --> |
201 |
|
|
202 |
<!-- copy over node 1:1 (use last element as a template) --> |
<!-- copy over node 1:1 (use last element as a template) --> |
203 |
<xsl:template name="clone_last_element"> |
<xsl:template name="clone_last_element"> |
204 |
<xsl:copy-of select="*[last()]" /> |
<xsl:copy-of select="*[last()]" /> |
205 |
</xsl:template> |
</xsl:template> |
206 |
|
|
207 |
<xsl:template name="clone_element_nr"> |
<xsl:template name="clone_element_nr"> |
208 |
<xsl:copy-of select="*[last()]" /> |
<!-- TODO: let idx be passed in via "with-param" or s.th.l.th. --> |
209 |
|
<xsl:copy-of select="*[2]" /> |
210 |
</xsl:template> |
</xsl:template> |
211 |
|
|
212 |
<!-- creates instance of new element --> |
<!-- creates instance of new element --> |
213 |
<xsl:template name="create_fresh_element"> |
<xsl:template name="create_fresh_element"> |
214 |
<xsl:element name="new">content</xsl:element> |
<xsl:element name="new">content</xsl:element> |
215 |
</xsl:template> |
</xsl:template> |
216 |
|
|
217 |
|
|
222 |
</xsl:template> |
</xsl:template> |
223 |
|
|
224 |
|
|
|
<!-- Fine stuff from others. --> |
|
225 |
|
|
226 |
<!-- by Mike Kay, Software AG [http://p2p.wrox.com/archive/xslt/2001-06/98.asp] --> |
|
227 |
<!-- enhancements & comments: Andreas Motl, rotamente.de --> |
<!-- 0. The root node dispatcher. --> |
228 |
<xsl:template match="source"> |
<!-- <xsl:template match="source"><xsl:call-template name="insertChildNode"/></xsl:template> --> |
229 |
|
|
230 |
|
<!-- 2. This is the manipulation logic: insertChildNode --> |
231 |
|
|
232 |
|
<!-- 2.a. The "API" method. - now deprecated --> |
233 |
|
<xsl:template name="insertChildNode"> |
234 |
|
|
235 |
|
<!-- manipulate node --> |
236 |
|
<xsl:comment> node - begin </xsl:comment> |
237 |
|
|
238 |
|
<!-- <xsl:copy-of select="source" /> --> |
239 |
<xsl:copy> |
<xsl:copy> |
240 |
<xsl:copy-of select="@*" /> |
|
241 |
|
<!-- Pass through children 1:1. --> |
242 |
<xsl:apply-templates /> |
<xsl:apply-templates /> |
243 |
<!-- multiple handlers here now: a) create fressshhhh element, b) clone s.th. --> |
|
244 |
<!-- TODO: Do switch/case or couple of if/then statements here to be able to handle that "at runtime". --> |
<!-- Call one of the manipulators - this implements injection behavior. --> |
|
<xsl:call-template name="create_fresh_element" /> |
|
245 |
<xsl:call-template name="clone_last_element" /> |
<xsl:call-template name="clone_last_element" /> |
246 |
</xsl:copy> |
<xsl:call-template name="inject_template" /> |
247 |
|
|
248 |
|
</xsl:copy> |
249 |
|
<xsl:comment> node - end </xsl:comment> |
250 |
|
|
251 |
</xsl:template> |
</xsl:template> |
252 |
|
|
253 |
|
|