擅长:python、mysql、java
<pre><code>def lxml_empty_str(context, nodes):
for node in nodes:
node.text = node.text or ""
return nodes
ns = etree.FunctionNamespace('http://ns.qubic.tv/lxmlfunctions')
ns['lxml_empty_str'] = lxml_empty_str
namespaces = {'i':"http://ns.qubic.tv/2010/item",
'f': "http://ns.qubic.tv/lxmlfunctions"}
packitems_duration = root.xpath('f:lxml_empty_str('//b:pack/i:packitem/i:duration)/text()',
namespaces={'b':billing_ns, 'f' : 'http://ns.qubic.tv/lxmlfunctions'})
packitems_max_count = root.xpath('f:lxml_empty_str('//b:pack/i:packitem/i:max_count) /text()',
namespaces={'b':billing_ns, 'f' : 'http://ns.qubic.tv/lxmlfunctions'})
packitems = zip(packitems_duration, packitems_max_count)
>>> packitems
[('520','14'), ('','23')]
</code></pre>
<p><a href="http://python-thoughts.blogspot.fr/2012/01/default-value-for-text-function-using.html" rel="nofollow">http://python-thoughts.blogspot.fr/2012/01/default-value-for-text-function-using.html</a></p>