0

XSLT 2.0 / XPath 2.0 中的saxon:ifsaxon:before函数是否有替代品?

我有这样的代码:

<xsl:variable name="stop"
  select="(following-sibling::h:h1|following-sibling::h:h2)[1]" />

<xsl:variable name="between"
  select="saxon:if($stop,
                   saxon:before(following-sibling::*, $stop),
                   following-sibling::*)" />

想法是between变量应该包含当前节点和下一个h1或元素之间的所有元素h2(存储在stop变量中),或者所有剩余的元素,如果没有下一个h1h2

我想在新的 XSLT 2.0 模板中使用此代码,并且我正在寻找saxon:ifsaxon:before.

4

3 回答 3

1

saxon.if(A, B, C)现在等同if (A) then B else C于 XPath 2.0

于 2010-12-08T17:28:07.910 回答
0

这是我的解决方案:

<xsl:variable 
     name="stop"
     select="(following-sibling::h:h1|following-sibling::h:h2)[1]" />

<xsl:variable name="between">
    <xsl:choose>
        <xsl:when test="$stop">
            <xsl:sequence select="following-sibling::*[. &lt;&lt; $stop]" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:sequence select="following-sibling::*" />
         </xsl:otherwise>
    </xsl:choose>
</xsl:variable>

它使用<xsl:sequence><<运算符(编码为&lt;&lt;),来自 XSLT 2.0 / XPath 2.0。

它不像原始版本那么短,但它不再使用撒克逊扩展。

于 2009-10-31T15:52:48.220 回答
0

您也可以在 XSLT/XPath 2.0 中只使用一个表达式:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="text()"/>
    <xsl:template match="p[position()=(1,3,4)]">
        <xsl:copy-of select="following-sibling::*
                                [not(self::h2|self::h1)]
                                [not(. >>
                                     current()
                                        /following-sibling::*
                                            [self::h2|self::h1][1])]"/>
    </xsl:template>
</xsl:stylesheet>

使用此输入:

<html>
    <p>1</p>
    <p>2</p>
    <h2>Header</h2>
    <p>3</p>
    <h1>Header</h1>
    <p>4</p>
    <p>5</p>
</html>

输出:

<p>2</p><p>5</p>
于 2010-12-08T19:23:45.243 回答