paulb@1 | 1 | #!/usr/bin/env python |
paulb@1 | 2 | |
paulb@1 | 3 | """ |
paulb@1 | 4 | XSL-based form templating. |
paulb@116 | 5 | |
paulb@116 | 6 | Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk> |
paulb@116 | 7 | |
paulb@116 | 8 | This library is free software; you can redistribute it and/or |
paulb@116 | 9 | modify it under the terms of the GNU Lesser General Public |
paulb@116 | 10 | License as published by the Free Software Foundation; either |
paulb@116 | 11 | version 2.1 of the License, or (at your option) any later version. |
paulb@116 | 12 | |
paulb@116 | 13 | This library is distributed in the hope that it will be useful, |
paulb@116 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paulb@116 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
paulb@116 | 16 | Lesser General Public License for more details. |
paulb@116 | 17 | |
paulb@116 | 18 | You should have received a copy of the GNU Lesser General Public |
paulb@116 | 19 | License along with this library; if not, write to the Free Software |
paulb@116 | 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
paulb@1 | 21 | """ |
paulb@1 | 22 | |
paulb@16 | 23 | import Constants |
paulb@66 | 24 | import libxsltmod, libxml2mod |
paulb@66 | 25 | import libxml2dom |
paulb@213 | 26 | import urllib |
paulb@1 | 27 | |
paulb@23 | 28 | def path_to_node(node, attribute_ref, name, multivalue=0): |
paulb@1 | 29 | |
paulb@9 | 30 | """ |
paulb@16 | 31 | Generate an XSLForms path to the given 'node', producing an attribute |
paulb@16 | 32 | reference if 'attribute_ref' is true; for example: |
paulb@16 | 33 | |
paulb@139 | 34 | /package$1/discriminators$5/discriminator$1/category |
paulb@16 | 35 | |
paulb@16 | 36 | Otherwise an element reference is produced; for example: |
paulb@16 | 37 | |
paulb@139 | 38 | /package$1/discriminators$5/discriminator$1 |
paulb@16 | 39 | |
paulb@16 | 40 | Use the given 'name' to complete the path if an attribute reference is |
paulb@16 | 41 | required (and if a genuine attribute is found at the context node - |
paulb@16 | 42 | otherwise 'name' will be None and the context node will be treated like an |
paulb@16 | 43 | attribute). |
paulb@23 | 44 | |
paulb@156 | 45 | If 'multivalue' is true and 'attribute_ref' is set, produce an attribute |
paulb@156 | 46 | reference using the given 'name': |
paulb@23 | 47 | |
paulb@139 | 48 | /package$1/categories$1/category$$name |
paulb@156 | 49 | |
paulb@156 | 50 | If 'multivalue' is true and 'attribute_ref' is not set, produce an attribute |
paulb@156 | 51 | reference using the given 'name' of form (element, attribute): |
paulb@156 | 52 | |
paulb@156 | 53 | /package$1/categories$1/element$$attribute |
paulb@9 | 54 | """ |
paulb@1 | 55 | |
paulb@1 | 56 | l = [] |
paulb@6 | 57 | # Skip attribute reference. |
paulb@66 | 58 | if node.nodeType == node.ATTRIBUTE_NODE: |
paulb@66 | 59 | node = node.parentNode |
paulb@9 | 60 | # Manually insert the attribute name if defined. |
paulb@16 | 61 | if attribute_ref: |
paulb@23 | 62 | # A real attribute is referenced. |
paulb@16 | 63 | if name is not None: |
paulb@16 | 64 | l.insert(0, name) |
paulb@23 | 65 | if multivalue: |
paulb@49 | 66 | l.insert(0, Constants.multi_separator) |
paulb@66 | 67 | l.insert(0, node.nodeName) |
paulb@66 | 68 | node = node.parentNode |
paulb@16 | 69 | l.insert(0, Constants.path_separator) |
paulb@23 | 70 | # Otherwise, treat the element name as an attribute name. |
paulb@156 | 71 | # NOTE: Not sure how useful this is. |
paulb@16 | 72 | else: |
paulb@66 | 73 | l.insert(0, node.nodeName) |
paulb@16 | 74 | l.insert(0, Constants.path_separator) |
paulb@66 | 75 | node = node.parentNode |
paulb@156 | 76 | # Otherwise insert any multivalue references (eg. list-attribute). |
paulb@156 | 77 | elif multivalue: |
paulb@156 | 78 | element_name, attribute_name = name |
paulb@156 | 79 | l.insert(0, attribute_name) |
paulb@156 | 80 | l.insert(0, Constants.multi_separator) |
paulb@156 | 81 | l.insert(0, element_name) |
paulb@156 | 82 | l.insert(0, Constants.path_separator) |
paulb@156 | 83 | |
paulb@1 | 84 | # Element references. |
paulb@66 | 85 | while node is not None and node.nodeType != node.DOCUMENT_NODE: |
paulb@66 | 86 | l.insert(0, str(int(node.xpath("count(preceding-sibling::*) + 1")))) |
paulb@16 | 87 | l.insert(0, Constants.pair_separator) |
paulb@66 | 88 | l.insert(0, node.nodeName) |
paulb@16 | 89 | l.insert(0, Constants.path_separator) |
paulb@66 | 90 | node = node.parentNode |
paulb@1 | 91 | return "".join(l) |
paulb@1 | 92 | |
paulb@23 | 93 | def path_to_context(context, attribute_ref, multivalue_name=None): |
paulb@1 | 94 | |
paulb@1 | 95 | """ |
paulb@1 | 96 | As a libxslt extension function, return a string containing the XSLForms |
paulb@9 | 97 | path to the 'context' node, using the special "this-name" variable to |
paulb@16 | 98 | complete the path if an attribute reference is required (as indicated by |
paulb@23 | 99 | 'attribute_ref' being set to true). If 'multivalue_name' is set, produce a |
paulb@23 | 100 | reference to a multivalued field using the given string as the attribute |
paulb@23 | 101 | name. |
paulb@1 | 102 | """ |
paulb@1 | 103 | |
paulb@66 | 104 | context = libxml2mod.xmlXPathParserGetContext(context) |
paulb@66 | 105 | transform_context = libxsltmod.xsltXPathGetTransformContext(context) |
paulb@66 | 106 | name_var = libxsltmod.xsltVariableLookup(transform_context, "this-name", None) |
paulb@23 | 107 | if multivalue_name is not None: |
paulb@23 | 108 | name = multivalue_name |
paulb@23 | 109 | multivalue = 1 |
paulb@23 | 110 | elif name_var is not None: |
paulb@67 | 111 | name = libxml2mod.xmlNodeGetContent(name_var[0]) |
paulb@213 | 112 | name = unicode(name, "utf-8") |
paulb@23 | 113 | multivalue = 0 |
paulb@9 | 114 | else: |
paulb@9 | 115 | name = None |
paulb@23 | 116 | multivalue = 0 |
paulb@66 | 117 | node = libxml2dom.Node(libxml2mod.xmlXPathGetContextNode(context)) |
paulb@23 | 118 | return path_to_node(node, attribute_ref, name, multivalue) |
paulb@16 | 119 | |
paulb@178 | 120 | # Exposed extension functions. |
paulb@178 | 121 | |
paulb@178 | 122 | def this_element(context): |
paulb@178 | 123 | |
paulb@178 | 124 | """ |
paulb@178 | 125 | Exposed as {template:this-element()}. |
paulb@382 | 126 | |
paulb@178 | 127 | Provides a reference to the current element in the form data structure. |
paulb@178 | 128 | """ |
paulb@178 | 129 | |
paulb@178 | 130 | #print "this_element" |
paulb@66 | 131 | r = path_to_context(context, 0) |
paulb@66 | 132 | return r.encode("utf-8") |
paulb@16 | 133 | |
paulb@178 | 134 | def this_attribute(context): |
paulb@178 | 135 | |
paulb@178 | 136 | """ |
paulb@178 | 137 | Exposed as {template:this-attribute()}. |
paulb@382 | 138 | |
paulb@178 | 139 | Provides a reference to the current attribute in the form data structure. |
paulb@178 | 140 | """ |
paulb@178 | 141 | |
paulb@178 | 142 | #print "this_attribute" |
paulb@66 | 143 | r = path_to_context(context, 1) |
paulb@66 | 144 | return r.encode("utf-8") |
paulb@1 | 145 | |
paulb@178 | 146 | def new_attribute(context, name): |
paulb@23 | 147 | |
paulb@178 | 148 | """ |
paulb@178 | 149 | Exposed as {template:new-attribute(name)}. |
paulb@382 | 150 | |
paulb@178 | 151 | Provides a reference to a new attribute of the given 'name' on the current |
paulb@178 | 152 | element in the form data structure. |
paulb@178 | 153 | """ |
paulb@178 | 154 | |
paulb@178 | 155 | #print "new_attribute" |
paulb@213 | 156 | name = unicode(name, "utf-8") |
paulb@66 | 157 | r = path_to_context(context, 0) + "/" + name |
paulb@66 | 158 | return r.encode("utf-8") |
paulb@34 | 159 | |
paulb@178 | 160 | def other_elements(context, nodes): |
paulb@178 | 161 | |
paulb@178 | 162 | """ |
paulb@178 | 163 | Exposed as {template:other-elements(nodes)}. |
paulb@382 | 164 | |
paulb@178 | 165 | Provides a reference to other elements in the form data structure according |
paulb@178 | 166 | to the specified 'nodes' parameter (an XPath expression in the template). |
paulb@178 | 167 | """ |
paulb@178 | 168 | |
paulb@178 | 169 | #print "other_elements" |
paulb@57 | 170 | names = [] |
paulb@57 | 171 | for node in nodes: |
paulb@66 | 172 | name = path_to_node(libxml2dom.Node(node), 0, None, 0) |
paulb@57 | 173 | if name not in names: |
paulb@57 | 174 | names.append(name) |
paulb@66 | 175 | r = ",".join(names) |
paulb@66 | 176 | return r.encode("utf-8") |
paulb@49 | 177 | |
paulb@178 | 178 | def list_attribute(context, element_name, attribute_name): |
paulb@178 | 179 | |
paulb@178 | 180 | """ |
paulb@178 | 181 | Exposed as {template:list-attribute(element_name, attribute_name)}. |
paulb@382 | 182 | |
paulb@178 | 183 | Provides a reference to one or many elements of the given 'element_name' |
paulb@178 | 184 | found under the current element in the form data structure having |
paulb@178 | 185 | attributes with the given 'attribute_name'. |
paulb@178 | 186 | """ |
paulb@178 | 187 | |
paulb@178 | 188 | #print "list_attribute" |
paulb@213 | 189 | element_name = unicode(element_name, "utf-8") |
paulb@213 | 190 | attribute_name = unicode(attribute_name, "utf-8") |
paulb@178 | 191 | r = path_to_context(context, 0, (element_name, attribute_name)) |
paulb@178 | 192 | return r.encode("utf-8") |
paulb@178 | 193 | |
paulb@178 | 194 | def other_list_attributes(context, element_name, attribute_name, nodes): |
paulb@178 | 195 | |
paulb@178 | 196 | """ |
paulb@178 | 197 | Exposed as {template:other-list-attributes(element_name, attribute_name, nodes)}. |
paulb@382 | 198 | |
paulb@178 | 199 | Provides a reference to other elements in the form data structure, found |
paulb@178 | 200 | under the specified 'nodes' (described using an XPath expression in the |
paulb@178 | 201 | template) having the given 'element_name' and bearing attributes of the |
paulb@178 | 202 | given 'attribute_name'. |
paulb@178 | 203 | """ |
paulb@178 | 204 | |
paulb@178 | 205 | #print "other_list_attributes" |
paulb@213 | 206 | element_name = unicode(element_name, "utf-8") |
paulb@213 | 207 | attribute_name = unicode(attribute_name, "utf-8") |
paulb@178 | 208 | names = [] |
paulb@178 | 209 | for node in nodes: |
paulb@178 | 210 | name = path_to_node(libxml2dom.Node(node), 0, (element_name, attribute_name), 1) |
paulb@178 | 211 | if name not in names: |
paulb@178 | 212 | names.append(name) |
paulb@178 | 213 | r = ",".join(names) |
paulb@178 | 214 | return r.encode("utf-8") |
paulb@178 | 215 | |
paulb@178 | 216 | def other_attributes(context, attribute_name, nodes): |
paulb@178 | 217 | |
paulb@178 | 218 | """ |
paulb@178 | 219 | Exposed as {template:other-attributes(name, nodes)}. |
paulb@382 | 220 | |
paulb@178 | 221 | Provides a reference to attributes in the form data structure of the given |
paulb@178 | 222 | 'attribute_name' residing on the specified 'nodes' (described using an XPath |
paulb@178 | 223 | expression in the template). |
paulb@178 | 224 | """ |
paulb@178 | 225 | |
paulb@178 | 226 | #print "other_attributes" |
paulb@213 | 227 | attribute_name = unicode(attribute_name, "utf-8") |
paulb@178 | 228 | # NOTE: Cannot directly reference attributes in the nodes list because |
paulb@178 | 229 | # NOTE: libxml2dom does not yet support parent element discovery on |
paulb@178 | 230 | # NOTE: attributes. |
paulb@178 | 231 | names = [] |
paulb@178 | 232 | for node in nodes: |
paulb@178 | 233 | name = path_to_node(libxml2dom.Node(node), 1, attribute_name, 0) |
paulb@178 | 234 | if name not in names: |
paulb@178 | 235 | names.append(name) |
paulb@178 | 236 | r = ",".join(names) |
paulb@178 | 237 | return r.encode("utf-8") |
paulb@178 | 238 | |
paulb@178 | 239 | def child_element(context, element_name, position, node_paths): |
paulb@178 | 240 | |
paulb@178 | 241 | """ |
paulb@178 | 242 | Exposed as {template:child-element(element_name, position, node_paths)}. |
paulb@382 | 243 | |
paulb@178 | 244 | Provides relative paths to the specifed 'element_name', having the given |
paulb@178 | 245 | 'position' (1-based) under each element specified in 'node_paths' (provided |
paulb@178 | 246 | by calls to other extension functions in the template). For example: |
paulb@178 | 247 | |
paulb@178 | 248 | template:child-element('comment', 1, template:this-element()) -> '.../comment$1' |
paulb@178 | 249 | """ |
paulb@178 | 250 | |
paulb@213 | 251 | element_name = unicode(element_name, "utf-8") |
paulb@178 | 252 | l = [] |
paulb@178 | 253 | for node_path in node_paths.split(","): |
paulb@178 | 254 | l.append(node_path + Constants.path_separator + element_name |
paulb@178 | 255 | + Constants.pair_separator + str(int(position))) |
paulb@178 | 256 | return ",".join(l).encode("utf-8") |
paulb@178 | 257 | |
paulb@178 | 258 | def child_attribute(context, attribute_name, node_paths): |
paulb@178 | 259 | |
paulb@178 | 260 | """ |
paulb@178 | 261 | Exposed as {template:child-attribute(attribute_name, node_paths)}. |
paulb@382 | 262 | |
paulb@178 | 263 | Provides a relative path to the specifed 'attribute_name' for each element |
paulb@178 | 264 | specified in 'node_paths' (provided by calls to other extension functions in |
paulb@178 | 265 | the template). For example: |
paulb@178 | 266 | |
paulb@178 | 267 | template:child-attribute('value', template:this-element()) -> '.../value' |
paulb@178 | 268 | """ |
paulb@178 | 269 | |
paulb@213 | 270 | attribute_name = unicode(attribute_name, "utf-8") |
paulb@178 | 271 | l = [] |
paulb@178 | 272 | for node_path in node_paths.split(","): |
paulb@178 | 273 | l.append(node_path + Constants.path_separator + attribute_name) |
paulb@178 | 274 | return ",".join(l).encode("utf-8") |
paulb@178 | 275 | |
paulb@301 | 276 | def selector_name(context, field_name, nodes): |
paulb@301 | 277 | |
paulb@301 | 278 | """ |
paulb@301 | 279 | Exposed as {template:selector-name(field_name, nodes)}. |
paulb@382 | 280 | |
paulb@301 | 281 | Provides a selector field name defined using 'field_name' and referring to |
paulb@301 | 282 | the given 'nodes'. For example: |
paulb@301 | 283 | |
paulb@301 | 284 | template:selector-name('add-platform', package/platforms) -> 'add-platform=/package$1/platforms$1' |
paulb@301 | 285 | |
paulb@301 | 286 | NOTE: The 'nodes' must be element references. |
paulb@301 | 287 | """ |
paulb@301 | 288 | |
paulb@301 | 289 | #print "selector_name" |
paulb@301 | 290 | names = [] |
paulb@301 | 291 | for node in nodes: |
paulb@301 | 292 | name = path_to_node(libxml2dom.Node(node), 0, None, 0) |
paulb@301 | 293 | if name not in names: |
paulb@301 | 294 | names.append(field_name + "=" + name) |
paulb@301 | 295 | r = ",".join(names) |
paulb@301 | 296 | return r.encode("utf-8") |
paulb@301 | 297 | |
paulb@178 | 298 | # Old implementations. |
paulb@178 | 299 | |
paulb@178 | 300 | def multi_field_name(context, multivalue_name): |
paulb@178 | 301 | #print "multi_field_name" |
paulb@213 | 302 | multivalue_name = unicode(multivalue_name, "utf-8") |
paulb@178 | 303 | r = path_to_context(context, 1, multivalue_name) |
paulb@178 | 304 | return r.encode("utf-8") |
paulb@178 | 305 | |
paulb@57 | 306 | def other_multi_field_names(context, multivalue_name, nodes): |
paulb@67 | 307 | #print "other_multi_field_names" |
paulb@213 | 308 | multivalue_name = unicode(multivalue_name, "utf-8") |
paulb@57 | 309 | names = [] |
paulb@57 | 310 | for node in nodes: |
paulb@66 | 311 | name = path_to_node(libxml2dom.Node(node), 1, multivalue_name, 1) |
paulb@57 | 312 | if name not in names: |
paulb@57 | 313 | names.append(name) |
paulb@66 | 314 | r = ",".join(names) |
paulb@66 | 315 | return r.encode("utf-8") |
paulb@49 | 316 | |
paulb@213 | 317 | # Utility functions. |
paulb@213 | 318 | |
paulb@213 | 319 | def url_encode(context, nodes, charset="utf-8"): |
paulb@213 | 320 | |
paulb@213 | 321 | """ |
paulb@213 | 322 | Exposed as {template:url-encode(nodes)}. |
paulb@382 | 323 | |
paulb@213 | 324 | Provides a "URL encoded" string created from the merged textual contents of |
paulb@213 | 325 | the given 'nodes', with the encoded character values representing characters |
paulb@213 | 326 | in the optional 'charset' (UTF-8 if not specified). |
paulb@213 | 327 | |
paulb@213 | 328 | template:url-encode(./text(), 'iso-8859-1') |
paulb@213 | 329 | """ |
paulb@213 | 330 | |
paulb@213 | 331 | l = [] |
paulb@213 | 332 | for node in nodes: |
paulb@213 | 333 | s = libxml2dom.Node(node).nodeValue |
paulb@213 | 334 | l.append(urllib.quote(s.encode("utf-8")).replace("/", "%2F")) |
paulb@213 | 335 | output = "".join(l) |
paulb@213 | 336 | return output |
paulb@213 | 337 | |
paulb@222 | 338 | def element_path(context, field_names): |
paulb@222 | 339 | |
paulb@222 | 340 | """ |
paulb@382 | 341 | Exposed as {template:element-path(field_names)}. |
paulb@382 | 342 | |
paulb@222 | 343 | Convert the given 'field_names' back to XPath references. |
paulb@222 | 344 | For example: |
paulb@382 | 345 | |
paulb@222 | 346 | /configuration$1/details$1/base-system$$value -> /*[position() = 1]/*[position() = 1]/base-system |
paulb@382 | 347 | |
paulb@222 | 348 | If more than one field name is given - ie. 'field_names' contains a |
paulb@222 | 349 | comma-separated list of names - then only the first name is used. |
paulb@382 | 350 | |
paulb@382 | 351 | To use this function effectively, use the result of another function as the |
paulb@382 | 352 | argument. For example: |
paulb@382 | 353 | |
paulb@382 | 354 | template:element-path(template:this-element()) |
paulb@382 | 355 | template:element-path(template:other-elements(matches)) |
paulb@382 | 356 | template:element-path(template:other-elements(..)) |
paulb@222 | 357 | """ |
paulb@222 | 358 | |
paulb@222 | 359 | field_name = field_names.split(",")[0] |
paulb@222 | 360 | |
paulb@222 | 361 | # Get the main part of the name (where a multivalue reference was given). |
paulb@222 | 362 | |
paulb@222 | 363 | field_name = get_field_name(field_name) |
paulb@222 | 364 | |
paulb@222 | 365 | # Build the XPath expression. |
paulb@222 | 366 | |
paulb@222 | 367 | parts = field_name.split(Constants.path_separator) |
paulb@222 | 368 | new_parts = [] |
paulb@222 | 369 | for part in parts: |
paulb@222 | 370 | path_parts = part.split(Constants.pair_separator) |
paulb@222 | 371 | if len(path_parts) == 2: |
paulb@222 | 372 | new_parts.append("*[position() = " + path_parts[1] + "]") |
paulb@222 | 373 | else: |
paulb@222 | 374 | new_parts.append(path_parts[0]) |
paulb@222 | 375 | return "/".join(new_parts) |
paulb@222 | 376 | |
paulb@156 | 377 | # New functions. |
paulb@156 | 378 | |
paulb@156 | 379 | libxsltmod.xsltRegisterExtModuleFunction("list-attribute", "http://www.boddie.org.uk/ns/xmltools/template", list_attribute) |
paulb@156 | 380 | libxsltmod.xsltRegisterExtModuleFunction("other-list-attributes", "http://www.boddie.org.uk/ns/xmltools/template", other_list_attributes) |
paulb@156 | 381 | libxsltmod.xsltRegisterExtModuleFunction("other-attributes", "http://www.boddie.org.uk/ns/xmltools/template", other_attributes) |
paulb@178 | 382 | libxsltmod.xsltRegisterExtModuleFunction("child-element", "http://www.boddie.org.uk/ns/xmltools/template", child_element) |
paulb@178 | 383 | libxsltmod.xsltRegisterExtModuleFunction("child-attribute", "http://www.boddie.org.uk/ns/xmltools/template", child_attribute) |
paulb@301 | 384 | libxsltmod.xsltRegisterExtModuleFunction("selector-name", "http://www.boddie.org.uk/ns/xmltools/template", selector_name) |
paulb@156 | 385 | |
paulb@144 | 386 | # New names. |
paulb@144 | 387 | |
paulb@178 | 388 | libxsltmod.xsltRegisterExtModuleFunction("this-element", "http://www.boddie.org.uk/ns/xmltools/template", this_element) |
paulb@178 | 389 | libxsltmod.xsltRegisterExtModuleFunction("this-attribute", "http://www.boddie.org.uk/ns/xmltools/template", this_attribute) |
paulb@178 | 390 | libxsltmod.xsltRegisterExtModuleFunction("new-attribute", "http://www.boddie.org.uk/ns/xmltools/template", new_attribute) |
paulb@178 | 391 | libxsltmod.xsltRegisterExtModuleFunction("other-elements", "http://www.boddie.org.uk/ns/xmltools/template", other_elements) |
paulb@144 | 392 | |
paulb@144 | 393 | # Old names. |
paulb@144 | 394 | |
paulb@178 | 395 | libxsltmod.xsltRegisterExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_element) |
paulb@178 | 396 | libxsltmod.xsltRegisterExtModuleFunction("field-name", "http://www.boddie.org.uk/ns/xmltools/template", this_attribute) |
paulb@178 | 397 | libxsltmod.xsltRegisterExtModuleFunction("new-field", "http://www.boddie.org.uk/ns/xmltools/template", new_attribute) |
paulb@178 | 398 | libxsltmod.xsltRegisterExtModuleFunction("other-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_elements) |
paulb@178 | 399 | |
paulb@178 | 400 | # Old functions. |
paulb@178 | 401 | |
paulb@66 | 402 | libxsltmod.xsltRegisterExtModuleFunction("multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", multi_field_name) |
paulb@66 | 403 | libxsltmod.xsltRegisterExtModuleFunction("other-multi-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_multi_field_names) |
paulb@49 | 404 | |
paulb@213 | 405 | # Utility functions. |
paulb@213 | 406 | |
paulb@213 | 407 | libxsltmod.xsltRegisterExtModuleFunction("url-encode", "http://www.boddie.org.uk/ns/xmltools/template", url_encode) |
paulb@222 | 408 | libxsltmod.xsltRegisterExtModuleFunction("element-path", "http://www.boddie.org.uk/ns/xmltools/template", element_path) |
paulb@213 | 409 | |
paulb@49 | 410 | def get_field_name(field_or_multi_name): |
paulb@49 | 411 | return field_or_multi_name.split(Constants.multi_separator)[0] |
paulb@49 | 412 | |
paulb@1 | 413 | # vim: tabstop=4 expandtab shiftwidth=4 |