2009-10-31 209 views
0

在XSLT 2.0/XPath 2.0中是否有替換saxon:ifsaxon:before函數?替換爲撒克遜:如果和撒克遜:在函數之前在xslt 2.0

我有這樣的代碼:

<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變量應該包含所有剩餘的元素當前節點和下一h1h2元件(存儲在stop變量)之間的所有的元件,或,如果有沒有下一個h1h2

我想在新的XSLT 2.0模板中使用此代碼,並且正在尋找saxon:ifsaxon:before的替代品。

回答

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><< operator(編碼爲&lt;&lt;),從XSLT 2.0/2.0的XPath。

它不像原始版本那麼短,但它不再使用撒克遜擴展。

1

saxon.if(A, B, C)現在等效if (A) then B else C了XPath 2.0

+0

+1正確答案。 – 2010-12-08 19:09:19

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>