tags:

views:

93

answers:

1

Is there any replacement for saxon:if and saxon:before functions in XSLT 2.0 / XPath 2.0?

I have code like this:

<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::*)" />

Idea is that between variable should contain all elements between current node and next h1 or h2 element (stored in stop variable), or all remaining elements, if there is no next h1 or h2.

I'd like to use this code in new XSLT 2.0 template, and I am looking for replacement for saxon:if and saxon:before.

A: 

Here is my solution:

<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>

It uses <xsl:sequence> and << operator (encoded as &lt;&lt;), from XSLT 2.0 / XPath 2.0.

It's not as short as original version, but it doesn't use saxon extensions anymore.

Peter Štibraný