我怎么能让这个XSLT(contains())工作?

时间:2017-11-12 20:11:44

标签: xml xslt

我将这部分XSLT与if

放在一起
<xsl:template match="receta">
<xsl:if test="./ingredientes/ingrediente[not(contains(., 'Leche'))] and 
              ./ingredientes/ingrediente[not(contains(., 'Queso'))] ">
    <article>
        <header>
            <h2>
                <xsl:apply-templates select="nombre"/>

和XML的相应部分:

<receta n="R2">
    <nombre>
        Croquetas de bacalao
    </nombre>
    <tipo>
        Primer plato
    </tipo>
    <ingredientes>
        <ingrediente cantidad= "1" unidad="en lomos">
            Bacalao
        </ingrediente>
        <ingrediente cantidad= "850" unidad= "ml.">
            Leche entera
        </ingrediente>

没有not()它有效,但显然它不是我需要的。在这种情况下使用not()的正确方法是什么?

3 个答案:

答案 0 :(得分:1)

如果您的目的是测试单个ingrediente是否包含两个子字符串,请更改

<xsl:if test="./ingredientes/ingrediente[not(contains(., 'Leche'))] and 
              ./ingredientes/ingrediente[not(contains(., 'Queso'))]">

<xsl:if test="ingredientes/ingrediente[not(contains(., 'Leche')) and
                                       not(contains(., 'Queso'))]"> 

否则两个单独的ingrediente可以分别不包含每个子字符串。

答案 1 :(得分:0)

添加变量new_url,如下所示:

ingredientes

答案 2 :(得分:0)

也许您想测试是否所有成分都含有Lecho或Quese。那将是

tag

您的代码正在测试至少有一种不含Leche的成分和至少一种不含Queso的成分,我认为这不会满足对乳制品过敏的人。

相关问题