Page 1 of 1

Template creates an empty div

Posted: Fri Dec 01, 2017 8:23 pm
by rdelong
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>

Re: Template creates an empty div

Posted: Wed Dec 20, 2017 3:42 pm
by alin
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