Add Parentheses Around Each Numbered List Item - please HELP!

Posted on 2006-04-18
Last Modified: 2008-03-04

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,

Question by:jmc430
    LVL 60

    Accepted Solution

    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 :-)

    Author Comment

    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!

    Author Comment

    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! :)
    LVL 60

    Expert Comment

    by:Geert Bormans
    <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)"/>
    LVL 60

    Expert Comment

    by:Geert Bormans
    well, seems my last post took me to long to write :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity
    illegal characters in XML using UTF-8 8 24
    Excel VBA and XML - traversing the nodes 2 50
    C# Delete from XML 10 35
    Specific format 21 105
    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now