Topics

How to add multiple formats for <li> element in <ul>


Derek Fess
 

I'm running DITA-OT 3.2.1

Our company has rebranded, and as such we now have a new Marketing style guide. I need to format three levels of bullets. This part I've done (using the commonvariables.xml file). However, I need to make them different colors depending on which level they are at. All that I can seem to do is set the color for all levels, using the ul.li__label attribute set. If I understand correctly, I can make a new attribute set (say ul.li.li__label), but would have to call it from the lists.xsl file. This is where I am stuck. I do not know xslt well enough to know how to construct what I need. I know I need to use this piece of code from the pdf2 lists.xsl file:

<xsl:template match="*[contains(@class, ' topic/ul ')]/*[contains(@class, ' topic/li ')]">
        <xsl:variable name="depth" select="count(ancestor::*[contains(@class, ' topic/ul ')])"/>
        <fo:list-item xsl:use-attribute-sets="ul.li">
            <xsl:call-template name="commonattributes"/>
            <fo:list-item-label xsl:use-attribute-sets="ul.li__label">
                <fo:block xsl:use-attribute-sets="ul.li__label__content">
                    <xsl:call-template name="getVariable">
                        <xsl:with-param name="id" select="concat('Unordered List bullet ', (($depth - 1) mod 4) + 1)"/>
                    </xsl:call-template>
                </fo:block>
            </fo:list-item-label>
            <fo:list-item-body xsl:use-attribute-sets="ul.li__body">
                <fo:block xsl:use-attribute-sets="ul.li__content">
                    <xsl:apply-templates/>
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:template>

Any help would be greatly appreciated.


Nicolas Delobel
 

Hi Derek,

I think in you case you have to create a new a new attribute set per ul level: ul.ul.li__label, ul.ul.ul.li__label, ul.ul.ul.ul.li__label, etc.

And after, you have to apply dynamically these attibute-set based on item level using processAttrSetReflection named template:
<xsl:template match="*[contains(@class, ' topic/ul ')]/*[contains(@class, ' topic/li ')]">
        <xsl:variable name="depth" select="count(ancestor::*[contains(@class, ' topic/ul ')])"/>
        <xsl:variable name="attrName" as="xs:string">
            <xsl:for-each select="0 to $depth">ul.</xsl:for-each>
        </xsl:variable>
        <fo:list-item xsl:use-attribute-sets="ul.li">
            <xsl:call-template name="commonattributes"/>
            <fo:list-item-label>
                <xsl:call-template name="processAttrSetReflection">
                    <xsl:with-param name="attrSet" select="concat('ul',$attrName,'li__label__content')"/>
                    <xsl:with-param name="path" select="'../../cfg/fo/attrs/commons-attr.xsl'"/>
                </xsl:call-template>
                <fo:block xsl:use-attribute-sets="ul.li__label__content">
                    <xsl:call-template name="getVariable">
                        <xsl:with-param name="id" select="concat('Unordered List bullet ', (($depth - 1) mod 4) + 1)"/>
                    </xsl:call-template>
                </fo:block>
            </fo:list-item-label>
            <fo:list-item-body xsl:use-attribute-sets="ul.li__body">
                <fo:block xsl:use-attribute-sets="ul.li__content">
                    <xsl:apply-templates/>
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:template>
I didn't test, but I think it may work.

Regards,
Nicolas


Ozana Dragomir
 

Here is our code for different bullet colours:

In lists-attr.xsl

    <xsl:variable name="custom-color-purple">#72166B</xsl:variable>
    <xsl:variable name="custom-color-blue">#6687B7</xsl:variable>

    <xsl:attribute-set name="ul.li__label__content">
        <xsl:attribute name="text-align">start</xsl:attribute>
        <!-- change second level bullet color to blue and third level bullet color to purple -->
        <xsl:attribute name="color">
            <xsl:choose>
                <xsl:when test="count(ancestor::*[contains(@class, ' topic/ul ')]) = 2">
                    <xsl:value-of select="$custom-color-blue"/>
                </xsl:when>
                <xsl:when test="count(ancestor::*[contains(@class, ' topic/ul ')]) = 3">
                    <xsl:value-of select="$custom-color-purple"/>
                </xsl:when>
                <xsl:otherwise>black</xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>
    </xsl:attribute-set>


I hope this helps.

Best regards,
Ozana


Derek Fess
 

On Fri, Mar 26, 2021 at 06:39 AM, Ozana Dragomir wrote:
count(ancestor::*[contains(@class, ' topic/ul ')]) = 2
Ozana, thank you so much! That worked perfectly. I guess I didn't realize you could use the <xsl:choose> element in the attr file. I thought it was just defining each attribute set at a time.