我有一个XML,其中有n个GRTSource下的GRTSource节点。我只需要GRTSource的前5个节点,并且我想访问表的详细信息,而不管表是否是immidiate子表。XSL将所选节点的子节点与模板相关联
这里是演示文件:
<GRTReport>
<GRTSource>
<title>Unified CM Cluster Name</title>
<comment>Lists the cluster name from the Enterprise Parameter and the publisher server name/IP.</comment>
<title></title>
<comment></comment>
<table summary='Cluster Information'>
<row>
<cell style='header'>Cluster Name</cell>
<cell style='header'>Publisher Name/IP</cell>
</row>
<row>
<cell>xyzw</cell>
<cell>xyz1234</cell>
</row>
</table>
</GRTSource>
<GRTSource>
<div>
<title>Unified CM Cluster Name</title>
<comment>Lists the cluster name from the Enterprise Parameter and the publisher server name/IP.</comment>
<title></title>
<comment></comment>
<table summary='Cluster Information'>
<row>
<cell style='header'>Cluster Name</cell>
<cell style='header'>Publisher Name/IP</cell>
</row>
<row>
<cell>xyzw</cell>
<cell>xyz1234</cell>
</row>
</table>
</div>
</GRTSource>
</GRTReport>
这里是我的xsl:
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="GRTReport/GRTSource[position() < 6]">
<fieldset class="reportSourceFieldset">
<legend>
<xsl:value-of select="title[1]"/>
</legend>
<xsl:apply-templates select="descendant::table"/>
</fieldset>
<br />
</xsl:template>
<xsl:template match="table">
<table class="reportData">
<tr class="cuesTableBg">
<xsl:for-each select="row[position() = 1]/cell">
<th>
<pre>
<xsl:value-of select="current()"/>
</pre>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="row[position() > 1]">
<tr>
<xsl:for-each select="cell">
<xsl:choose>
<xsl:when test="current()[contains(@style,'fixedFormat')]">
<td>
<pre><xsl:value-of select="current()"/></pre>
</td>
</xsl:when>
<xsl:otherwise>
<td>
<span>
<xsl:value-of select="current()"/></span>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
<br />
</xsl:template>
不知怎的,它正在计数GRTSources高达5,但该查询接受外界的5 GRSource算作表好。据逸岸考虑网页上的所有表,而不仅仅是前五名内GRTSource
这是可能的,但不建议由于内的两个复制模板。更好:使用一个''和''/'',分别。 –
Tomalak
@Tomalak,修改后的模板好吗? –
不,这是一样的事情:你会*需要第二个模板来输出位置5之后的''元素。这是一个重复性和不清晰的方法。 - 使用一个可输出''元素的模板。它一定不在乎他们的立场。然后使用''来只输出你想看到的元素。 –
Tomalak