Re: separating precedence of 2 types of inheritance

Hi Nathan again,

Am 07.08.13 05:42, schrieb Nathan Glenn:
> Hello again,
> I was wondering if I could ask a question about inheritance and 
> precedence. Section 5.5 of the spec gives information on this, but 
> leaves the proper implementation unclear in my mind.
> Implementing global selection makes a lot of sense to me because once 
> rules are properly ordered, they can all be applied and later ones 
> will overwrite older ones. However, it is less clear for inheritance. 
> What I would like to think is that one could do the following in order 
> to decide the ITS metadata for an entire document:
>
>  1. Apply default values.
>  2. Apply global selection via rules, one at a time, also applying
>     inheritance for each one. Each rule application writes over any
>     previous ones.
>  3. Apply selection via explicit local markup, and then the
>     inheritance of this markup, overwriting any previously applied
>     selections. Application would be a pre-order operation in a
>     depth-first search (or something else that would cause selections
>     for children to overwrite selections/inheritance via ancestors).
>
> However, the specification for precedence of selection from section 
> 5.5 is:
>
>  1. local markup
>  2. global selectors
>  3. inherited values
>  4. default values
>

Correct.

> The problem with this is that there are 2 types of inheritance: 
> inheritance from global selections (example 13) and inheritance from 
> local selections (example 11), and the given precedence order implies 
> that they are both at the same level.

They actually are at the same level.

> If they were, then implementation would be much less simple than the 3 
> step process outlined above


There is a mismatch between your steps and the four types of 
inheritance. Your steps describe an algorithm how to process (your type 
of) inheritance. The four types of inheritance are "declarative": they 
don't presprice how to process ITS information, but only how the 
relation between the four types of information is.
A simple algorithm to process the four types of inheritance could have 
two steps:

1) For the input document apply global rules taking their order into 
account ("the last rule wins"). Output: an XML / HTML DOM decorated with 
ITS information
2) Traverse the decorated DOM. For each node check if there is local 
markup and if yes apply that. If there is no local markup check if there 
is a decoration from step 1). If there is no decoration check for 
inherited values, then default values.

Although 2) has several sub parts, I am saying "two steps" since you 
only need to process the document twice: decoration for global rules and 
traversing for the rest. If I recall correctly, the okapi ITS 
implementation uses that kind of approach. The second step then can be 
implemented in streaming mode and hence is relatively efficient.

> , and ITS could get pretty clumsy. For example, there would be no way 
> to set an entire Arabic document as right-to-left (<its:dirRule 
> selector="/*" dir="rtl"> or selector="//*") and then mark the parent 
> of several English elements with its:dir="ltr".

I see this rather as an issue that you can resolve by educating authors. 
Take CSS as an example: if authors have markup like this
<!DOCTYPE html>
<html>
   <head>
     <meta content="text/html; charset=UTF-8" http-equiv="content-type">
     <title>Example of CSS inheritance</title>
     <style type="text/css">
       span {color: red;}  </style>
   </head>
   <body>
     <p><span style="color:blue;">blue, via local style attribute 
<span>red via
           global style element</span> </span></p>
   </body>
</html>

They know that the local style attribute does not inherit to the nested 
span, since the nested span is selected directly via a global CSS element.

So rather than complicating the implementations and eventually how ITS 
markup authors have to understand inheritance, I would keep things as 
they are - relatively simple and aligned with well known CSS.

> You would have to set the direction on each individual element, or 
> create another global selector and place it after the first.
>
> I think that the precedence order should probably be:
>
>  1. local markup
>  2. inherited local markup
>  3. global selectors
>  4. inheritance from global selectors
>  5. default values
>
> Provided it is correct, it makes it easier to see that a proper 
> implementation of ITS is simply the reverse application of this list. 
> One could even combine 1-2 and 3-4.
>
> I'm sorry if I'm way off on this. Could someone tell me if my 
> understanding of precedence and inheritance is correct?

I hope that above CSS example made this clear.

Best,

Felix
>
> Nathan

Received on Wednesday, 7 August 2013 07:54:25 UTC