gpt4 book ai didi

xml - XSL : Why is there no `` tag defined

转载 作者:数据小太阳 更新时间:2023-10-29 02:47:50 25 4
gpt4 key购买 nike

对于条件检查,我们可以选择 <xsl:choose><xsl:if>

<xsl:choose>
<xsl:when test="expression">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output ....
</xsl:otherwise>
</xsl:choose>

<xsl:if test="$admin=$value1">
<control>true</control>
</xsl:if>
<xsl:if test="not($admin=$value1)">
<control>false</control>
</xsl:if>

为什么没有<xsl:else>标签定义?

当我使用 <xsl:if> 时, 如果有 <xsl:else> , 我不需要重复 test="not($admin=$value1)健康)状况。 <xsl:choose>当您有多个案例要检查时很好。当然上面会模拟一个典型的'if-else',但是为什么这么多行代码模拟一个if-else条件

我想知道为什么没有 <xsl:else> 为 XSL 定义的标记?对此有什么想法吗?

最佳答案

这样做需要父节点执行条件逻辑以及与配对有关的逻辑 - 作为 xsl:ifxsl: else 节点将是独立的 sibling 。同样的“问题”存在于其他基于树的控制语法结构中,例如 Knockout。

虽然 xsl:if 可以假设支持以下内容以避免之前的问题(节点是兄弟节点的问题),但这样做也会使其在普通情况下更难使用。

<xsl:if test="$admin=$value1">
<xsl:then-hypothetical>
<control>true</control>
</xsl:then-hypothetical>
<xsl:else-hypothetical>
..
</xsl:else-hypothetical>
</xsl:if>

此外,正如 JLRishe 指出的那样,这种方法将大大低于支持任意数量条件分支的 xsl:choose,因为每个“else if”分支都会引入一个额外的级别(或两个)嵌套元素。

因此,当需要真正的“else”时,只需使用 xsl:choose

关于xml - XSL : Why is there no `<xsl:else>` tag defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22871423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com