Thank you! Your suggested solution works perfectly. You were right: I had to 
add a rule for each border-style and border-with (bottom, top, left, right) 
separately.


On 10/06/16 09:40, "Hussein Shafie" <[email protected]> wrote:

>On 06/09/2016 07:28 PM, Thomas Dumm wrote:
>> Thank you so much!!!
>>
>> - Is the following addition to also keep the border-style and border-width 
>> correct?
>
>Almost. Your original script overwrites attribute style each time. Try this:
>
>---
>     set-variable("bg", lookup-style("background-color"));
>     if $bg {
>         set-attribute("style", concat("background-color: ", $bg, ";"));
>     }
>
>     set-variable("bs", lookup-style("border-style"));
>     if $bs {
>         set-attribute("style",
>                       concat(./@style, "border-style: ", $bs, ";"));
>     }
>
>     set-variable("bw", lookup-style("border-width"));
>     if $bw {
>         set-attribute("style",
>                       concat(./@style, "border-width: ", $bw, ";"));
>     }
>----
>
>Now, I've not tested this with border styles, but only with background 
>color.
>
>I'm not even sure w2x generates border-style and border-width. May be it 
>generates border-top-style, border-right-style,border-bottom-width, etc. 
>You'll have to look at the generated styled --not semantic-- XHTML to be 
>sure.
>
>Therefore I cannot guarantee that your addition as is will give you the 
>results you expect.
>
>
>
>
>> - Should I also add „or self::th“ tot he for-each?
>
>To my knowledge, w2x never generates th. However adding "or self::th" 
>cannot hurt.
>
>
>
>
>>
>>
>> namespace "http://www.w3.org/1999/xhtml";;
>> namespace html = "http://www.w3.org/1999/xhtml";;
>>
>> for-each /html/body//*[self::td or self::tr or self::table] {
>>
>>      set-variable("bg", lookup-style("background-color"));
>>      if $bg {
>>          set-attribute("style", concat("background-color: ", $bg, ";"));
>>
>>      set-variable("bs", lookup-style("border-style"));
>>      if $bs {
>>          set-attribute("style", concat("border-style: ", $bs, ";"));
>>      }
>>
>>     set-variable("bw", lookup-style("border-width"));
>>      if $bw {
>>          set-attribute("style", concat("border-width: ", $bw, ";"));
>>      }
>>
>>
>>      }
>> }
>>
>>
>> On 09/06/16 19:18, "Hussein Shafie" <[email protected]> wrote:
>>
>>> On 06/09/2016 09:34 AM, Thomas Dumm wrote:
>>>>
>>>> Is there a way to generate sematic XHTML but retain the ruling and
>>>> shading of tables either via added styles or classes?
>>>
>>> Yes.
>>>
>>>
>>>
>>>>
>>>> I naively tried with edit.prune.preserve "background-color" which did
>>>> not show any consequence.
>>>>
>>>
>>> It's slightly more complicated than this.
>>>
>>> Here's the XED script:
>>>
>>> ---
>>> namespace "http://www.w3.org/1999/xhtml";;
>>> namespace html = "http://www.w3.org/1999/xhtml";;
>>>
>>> for-each /html/body//*[self::td or self::tr or self::table] {
>>>      set-variable("bg", lookup-style("background-color"));
>>>      if $bg {
>>>          set-attribute("style", concat("background-color: ", $bg, ";"));
>>>      }
>>> }
>>> ---
>>>
>>> I stored it in a file called "before-remove-styles.xed", but the file
>>> name does not matter. Could be foobar.xed.
>>>
>>> You must pass it to w2x (or w2x-app in an option file) as follows:
>>>
>>> -pu edit.before.remove-styles "before-remove-styles.xed"
>>>
>>> Now a few explanations:
>>>
>>> * The semantic XHTML is created using "w2x_install_dir/xed/main.xed".
>>>
>>> * One of the steps of "main.xed" is "remove-styles.xed" which removes
>>> all *interned* styles and classes from the XHTML input file.
>>>
>>> (Interning styles and classes allows a fast lookup of CSS styles. More
>>> info in http://www.xmlmind.com/w2x/_distrib/doc/xedscript/parse-styles.html)
>>>
>>> * for-each /html/body//*[self::td or self::tr or self::table]
>>> iterates over cells, rows and tables.
>>>
>>> * lookup-style("background-color") returns the value of CSS property
>>> background-color not matter how this property has been specified.
>>>
>>> See
>>> http://www.xmlmind.com/w2x/_distrib/doc/xedscript/w2xfuncs.html#lookup-style
>>>
>>> * If a cell, row and table has a background color, then give it an
>>> actual style attribute (not an interned style) with this property.
>>>
>>> See http://www.xmlmind.com/w2x/_distrib/doc/xedscript/set-attribute.html
>>>
>>> * In "main.xed", after "remove-styles.xed", you'll find
>>> "finish-styles.xed" which discards all interned styles and classes.
>>> However "finish-styles.xed" does *not* discard actual style and class
>>> attributes.
>>
>



--
XMLmind Word To XML Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/w2x-support

Reply via email to