2013-07-02 14 views
1

如何理解這個代碼塊,如何理解這個XSL模板選擇

<xsl:for-each select="testsuite"> 
    <xsl:apply-templates select="."/> 
</xsl:for-each> 

使用下,

<xsl:template match="testsuites"> 
    <table border="1" width="100%"> 
    <tr bgcolor="#9acd32"> 
     <th align="left">module</th> 
     <th align="left">tests</th> 
     <th align="left">time</th> 
    </tr> 
    <tr> 
     <td><xsl:value-of select="@name"/></td> 
     <td><xsl:value-of select="@tests"/></td> 
     <td><xsl:value-of select="@time"/></td> 
    </tr> 
    </table> 
    <br/> 

    <xsl:for-each select="testsuite"> 
     <xsl:apply-templates select="."/> 
    </xsl:for-each> 
</xsl:template> 

什麼模板<xsl:apply-templates/>申請,根據上面的代碼? 你能提供關於這個問題的任何線索嗎?

我會高度評價你的幫助。

回答

3

由於hr_117表示,所有的實際目的的代碼

<xsl:for-each select="testsuite"> 
    <xsl:apply-templates select="."/> 
</xsl:for-each> 

相當於

<xsl:apply-templates select="testsuite"/> 

這相當於實際上不是100%,所以改寫它之前進行輕微的警告:在第一種情況下,所選模板中position()的調用將始終返回1,而在第二種情況下,它將返回測試套件在同組測試套件元素中的位置。然而,這不太可能是重要的。

1

<xsl:for-each select="testsuite">聲明遍歷當前節點的所有兒童(這是testsuites
<xsl:apply-templates select="."/>比「觸發」的testsuite模板(未示出)的for-each意志裏面。

因此這就要求testsuite模板(兒童testsuite) 。這不只是做一些事情,如果有testsuites節點內testsuite節點。

另外for-each不需要<xsl:apply-templates select="testsuite"/>也會這樣做。