以下两个变量定义的行为是否应该有所不同?
第一个定义使用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>风格会导致不同的结果.