2014-01-31 27 views
0

我正在研究負責生成報告的junit-frames.xsl文件。我需要在xsl文件中進行一些更改以遵守我們用於顯示內容的格式。我發現很難理解這個複雜的Xpath。請幫助一下。junit-frames.xsl中的複雜Xpath

<xsl:apply-templates select="testsuite[not(./@package = preceding-sibling::testsuite/@package)]" mode="all.packages"> 
     <xsl:sort select="@package"/> 
    </xsl:apply-templates> 

有人可以幫忙嗎?上述

回答

2
testsuite[not(./@package = preceding-sibling::testsuite/@package)] 

xpath表達式意味着:

select element named `testsuite` that match following criteria : 
have attribute `package` with value not equal to : 
attribute `package` of any previous `testsuite` element 

因此,如果你有以下結構例如XML:

<parent> 
    <testsuite package="value1" id="1"/> 
    <testsuite package="value2" id="2"/> 
    <testsuite package="value2" id="3"/> 
    <testsuite package="value1" id="4"/> 
</parent> 

只有第一和第二<testsuite>元件將匹配上述xpath表達式。

+0

所以它會檢查所有以前的兄弟姐妹或只是以前的兄弟姐妹 – anon

+0

所有以前的兄弟 – har07

+0

我已經測試,以確保。我更新的答案顯示了我用來測試的最新XML,結果 – har07