输入和预期输出的示例 XML 文件在底部,需要帮助根据子元素的数量进行分组。
<DashboardXML>
<Column>
<ColumnOrder>1</ColumnOrder>
<ColLabel><![CDATA[test1]]></ColLabel>
</Column>
<Column>
<ColumnOrder>2</ColumnOrder>
<ColLabel><![CDATA[t1est]]></ColLabel>
</Column>
<Column>
<ColumnOrder>3</ColumnOrder>
<ColLabel><![CDATA[terst]]></ColLabel>
</Column>
</DashboardXML>
<DashboardXML>
<Column>
<ColumnOrder>1</ColumnOrder>
<ColLabel><![CDATA[test1]]></ColLabel>
</Column>
<Column>
<ColumnOrder>2</ColumnOrder>
<ColLabel><![CDATA[t1est]]></ColLabel>
</Column>
<Column>
<ColumnOrder>3</ColumnOrder>
<ColLabel><![CDATA[terst]]></ColLabel>
</Column>
</DashboardXML>
<DashboardXML>
<Column>
<ColumnOrder>1</ColumnOrder>
<ColLabel><![CDATA[test1]]></ColLabel>
</Column>
<Column>
<ColumnOrder>2</ColumnOrder>
<ColLabel><![CDATA[t1est]]></ColLabel>
</Column>
</DashboardXML>
<DashboardXML>
<Column>
<ColumnOrder>1</ColumnOrder>
<ColLabel><![CDATA[test1]]></ColLabel>
</Column>
<Column>
<ColumnOrder>2</ColumnOrder>
<ColLabel><![CDATA[t1est]]></ColLabel>
</Column>
<Column>
<ColumnOrder>1</ColumnOrder>
<ColLabel><![CDATA[test1]]></ColLabel>
</Column>
<Column>
<ColumnOrder>2</ColumnOrder>
<ColLabel><![CDATA[t1est]]></ColLabel>
</Column>
</DashboardXML>
<DashboardXML>
<Column>
<ColumnOrder>1</ColumnOrder>
<ColLabel><![CDATA[test1]]></ColLabel>
</Column>
<Column>
<ColumnOrder>2</ColumnOrder>
<ColLabel><![CDATA[t1est]]></ColLabel>
</Column>
</DashboardXML>
上面是作为输入的示例 XML,下面是 XQuery:
for $b in /DashboardXML where count($b/Column) > 0 order by count($b/Column) return <li>{count($b/Column)} </li>
查询产生以下输出(示例):
<li>3</li>
<li>3</li>
<li>2</li>
<li>4</li>
<li>2</li>
现在的问题是如何将输出分组如下:
2 = 2 (counts)
3 = 2 (counts)
4 = 1 (counts)