[英]XSL style: using <xsl:for-each select> or <xsl:template match> or other solutions in XSLT?
[英]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.