Search code examples
openxml

How to deal with multiple "basedOn" elements in style definition?


I think the reference doesn't specify a max number of occurence of the "basedOn" element, but it neither specify how to deal with multiple instance of this element. Any ideas?


Solution

  • I made tests, and it seems that MS Word only deals with the last occurence of the "basedOn" element. If I have this style definition:

    <w:style w:type="character" w:default="1" w:styleId="Underline">
      <w:name w:val="Underline"/>
      <w:rPr>
        <w:u w:val="single"/>
      </w:rPr>
    </w:style>
    <w:style w:type="character" w:styleId="Blue">
      <w:name w:val="Blue"/>
      <w:rPr>
        <w:color w:val="0000FF"/>
      </w:rPr>
    </w:style>
    <w:style w:type="character" w:styleId="BlueUnderline">
      <w:name w:val="BlueUnderline"/>
      <w:basedOn w:val="Blue"/>
      <w:basedOn w:val="Underline"/>
    </w:style>
    

    The run which I apply the style on is underlined but not blue. Considering I want to reproduce the Word's behaviour, this is what I decided to do.