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 |
## Revision 1.2 2003/04/25 12:35:23 joko |
11 |
## added some pod |
## added some pod |
12 |
## revamped xsl |
## revamped xsl |
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). --> |
|
<xsl:template match="*"><xsl:call-template name="passthru" /></xsl:template> |
|
|
<xsl:template match="source"><xsl:call-template name="lock_context" /></xsl:template> |
|
|
|
|
|
<!-- 1. This is the passthru logic (copy all). --> |
|
113 |
<xsl:template name="passthru"><xsl:copy><xsl:apply-templates /></xsl:copy></xsl:template> |
<xsl:template name="passthru"><xsl:copy><xsl:apply-templates /></xsl:copy></xsl:template> |
114 |
|
<!-- 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 |
<!-- 2. This is the crud API. --> |
<!-- 2. This is the crud API. --> |
120 |
|
|
121 |
<!-- 2.a. The context finder. --> |
<!-- 2.a. The context finder. --> |
122 |
|
|
123 |
<xsl:template name="lock_context"> |
<!-- query part one: the node name --> |
124 |
|
<xsl:template match="source"> |
125 |
<xsl:choose> |
<xsl:choose> |
126 |
|
<!-- query part two: the attrib key and value --> |
127 |
<xsl:when test="@key=expekt"> |
<xsl:when test="@key=expekt"> |
128 |
<xsl:call-template name="inject_kay_motl" /> |
<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> |
</xsl:when> |
|
|
|
133 |
<xsl:otherwise> |
<xsl:otherwise> |
134 |
<xsl:call-template name="passthru_kay" /> |
<xsl:call-template name="passthru_kay" /> |
135 |
</xsl:otherwise> |
</xsl:otherwise> |
|
|
|
136 |
</xsl:choose> |
</xsl:choose> |
137 |
</xsl:template> |
</xsl:template> |
138 |
|
|
150 |
</xsl:template> |
</xsl:template> |
151 |
|
|
152 |
<xsl:template name="inject_kay_motl"> |
<xsl:template name="inject_kay_motl"> |
153 |
|
<xsl:param name="payload" /> |
154 |
|
<xsl:value-of select="$payload" /> |
155 |
<xsl:copy> |
<xsl:copy> |
156 |
<xsl:copy-of select="@*" /> |
<xsl:copy-of select="@*" /> |
157 |
<xsl:apply-templates /> |
<xsl:apply-templates /> |
165 |
</xsl:copy> |
</xsl:copy> |
166 |
</xsl:template> |
</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 |
|
|
178 |
|
<xsl:copy> |
179 |
|
<xsl:copy-of select="@*" /> |
180 |
|
<xsl:apply-templates /> |
181 |
|
|
182 |
|
<!-- crud action dispatcher --> |
183 |
|
<xsl:choose> |
184 |
|
<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> |
195 |
|
|
196 |
|
</xsl:template> |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
<!-- 2.c. The element manipulators: They mungle a specific element inside 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 |
<!-- TODO: let idx be passed in via "with-param" or s.th.l.th. --> |
<!-- TODO: let idx be passed in via "with-param" or s.th.l.th. --> |
209 |
<xsl:copy-of select="*[2]" /> |
<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 |
|
|