It is of course possible to combine all the above methods. For example, the following w2x
command is used to create w2x_install_dir/doc/manual/manual_restyled.html
:
w2x -pu edit.before.finish-styles customize\patch_manual_restyled.xed¬ -p edit.finish-styles.css-uri manual_restyled_css/custom.css¬ -pu edit.finish-styles.custom-styles-url-or-file customize\custom.css¬ manual.docx out\manual_restyled.html
where w2x_install_dir/doc/manual/customize/patch_manual_restyled.xed
contains:
for-each /html/body/p[get-class("^p-Heading\d$")] { set-variable("class", get-class("^n-\d+-\d+$")); if $class != '' { set-variable("selector", concat(".", $class, ":after")); if find-rule($selector) >= 0 { remove-rule($selector); set-variable("selector", concat(".", $class, ":before")); set-rule($selector, "float"); set-rule($selector, "width"); set-rule($selector, "content", concat(get-rule($selector, "content"), ' " "')); set-rule($selector, "display", "inline"); } } }
The above XED script:
.n-1-0:after { clear: both; content: ""; display: block; }
.n-1-0:before { content: counter(n-1-0); counter-increment: n-1-0; float: left; width: 21.6pt; }
which becomes:
.n-1-0:before { content: counter(n-1-0) " "; counter-increment: n-1-0; display: inline; }
This script is useful because otherwise adding a bottom border to headings gives an ugly result. While the contents of the heading is “underlined”, the CSS float
containing the numbering value of the heading is not.
Besides get-class, the following XPath extension functions may be used to access the CSS styles contained in the XHTML+CSS document created by the Convert step: find-rule
, font-size
, get-rule
, get-style
, lookup-length
, lookup-style
, style-count
.
Why use XPath extension function get-class
and not matches(@class,pattern)
?
The answer is: because all class
attributes have been removed by XED script w2x_install_dir/xed/init-styles.xed
.
This script “interns” the CSS rules found in the html
/head
/style
element of the XHTML+CSS document, the CSS styles directly set on some elements and the CSS classes set on some elements.
This operation is needed to allow an efficient implementation of the following XPath extension functions: find-rule
, font-size
, get-class
, get-rule
, get-style
, lookup-length
, lookup-style
, style-count
, and of the following editing commands: add-class
, add-rule
, remove-class
, remove-rule
, set-rule
, set-style
.
More information about “interned” CSS styles in command parse-styles (command invoked by w2x_install_dir/xed/init-styles.xed
) and inverse command unparsed-styles
(command invoked by w2x_install_dir/xed/finish-styles.xed
).