簡體   English   中英

如何理解這個xsl模板選擇

[英]how to understand this xsl template select

如何理解這個代碼塊,

<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/>適用的模板是什么? 你能對這個問題提出任何線索嗎?

我會高度評價你的幫助。

正如hr_117所示,出於所有實際目的,代碼

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

相當於

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

它實際上並非100%等效,所以在重寫之前要小心謹慎:在第一種情況下,對所選模板中的position()的調用將始終返回1,而在第二種情況下,它將返回testuite中的位置。一套兄弟測試元素。 然而,這不太重要。

<xsl:for-each select="testsuite">語句遍歷當前節點的所有子節點(即testsuites
for-each<xsl:apply-templates select="."/>比“觸發” testsuite模板(未顯示)。

因此,這稱為testsuite模板(用於兒童testsuite )。 這不只是做一些事情,如果有testsuite的內部節點testsuites的節點。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM