好的,到目前为止,我要创建多个表。
<xsl:for-each select="report/issue">
<table id="@name" class="idwb sortable">
<tr>
<th class="center">Filename</th>
<th class="center">Level</th>
<th class="center">GID</th>
<th class="center">Message</th>
<th class="center">XPath</th>
<th class="center">Line Number</th>
<th class="center">Help</th>
</tr>
<!--xsl:sort select="@filename" order="descending" data-type="text" /-->
<tr onmouseover="this.style.backgroundColor='#f5f6be';"
onmouseout="this.style.backgroundColor= '';">
<xsl:attribute name="class">alt_0</xsl:attribute>
<td class="center">
<a href="{@infocenterURL}"><xsl:value-of select="@filename" /></a>
</td>
<td align="center">
<xsl:value-of select="@level" />
</td>
<td align="center">
<xsl:value-of select="@gid" />
</td>
<td align="center">
<xsl:value-of select="@message" />
</td>
<td align="center">
<xsl:value-of select="@xpath" />
</td>
<td align="center">
<xsl:value-of select="@linenum" />
</td>
<td alight="center">
<a href="{@helplink}">More</a>
</td>
</tr>
</table>
<br />
<br />
</xsl:for-each> 没有什么能让世界着火的。问题是,这会为每个条目创建一个表,但我只想为每个文件名和级别创建表,而与该文件名和级别有关的所有条目都将放在那里。目前是否存在不使用javascript的情况下这样做?
XML示例
<issue filename="file.html"
gid="506"
helplink="www.somewhere.com"
infocenterURL="www.somewhere.com"
level="Potential Violation"
linenum="49"
message="stuff nneeds to happen"
xpath="/html/body/div[3]/img"/>我需要发生的是,对于每个文件名,我需要一个表,其中包含匹配相同文件名和相同冲突级别的所有问题。违规级别被修正为5,我知道所有这些。但是文件名是动态的。
发布于 2013-12-02 15:43:17
如果你想为“每个报告”做些什么(而不是“针对每一个问题”),那么说<xsl:for-each select="report/issue">是行不通的。
但我也要说几句:
:hover伪类,它就是为此目的而创建的。:nth-child(odd)和:nth-child(even)。<xsl:for-each>。使用模板匹配。这样,您将获得更多的模块化,嵌套更少的代码,模板不需要滚动几个屏幕就可以看到它们正在做什么。<thead>和<tbody>是个好主意。align="center"还是class="center"。记住这一点..。
<xsl:template match="/">
<xsl:apply-templates select="report" />
</xsl:template>
<!-- <report> becomes <table>... -->
<xsl:template match="report">
<table id="@name" class="idwb sortable">
<thead>
<tr>
<th class="center">Filename</th>
<th class="center">Level</th>
<th class="center">GID</th>
<th class="center">Message</th>
<th class="center">XPath</th>
<th class="center">Line Number</th>
<th class="center">Help</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="issue">
<xsl:sort select="@filename" order="descending" data-type="text" />
</xsl:apply-templates>
</tbody>
</table>
</xsl:template>
<!-- <issue> becomes <tr>... -->
<xsl:template match="issue">
<tr class="alt_0">
<td class="center"><a href="{@infocenterURL}"><xsl:value-of select="@filename" /></a></td>
<td class="center"><xsl:value-of select="@level" /></td>
<td class="center"><xsl:value-of select="@gid" /></td>
<td class="center"><xsl:value-of select="@message" /></td>
<td class="center"><xsl:value-of select="@xpath" /></td>
<td class="center"><xsl:value-of select="@linenum" /></td>
<td class="center"><a href="{@helplink}">More</a></td>
</tr>
</xsl:template>https://stackoverflow.com/questions/20331267
复制相似问题