繁体   English   中英

XSLT 1.0:有条件的

[英]XSLT 1.0: Conditional For-Each

我给出了以下XML,其中包含随机数量的“ Note”元素:

<Notes>
   <Note>
       <Size>400000</Size>
   </Note>
   <Note>
       <Size>200000</Size>
   </Note>
   <Note>
       <Size>500000</Size>
   </Note>
</Notes>

我想检查一下这些Notes中是否有一个size元素等于或大于500000。如果是这种情况,我想调用主模板。 如果没有,我想做点别的。

我遇到的问题是:如果我在for-each循环中具有if-then逻辑,那么我将多次调用该模板。 由于xslt中没有中断功能,因此我当时想使用一个变量,如果满足条件,则将其设置为true,如果设置为true,则将for-each称为模板。 但这不是我真正担心的最佳方法,您认为呢?

提前致谢。

无需for-each循环。 这样的事情会做你想要的:

<xsl:template match="Notes">
    <xsl:choose>
        <xsl:when test="number(descendant::Size/text()) &gt; 500000">
        <xsl:call-template name="process Note"/>
        </xsl:when>
        <xsl:otherwise>
        <xsl:call-template name="add attribute to Note"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM