检查是否有节点但没有文本

时间:2013-06-17 09:50:01

标签: xslt

我有下面的xml片段。

情况1:

 <para>
    <content-style font-style="bold">Affidavit</content-style>
</para>

情况2:

 <para>This is a different <content-style font-style="bold">Affidavit</content-style> case              
</para>

如果只存在节点(案例1),我想在这里控制调用节模板,但如果节点中也有文本,则需要调用(案例2)。我尝试了下面的xslt,但它无法正常工作。请让我知道怎么做。

<xsl:template match="para">
<xsl:choose>
<xsl:when test="child::content-style/node[1]">
<xsl:call-template name="section"/>
</when></xsl:choose>
</xsl:template>

由于

1 个答案:

答案 0 :(得分:2)

从您的示例中我认为您应该使用内容样式而不是文本来调用para的模板部分。 最好的方法是这样:

<xsl:template match="para" />
<xsl:template match="para[content-style][not ( text() )]">
            <xsl:call-template name="section"/>
</xsl:template>

使用xsl:何时应该这样做:

<xsl:template match="para" >
    <xsl:choose>
        <xsl:when test="content-style and not(text())">
            <xsl:call-template name="section"/>
        </xsl:when>
    </xsl:choose>
</xsl:template>
相关问题