我正在使用这个algo
http://www.jenitennison.com/xslt/grouping/muenchian.html 分组。我能够使用该算法,但我面临一个问题。我有一个xml
,我在其中对Over
应用分组。我能够显示我的数据,但有时@over变得blank
..我不想显示这些数据.. 这是我的代码 http://xsltransform.net/pNmBxZY/1
转型
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:key name="node-by-over" match="Node" use="@Over" />
<xsl:template match="/Innings">
<hmtl>
<head>
<title>New Version!</title>
</head>
<xsl:apply-templates select="Node[generate-id() = generate-id(key('node-by-over', @Over)[1])]"/>
</hmtl>
</xsl:template>
<xsl:template match="Node">
over::: <h1><xsl:value-of select="@Over"/></h1>
<table id="{Over}">
<xsl:for-each select="key('node-by-over', @Over)">
<tr>
<td>balls:::<xsl:value-of select="@Ball"/></td>
<td>runs:::<xsl:value-of select="Runs"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:transform>
当前结果
<!DOCTYPE html
PUBLIC "XSLT-compat">
<hmtl>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Version!</title>
</head>
over:::
<h1>1</h1>
<table id="">
<tr>
<td>balls:::1</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::2</td>
<td>runs:::1</td>
</tr>
<tr>
<td>balls:::3</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::4</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::5</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::6</td>
<td>runs:::2</td>
</tr>
</table>
over:::
<h1></h1>
<table id="">
<tr>
<td>balls:::</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::</td>
<td>runs:::0</td>
</tr>
</table>
over:::
<h1>2</h1>
<table id="">
<tr>
<td>balls:::1</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::2</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::3</td>
<td>runs:::2</td>
</tr>
<tr>
<td>balls:::4</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::5</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::6</td>
<td>runs:::1</td>
</tr>
</table>
over:::
<h1>3</h1>
<table id="">
<tr>
<td>balls:::1</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::2</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::3</td>
<td>runs:::1</td>
</tr>
<tr>
<td>balls:::4</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::5</td>
<td>runs:::1</td>
</tr>
</table>
</hmtl>
预期产出
<!DOCTYPE html
PUBLIC "XSLT-compat">
<hmtl>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Version!</title>
</head>
over:::
<h1>1</h1>
<table id="">
<tr>
<td>balls:::1</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::2</td>
<td>runs:::1</td>
</tr>
<tr>
<td>balls:::3</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::4</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::5</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::6</td>
<td>runs:::2</td>
</tr>
</table>
over:::
<h1>2</h1>
<table id="">
<tr>
<td>balls:::1</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::2</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::3</td>
<td>runs:::2</td>
</tr>
<tr>
<td>balls:::4</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::5</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::6</td>
<td>runs:::1</td>
</tr>
</table>
over:::
<h1>3</h1>
<table id="">
<tr>
<td>balls:::1</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::2</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::3</td>
<td>runs:::1</td>
</tr>
<tr>
<td>balls:::4</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::5</td>
<td>runs:::1</td>
</tr>
</table>
</hmtl>
当前输出和预期输出之间的差异
over:::
<h1></h1>
<table id="">
<tr>
<td>balls:::</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::</td>
<td>runs:::0</td>
</tr>
</table>
我不想遍历那个blank
@OverNode
..请参阅xml中的示例
<Node Id="14" Over=""
我不想遍历id="14",因为它没有超值,但是当前的代码正在这样做,为什么它显示在html部分上方? 如何应用检查?
当前最后一个节点显示如下
over:::
<h1>3</h1>
<table id="">
<tr>
<td>balls:::1</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::2</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::3</td>
<td>runs:::1</td>
</tr>
<tr>
<td>balls:::4</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::5</td>
<td>runs:::1</td>
</tr>
</table>
我们可以这样展示吗
over:::
<h1>2.5</h1>
<table id="">
<tr>
<td>balls:::1</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::2</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::3</td>
<td>runs:::1</td>
</tr>
<tr>
<td>balls:::4</td>
<td>runs:::0</td>
</tr>
<tr>
<td>balls:::5</td>
<td>runs:::1</td>
</tr>
</table>
@over.@ball(最后一个节点)
如果我理解正确,您想更改:
<xsl:apply-templates select="Node[generate-id() = generate-id(key('node-by-over', @Over)[1])]"/>
自:
<xsl:apply-templates select="Node[@Over>0][generate-id() = generate-id(key('node-by-over', @Over)[1])]"/>