How to apply CSS to XML in python?



I have an xml file that would I would like to parse (E.g. using lxml.etree) apply a set of css styles to, and then export. For instance, the input would be this xml:



<root>
<foo id="good">
<bar class="bad">
</bar>
</foo>
</root>


and this css:



bar {
color:red
}

#good {
color: green
}


and the resulting etree would look something like:



<root>
<foo id="good" color="green">
<bar class="bad" color="red">
</bar>
</foo>
</root>


So that the effects of the css are represented in the attributes of the resulting tree.


I can do this in python, but I thought there might be a simple way to reuse existing libraries to make it much easier.


Thanks!


No comments:

Post a Comment