Home Forums General XMetaL Discussion Dynamic List Start Number Reply To: Dynamic List Start Number

Derek Read

Reply to: Dynamic List Start Number

The following CSS would probably do it but you need to make sure to define a selector to match every possible value for the “starting number” attribute:


numberedlist { counter-reset: item 0 }
numberedlist[startnumber="1"] { counter-reset: item 0 }
numberedlist[startnumber="2"] { counter-reset: item 1 }
numberedlist[startnumber="3"] { counter-reset: item 2 }
numberedlist[startnumber="4"] { counter-reset: item 3 }
numberedlist[startnumber="5"] { counter-reset: item 4 }
numberedlist[startnumber="6"] { counter-reset: item 5 }
...etc...

listitem:before {
content: counter(item) ". ";
}

listitem {
display:block;
counter-increment: item;
}

…note the fallback (where a specific value is not defined) on the first line. Without this, values that don't match any of the values you have defined won't restart the list and would continue the number from any that did match (lists appearing before it). If the schema enforces validity to that level then it would be less of an issue, but you would still need it there if the attribute was optional (and means start from 1).

I suspect this is likely “good enough”. If not, then I think you'd be looking at a more complex scripting solution that uses the CSS styling APIs and some additional logic, but hopefully you can avoid that as it introduces other complexities.

Reply

Products
Downloads
Support