Search code examples
xmlxsltditadita-ot

How to select by attribute in Dita OTs custom.xsl


My goal is to change the font color of any text that is contained within an element that has the attribute and value of <li audience="beginner"></li>. I'm currently looking to do this in the custom.xsl file of Dita Open Toolkits PDF plugin. The custom.xsl will override any styles in the common.xsl. My Question is how do I select by attribute in the attribute-set tag?

Custom.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    version="2.0">
    <xsl:attribute-set name="li">
        <xsl:attribute name="color">red</xsl:attribute>
    </xsl:attribute-set>
</xsl:stylesheet>

XML

<li audience="beginner" class="- topic/li ">This text should be blue</li>
<li audience="expert" class="- topic/li ">This text should be red</li>

Solution

  • The selection criteria for the OT would be something like:

        ...
        <xsl:template match="*[contains(@class,' topic/li ')]">
            <xsl:attribute name="color">
            <xsl:choose>
                <xsl:when test="@audience="beginner">blue</xsl:when>
                <xsl:when test="@audience="expert">red</xsl:when>
                <xsl:otherwise>black</xsl:otherwise>
            </xsl:choose>
            </xsl:attribute>
        ... (anything else you want to do with li)
        </xsl:template>
        ...
    

    Hope this helps.