0

Im trying to edit a mail being formatted with XSL 1 to display one line if my template conditions are met and information is displayed in the mail. The mail has the current format:

People attending:

   person1
       -someinfo

   person2
       -someinfo

People not attending:

   person3
       -someinfo

The problem is when there are nothing displayed for people not attending, the mail will still show "People not attending:" as i currently have it before running the apply-template.

Is there any good way to display the paragraph before the information about people not attending, only if there are people not attending? The reason for two templates is that in my original code i check for changes in the xml.

Code:

<p>People not attending</p>
<xsl:apply-templates select="1_type/2_group/1_type_f" mode="pn"/>

<xsl:template match="1_type_f" mode="pn">
    <xsl:if test="((1_type_f_v/@old_selected='Selected') and (1_type_f_v/@selected!='Selected'))">
        <xsl:apply-templates select="t1_type_f_v" mode="pn"/>
    </xsl:if>
</xsl:template>

<xsl:template match="1_type_f_v" mode="pn">
    <xsl:if test="((@old_selected='Selected') and (@selected!='Selected'))">
        <p><xsl:value-of select="../nameOfPerson"/></p>
        <ul>
            <li><xsl:value-of select="someInfo"/></li>
            <p><xsl:value-of select="someInfo2"/></p>
        </ul>
    </xsl:if>
</xsl:template>
Raalph
  • 28
  • 6

1 Answers1

1

Instead of outputting

<p>People not attending</p>
<xsl:apply-templates select="1_type/2_group/1_type_f" mode="pn"/>

unconditionally you need to use xsl:if

<xsl:if test="1_type/2_group/1_type_f">
    <p>People not attending</p>
    <xsl:apply-templates select="1_type/2_group/1_type_f" mode="pn"/>
</xsl:if>

I am not quite sure if the xsl:if test condition I have used above suffices, I suppose it might not, so you will need to see whether you can adapt it to check whether the input has any elements you will output there.

Another option would be to run the apply-templates into a variable, convert it to a node-set with exsl:node-set or similar and then check whether it has any relevant content and only then to output the heading (or in your case p) and the contents of the variablee.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Thank you for the quick reply, i have yet to find any test conditions that can check if the template will show any information, due to the @selected!='Selected' part (and due to being a xsl novice). Far as my understanding goes the first option will pass the test if the statement contain nodes, and i mainly do the selection in the selected & old_selected part. Your second option however gives me a new path to test out over the weekend, many thanks! – Raalph Jun 18 '20 at 11:53