如何在xslt中使用group [英] How to use group by in xslt

查看:86
本文介绍了如何在xslt中使用group的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xml,它有很多元素,大部分都包含属性..对于某些属性值是相同的,所以我需要将它们分组并生成diff xml。
I / p Ex:

 < TestNode> 
< ABC1 value =10.7format =$/>
< ABC2 value =10.5format =$/>
< ABC3 value =20format =Rs/>
< ABC4 value =50format =Rs/>
< ABC5 value =10.5format =$/>
< / TestNode>

我需要按格式对行进行分组。 注意:格式不固定...可能会增加...
O / P例如:









有可能得到吗?在此先感谢...

解决方案

在XSLT 2.0中,您应该可以使用< xsl:for-each-group> current-grouping-key() current-group() code

示例:

 < xsl: for-each-group 
select =TestNode / *
group-by =@ format
>
< group format ={current-grouping-key()}>
< xsl:for-each select =current-group()>
< xsl:copy-of select =。/>
< / xsl:for-each>
< / group>
< / xsl:for-each-group>

请参阅: http://www.w3.org/TR/xslt20/#grouping


I have a xml that has so many elements and most of that contain attributes.. for some of the attributes values are same so I need to group them and generate diff xml. I/p Ex:

<TestNode>
 <ABC1 value="10.7" format="$" />
 <ABC2 value="10.5" format="$" />
 <ABC3 value="20" format="Rs" />
 <ABC4 value="50" format="Rs" />
 <ABC5 value="10.5" format="$" />
</TestNode>

I need to group the rows by format. Note: Format is not fixed... it may grow ... O/P Ex: is it possible to get ? Thanks in advance...

解决方案

In XSLT 2.0 you should be able to do it with <xsl:for-each-group>, current-grouping-key() and current-group()

Example:

<xsl:for-each-group 
    select="TestNode/*"
    group-by="@format"
>
    <group format="{current-grouping-key()}">
        <xsl:for-each select="current-group()">
            <xsl:copy-of select="."/>
        </xsl:for-each>
    </group>
</xsl:for-each-group>

See: http://www.w3.org/TR/xslt20/#grouping

这篇关于如何在xslt中使用group的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆