Hi,

Sorry to answer to myself, I got something which seems to work, but it 
sure need improvement from better python/libxml gurus.

def test(ctx):
   """
   XSLT extension function, a skeleton for regexp tagging of a string
   """
   try:

     # string tagging ...

     # is it encoding safe ?
     result="1 <é>2</é> 3"

     doc = libxml2.parseDoc("<root>" + result + "</root>")
     root= doc.getRootElement()

     # sometimes needed, but can't say when
     # root.unlinkNode()
     # OK, but with root element
     # return [root]

     # to return a node list, is there better in  API ?
     nl = []
     child = root.children
     while child is not None:
       nl.append(child)
       child = child.next
       # unlink needed, or you can get strange results
       # like mixing, "1 <é>2</é> 3" => "<é>2</é> 31 "
       # but do it carefully, or child will loose its next
       nl[len(nl) - 1].unlinkNode()

     # seems OK
     return nl
   finally:
     doc.freeDoc()


-- 
Frédéric Glorieux <http://fictif.org>
_______________________________________________
xslt mailing list, project page http://xmlsoft.org/XSLT/
[email protected]
http://mail.gnome.org/mailman/listinfo/xslt

Reply via email to