Template creates an empty div

rdelong
Posts: 57

Template creates an empty div

Fri Dec 01, 2017 8:23 pm

We have an xsl:template in our WebHelp plugin that places all of the <info> content within a collapsible div. We designed this template so that any cautions and Important Notes are outside of the collapsible div. What the developer of this XSLT neglected to code is if the <info> tag contains only cautions and Important Notes then the results would be an empty div. The developer is long gone so I need to fix it, but I'm not sure how to approach this.

Here's our code:

Code: Select all

<xsl:template match="*[contains(@class,' task/info ')]|*[contains(@otherprops, 'enable_moreinfo')]|*[contains(@otherprops, 'disable_moreinfo')]" name="topic.task.info">
        <xsl:choose>
            <xsl:when test="contains(@otherprops, 'disable_moreinfo')">
                <xsl:apply-templates select="*[contains(@type,'caution') or contains(@type,'important')]"/>
                <xsl:call-template name="generateItemGroupTaskElement"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="*[contains(@type,'caution') or contains(@type,'important')]"/>
                <div data-role="collapsible" data-collapsed="true" data-mini="true" data-theme="c" style="border:1pt solid red">
                    <h2>More Information:</h2>
                    <xsl:call-template name="generateItemGroupTaskElement"/>
                </div>               
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="generateItemGroupTaskElement">
        <div>
            <xsl:call-template name="commonattributes"/>
            <xsl:call-template name="setidaname"/>
            <xsl:apply-templates
                select="*[not(contains(@type,'important')) and not(contains(@type,'caution'))]|text()"/>
        </div>
    </xsl:template>
alin
Site Admin
Posts: 126

Re: Template creates an empty div

Wed Dec 20, 2017 3:42 pm

Hello,

You can generate the 'notes' in a temporary variable and then generate the '<div>' element if at least one note was found.

For example:

Code: Select all

............

    <xsl:template name="generateItemGroupTaskElement">
       
        <xsl:variable name="notes">
            <xsl:apply-templates
                select="*[not(contains(@type,'important')) and not(contains(@type,'caution'))]|text()"/>
        </xsl:variable>
       
        <xsl:if test="count($notes/*) > 0">
            <!-- Generate the 'div' element if at least one note was matched. -->
            <div>
                <xsl:call-template name="commonattributes"/>
                <xsl:call-template name="setidaname"/>
                <xsl:copy-of select="$notes"/>
            </div>
        </xsl:if>
    </xsl:template>



Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “DITA (Editing and Publishing DITA Content)”

Who is online

Users browsing this forum: No registered users and 0 guests