如果满足模板条件,则显示一次段落 - Xsl 1

Display paragraph once if tempalte conditions are met - Xsl 1

我正在尝试编辑一封使用 XSL 1 格式化的邮件,以便在满足我的模板条件并且邮件中显示信息的情况下显示一行。邮件具有当前格式:

People attending:

   person1
       -someinfo

   person2
       -someinfo

People not attending:

   person3
       -someinfo

问题是当没有为不参加的人显示任何内容时,邮件仍会显示 "People not attending:",因为我目前在 运行 应用模板之前有它。

有没有什么好的方法,只有在有人不参加的情况下,才显示未参加人员信息前的段落?使用两个模板的原因是在我的原始代码中我检查 xml 中的更改。

代码:

<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>

而不是输出

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

无条件使用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>

我不太确定我上面使用的xsl:if test条件是否满足,我想它可能不会,所以你需要看看你是否可以调整它来检查输入是否有任何元素你会在那里输出。

另一种选择是将 运行 和 apply-templates 转换成一个变量,将其转换为 node-set 和 exsl:node-set 或类似的,然后检查它是否有任何相关内容,然后才输出标题(或者在你的情况下 p)和变量的内容。