如何在XSL中为每个组使用 [英] How to use for each group in XSL
本文介绍了如何在XSL中为每个组使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我仍在学习 for-each-group
使用 XSL 对此类内容进行分组的最佳方法是什么?(按国家/地区)我正在尝试使用 XSL 将此 XML 转换为另一个 XML.
im still learning for-each-group
what is the best way of grouping something like this using XSL?(by country) i'm trying to use XSL to convert this XML to another XML.
<?xml version="1.0" encoding="UTF-8"?>
<Person>
<Student>
<Info Country="England" Name="Dan" Age="20" Class="C" />
</Student>
<Student>
<Info Country="England" Name="Dan" Age="20" Class="B" />
</Student>
<Student>
<Info Country="England" Name="Sam" Age="20" Class="A" />
</Student>
<Student>
<Info Country="Australia" Name="David" Age="22" Class="D" />
</Student>
<Student>
<Info Country="Australia" Name="David" Age="22" Class="A" />
</Student>
</Person>
推荐答案
如果您按国家/地区分组,您将从例如开始
If you group by country you would start with e.g.
<xsl:template match="Person">
<xsl:for-each-group select="Student/Info" group-by="@Country">
<country name="{current-grouping-key()}">
</country>
</xsl:for-each-group>
</xsl:template>
然后您必须决定是否要进一步分组每个国家/地区组中的 Info
元素,例如按名称:
Then you have to decide whether you want to further group the Info
elements in each country group, for instance by name:
<xsl:template match="Person">
<xsl:for-each-group select="Student/Info" group-by="@Country">
<country name="{current-grouping-key()}">
<xsl:for-each-group select="current-group()" group-by="@Name">
<student name="{current-grouping-key()}">
<classes>
<xsl:for-each select="current-group()">
<class><xsl:value-of select="@Class"/></class>
</xsl:for-each>
</classes>
</student>
</xsl:for-each-group>
</country>
</xsl:for-each-group>
</xsl:template>
这篇关于如何在XSL中为每个组使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文