How to concatenate XHTML files in Java resolving any possible CSS conflicts? -
i need concatenate in java , @ runtime xhtml files (containing formatted text) single file. final file must have content included in original ones. however, these files may have different css definitions, have resolve possible collision of styles. have tried search library can automate task , believe jsoup can help, doesn't seem able deal css collisions automatically.
is there open source framework or api make task easier implement?
let me show example explain better trying do.
<!-- file 1 --> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> h1 { color: red; } .default-stroke { font-weight: bold; } #custom-id { font-style: normal; } div.align { position: absolute; right: 800px; width: 300px; } </style> </head> <body> <h1>html file 1 header 1 tag</h1> <div class="align"> <p id="custom-id" class="default-stroke">paragraph inside div</p> </div> </body> </html> <!-- file 2 --> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> h1 { color: blue; } .default-stroke { font-weight: italic; } div.align { position: absolute; right: 1000px; width: 300px; } </style> </head> <body> <h1>html file 2 header 1 tag</h1> <div class="align"> <p id="custom-id" class="default-stroke">paragraph inside div</p> </div> </body> </html> <!-- file 3 --> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> h1 { color: green; } .default-stroke { font-weight: 900; } div.align { position: absolute; right: 1200px; width: 300px; } </style> </head> <body> <h1>html file 3 header 1 tag</h1> <div class="align"> <p id="custom-id" class="default-stroke">paragraph inside div</p> </div> </body> </html> note css styles (h1, .default-stroke , div.align) have different definitions each xhtml file. call collision. need find way deal such collisions, keeping styles defined in every file. best way of doing it? may write own code introduce css namespaces?
i guess not trivial task. appreciate suggestions.
thanks!
<style scoped> may help. put contents of each of html files in own sections , put style blocks in there too, giving them scoped attributes. see https://developer.mozilla.org/en-us/docs/web/html/element/style
<section> <style scoped> h1 { color: red; } .default-stroke { font-weight: bold; } #custom-id { font-style: normal; } div.align { position: absolute; right: 800px; width: 300px; } </style> <h1>html file 1 header 1 tag</h1> <div class="align"> <p id="custom-id" class="default-stroke">paragraph inside div</p> </div> </section> <section> <style scoped> h1 { color: blue; } .default-stroke { font-weight: italic; } div.align { position: absolute; right: 1000px; width: 300px; } </style> <h1>html file 2 header 1 tag</h1> <div class="align"> <p id="custom-id" class="default-stroke">paragraph inside div</p> </div> </section> <section> <style scoped> h1 { color: green; } .default-stroke { font-weight: 900; } div.align { position: absolute; right: 1200px; width: 300px; } </style> <h1>html file 3 header 1 tag</h1> <div class="align"> <p id="custom-id" class="default-stroke">paragraph inside div</p> </div> </section> disclaimer: doesn't work in browsers (yet).
Comments
Post a Comment