Add Parentheses Around Each Numbered List Item - please HELP!


Is it feasible to add parentheses around numbered list items in XSLT?

I have a template that basically works like this for all ordered lists:

a.  Some AA text
b.  Some BB text
c.  Some CC text

The XSLT that handles this looks like this:

<OL type="a">

Now, however, there have been requests to envelope the numbered list items within parentheses, and to remove the trailing periods after the letter, so that the ordered list looks like this:

(a)   Some AA text
(b)   Some BB text
(c)   Some CC text

I've surfed the web for hours in the hopes of finding a way to resolve this issue, to no avail.  

Is this impossible?  I made some fruitless attempts to put "(" and ")" characters around the <li> tags, and tried to hardcode it in using a pseudo-counter to count the list items and then output the counter values, but none of my resolutions have worked.

I am tearing my hair out because I assumed this would be relatively trivial to do yet I am at a complete and total loss...

Any advice or guidance is greatly appreciated!  

Please help me!

Best regards,

Who is Participating?
Geert BormansInformation ArchitectCommented:
Hi Jamie,

this one is though.
You would basically need some CSS2 properties that aren't supported by any browser yet
marker, marker-offset...

The only way to tackle this is
- give the <LI> a style attribute (style="display: block;") The list items will then display as a block. You should play with margins and padding then.
maybe you can make it <dfn> and <dd> elements instead of <li>, if that is acceptable
- after that you have to calculate the item numbering yourself... the format can be controlled with the xsl:count element,
put a "(" before and a ")" after yourself

sorry but browsers don't support what they could have yet :-)
jmc430Author Commented:
Hi Geert!

Thanks for responding!

How do I count the values of <LI>?  I tried doing self:://theNameOfTheParentElementForLiTags, but it only gives the grand total of the element itself..

I am using this now:

<div align="left">
<xsl:if test="count(//para)>1">
<xsl:text disable-output-escaping="yes">(</xsl:text>
<xsl:value-of select="count(//para)"/>
<xsl:text disable-output-escaping="yes">)</xsl:text>
<div align="left">

But this is only outputting "(22)" values instead of incrementing them  ... what am I doing wrong?

Thanks so much for helping me!
jmc430Author Commented:
Hi Geert!!

Thanks for pointing me in the right direction... I  got it working.

Thanks so much again for all of your help!  I really really appreciate everything! :)
Geert BormansInformation ArchitectCommented:
<xsl:value-of select="count(//para)"/>

this will count all the para elements of course

you should do the count in the processing of the para element

<div align="left">
<xsl:apply-templates select="para"/>

<xsl:template match="para">
   <xsl:value-of select="countpreceding-sibling::para + 1)"/>
Geert BormansInformation ArchitectCommented:
well, seems my last post took me to long to write :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.