Lua - 340340 335
a,b=f='(%w+)'a={},b={}for l in io.lines(arg[2])do i=l:sub(1,1)t=i=='#'and a or b
k,v=l:match'match(%w+)f..' {(.-)}'t[k]=v')t[k]=v end
for l in io.lines(arg[1])do
c=''g='class="(.-)"'f='(%w+)'h='style="'l=l"'h='style="'l=l:gsub('id="(%w+)"''id='..f,function(v)l:gsub(g,function(e)c=e:gsub(f,b)end)return h..a[v]..c..'"'end)l=l:gsub(g,function(e)return #c<1 and h..e:gsub(f,b)..'"'end)print(l)end
**Usage:** execute from the command line `lua script.lua input.html input.css`