小编Tob*_*enz的帖子

@select与if和嵌套<xsl:choice>之间的区别?

以下两个变量定义的行为是否应该有所不同?

第一个定义使用XPath 2 if声明:

<xsl:variable name="content" select="if ($next-divm)
    then (./following-sibling::node() intersect $next-divm/preceding-sibling::node())
    else (./following-sibling::node())"/>
Run Code Online (Sandbox Code Playgroud)

第二个定义用于<xsl:choose>达到相同的结果(或者我认为):

<xsl:variable name="content1">
    <xsl:choose>
        <xsl:when test="$next-divm">
            <xsl:copy-of select="./following-sibling::node() intersect $next-divm/preceding-sibling::node()"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:copy-of select="./following-sibling::node()"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>
Run Code Online (Sandbox Code Playgroud)

但是,当$content使用输出时,这两种技术会导致两种不同的结果

<xsl:apply-templates select="$content" mode="keep"/>
Run Code Online (Sandbox Code Playgroud)

在第一种情况下,所有内容都被正确复制(即保留所有元素和文本节点),而在后者中仅保留文本节点.这种奇怪的行为可能与以下其他两个模板相关联.

<xsl:template match="node()[not(self::divm)][./preceding-sibling::divm]"/>

<xsl:template match="node()[not(self::divm)][./preceding-sibling::divm]" mode="keep">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()" mode="keep"/>
    </xsl:copy>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

无论我的具体模板如何,我都想知道为什么这两种<xsl:variable>风格会导致不同的结果.

xml xslt xpath xslt-2.0 xpath-2.0

2
推荐指数
1
解决办法
220
查看次数

标签 统计

xml ×1

xpath ×1

xpath-2.0 ×1

xslt ×1

xslt-2.0 ×1