0

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

People attending:

   person1
       -someinfo

   person2
       -someinfo

People not attending:

   person3
       -someinfo

问题是当没有为未参加的人显示任何内容时,邮件仍将显示“未参加的人:”,因为我目前在运行应用模板之前拥有它。

有没有什么好的方法可以在没有人参加的信息之前显示段落,只有在有人没有参加的情况下?两个模板的原因是在我的原始代码中我检查了 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>
4

1 回答 1

1

而不是输出

<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我上面使用的条件是否足够,我想它可能不够,所以你需要看看你是否可以调整它来检查输入是否有任何你将在那里输出的元素。

另一种选择是将应用模板运行到变量中,将其转换为具有exsl:node-set或类似的节点集,然后检查它是否具有任何相关内容,然后才输出标题(或在您的情况下p)和内容变量。

于 2020-06-18T09:07:55.657 回答