2011-04-13 3 views

Répondre

7

Utilisez quelque chose comme ceci:

from xml.dom import minidom 

xml = """ 
<root> 
<x>text</x> 
</root>""" 

dom = minidom.parseString(xml) 
pi = dom.createProcessingInstruction('xml-stylesheet', 
            'type="text/xsl" href="mystyle.xslt"') 
root = dom.firstChild 
dom.insertBefore(pi, root) 
print dom.toprettyxml() 

=>

<?xml version="1.0" ?> 
<?xml-stylesheet type="text/xsl" href="mystyle.xslt"?> 
<root> 

    <x> 
     text 
    </x> 

</root> 
2

Je ne suis pas familier avec minidom, mais vous devez créer un noeud d'instructions de traitement (PI) avec le nom: "xml-stylesheet" et le texte: "type = 'text/xsl' href = 'mystyle.xslt'"

Lisez la documentation sur la création d'un PI.

Questions connexes