XSLT ignores if it contains 0 elements

How can I ignore a style if there are 0 elements?

<xsl:template match="DifferenceNodes">
        <div class="code">
            <xsl:apply-templates select="DifferenceNode"/>
        </div>
    </xsl:template>

I want to do divwith class code only if it DifferenceNodecontains at least one element

+3
source share
1 answer

Change the matching criteria for DifferenceNodes. Add a predicate filter that ensures that it only matches when there are DifferenceNodechildren.

<xsl:template match="DifferenceNodes[DifferenceNode]">
   <div class="code">
       <xsl:apply-templates select="DifferenceNode"/>
   </div>
 </xsl:template>
+5
source

Source: https://habr.com/ru/post/1788477/


All Articles