Continuing CSS counter numbering on two levels
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 49
- Joined: Mon Mar 12, 2007 1:56 am
- Location: Sweden
Continuing CSS counter numbering on two levels
Hi,
I'm trying to write a CSS for an oXygen authoring framework for a customer DTD where I have nested lists like so:
A. Item 1
(1) Subitem 1
(2) Subitem 2
B. Item 2
(1) Subitem 3
(2) Subitem 4
Normally, a new list on either level will reset the list item counter, like above. However, if I set an attribute on the first list item of a level, the counter numbering should continue from the previous list on the same level:
A. Item 1
(1) Subitem 1
(2) Subitem 2
B. Item 2
(3) Subitem 3 (cont="1")
(4) Subitem 4
The relevant CSS looks like this (with additional counter resets outside this:
For list1, this works just fine. For the nested list2, however, I can't make the numbering continue, it will simply reset again. I've attached a complete XML and associated CSS.
I'm not sure if I am doing something wrong or if there is a bug of some description. The former is not entirely unlikely - CSS is not my first language.
As always, many thanks for a great editor!
Best.,
/Ari
I'm trying to write a CSS for an oXygen authoring framework for a customer DTD where I have nested lists like so:
A. Item 1
(1) Subitem 1
(2) Subitem 2
B. Item 2
(1) Subitem 3
(2) Subitem 4
Code: Select all
<list1>
<l1item>
<para>Item 1</para>
<list2>
<l2item>
<para>Subitem 1</para>
</l2item>
<l2item>
<para>Subitem 2</para>
</l2item>
</list2>
</l1item>
<l1item>
<para>Item 2</para>
<list2>
<l2item>
<para>Subitem 3</para>
</l2item>
<l2item>
<para>Subitem 4</para>
</l2item>
</list2>
</l1item>
</list1>
Code: Select all
cont="1"
A. Item 1
(1) Subitem 1
(2) Subitem 2
B. Item 2
(3) Subitem 3 (cont="1")
(4) Subitem 4
Code: Select all
<list1>
<l1item>
<para>Item 1</para>
<list2>
<l2item>
<para>Subitem 1</para>
</l2item>
<l2item>
<para>Subitem 2</para>
</l2item>
</list2>
</l1item>
<l1item>
<para>Item 2</para>
<list2>
<l2item cont="1">
<para>Subitem 3</para>
</l2item>
<l2item>
<para>Subitem 4</para>
</l2item>
</list2>
</l1item>
</list1>
Code: Select all
list1:has(l1item:first-of-type:not([cont="1"])) {
counter-reset: level1;
}
l1item:before {
counter-increment: level1;
content: counter(level1, upper-alpha) " ";
}
/* list2 */
list2:has(l2item:not([cont="1"]):first-of-type) {
counter-reset: level2;
}
l2item:before {
counter-increment: level2;
content: "(" counter(level2) ") ";
}
I'm not sure if I am doing something wrong or if there is a bug of some description. The former is not entirely unlikely - CSS is not my first language.
As always, many thanks for a great editor!
Best.,
/Ari
authoring.zip
You do not have the required permissions to view the files attached to this post.
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Continuing CSS counter numbering on two levels
Hello Ari,
I see no way to make this work using CSS counters. You can try your work directly in a web browser and I think that using counters you will not be able to make this work at all.
I would suggest getting read in the CSS or all counter-reset, counter-increment properties and instead use as value for "content" the Oxygen oxy_xpath function:
https://www.oxygenxml.com/doc/versions/ ... ction.html
Probably with the proper xpath expression you can count the number of list items before the current list item and also take into account that specific attribute.
Regards,
Radu
I see no way to make this work using CSS counters. You can try your work directly in a web browser and I think that using counters you will not be able to make this work at all.
I would suggest getting read in the CSS or all counter-reset, counter-increment properties and instead use as value for "content" the Oxygen oxy_xpath function:
https://www.oxygenxml.com/doc/versions/ ... ction.html
Probably with the proper xpath expression you can count the number of list items before the current list item and also take into account that specific attribute.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 38
- Joined: Thu Jul 29, 2021 12:02 pm
Re: Continuing CSS counter numbering on two levels
Post by InspectorSpacetime »
Hi,
I had a look and this is truly baffling. Since your solution works perfectly well with the first level lists, I can't understand why it won't work with the second level lists! No matter what selectors I tried to use, it always resets the level2 counter for the second list as well. Unless you don't determine a reset at all, then the list flows as expected. Strange.
However, isn't there a simple workaround: Instead of determining when to NOT reset the list with the :has and :not pseudo selectors, couldn't you simply determine when to reset the second list. Like this:
And then in your CSS use:
Of course, you would have to put the reset="true" attribute in every time you want the list to reset. But it seems to work for me.
And just a thought: Wouldn't your CSS for the first level lists be a lot simpler if you defined the cont="1" attribute in the list1 element instead to the first l1item? That way you wouldn't have to use the :has and :first-of-type pseudo selectors?
Just thought I't throw these ideas out here.
I had a look and this is truly baffling. Since your solution works perfectly well with the first level lists, I can't understand why it won't work with the second level lists! No matter what selectors I tried to use, it always resets the level2 counter for the second list as well. Unless you don't determine a reset at all, then the list flows as expected. Strange.
However, isn't there a simple workaround: Instead of determining when to NOT reset the list with the :has and :not pseudo selectors, couldn't you simply determine when to reset the second list. Like this:
Code: Select all
<list2 reset="true">
<l2item>
<para>Second level2 list, first item, cont=1</para>
</l2item>
<l2item>
<para>Second level2 list, second item</para>
</l2item>
</list2>
Code: Select all
list2[reset="true"] {
counter-reset: level2;
}
And just a thought: Wouldn't your CSS for the first level lists be a lot simpler if you defined the cont="1" attribute in the list1 element instead to the first l1item? That way you wouldn't have to use the :has and :first-of-type pseudo selectors?
Just thought I't throw these ideas out here.
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Continuing CSS counter numbering on two levels
Hi,
There is a specification for the CSS counters function. I think we tried to obey that specification quite closely in the Author visual editor mode.
https://www.w3.org/TR/CSS21/generate.html#scope
In such cases I think it's best to try the XML with the CSS directly in a web browser, if you can get it to work like this and our Author visual editing mode does not work like the web browser, we can try to take a look and try to fix the possible issue.
Regards,
Radu
There is a specification for the CSS counters function. I think we tried to obey that specification quite closely in the Author visual editor mode.
https://www.w3.org/TR/CSS21/generate.html#scope
In such cases I think it's best to try the XML with the CSS directly in a web browser, if you can get it to work like this and our Author visual editing mode does not work like the web browser, we can try to take a look and try to fix the possible issue.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 38
- Joined: Thu Jul 29, 2021 12:02 pm
Re: Continuing CSS counter numbering on two levels
Post by InspectorSpacetime »
Hi Radu,Radu wrote: ↑Fri Apr 21, 2023 1:29 am Hi,
There is a specification for the CSS counters function. I think we tried to obey that specification quite closely in the Author visual editor mode.
https://www.w3.org/TR/CSS21/generate.html#scope
In such cases I think it's best to try the XML with the CSS directly in a web browser, if you can get it to work like this and our Author visual editing mode does not work like the web browser, we can try to take a look and try to fix the possible issue.
Regards,
Radu
At least for me, the same thing occurs in every browser. So I’m sure it’s not an issue with your software.
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service