如何在xslt中使用GROUPBY
我有一个xml,它有很多元素,其中大多数包含属性。。因为有些属性值是相同的,所以我需要对它们进行分组并生成diff-xml。 I/p Ex:如何在xslt中使用GROUPBY,xslt,group-by,Xslt,Group By,我有一个xml,它有很多元素,其中大多数包含属性。。因为有些属性值是相同的,所以我需要对它们进行分组并生成diff-xml。 I/p Ex: 我需要按格式将行分组注意:格式不固定。。。它可能会增长… O/P Ex: 有可能得到吗?提前感谢…在XSLT2.0中,您应该能够使用、当前分组-key()和当前分组() 例如: <xsl:for-each-group select="TestNode/*" group-by="@format" > <grou
我需要按格式将行分组注意:格式不固定。。。它可能会增长…
O/P Ex:
有可能得到吗?提前感谢…在XSLT2.0中,您应该能够使用
、当前分组-key()
和当前分组()
例如:
<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>
请参阅:在XSLT1.0中,您将使用Muenchian分组
定义一个键“format”,我们可以从中轻松地选择给定格式名称的所有元素。然后应用Muenchian分组来查找输入中的唯一格式
然后就变得简单了。每个格式将应用一次“*”模板,并使用key()获取该格式的所有条目
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="format" match="TestNode/*" use="@format" />
<xsl:template match="TestNode">
<body>
<xsl:apply-templates select="*[generate-id(.)=generate-id(key('format',@format)[1])]"/>
</body>
</xsl:template>
<xsl:template match="*">
<format format="{@format}">
<xsl:copy-of select="key('format', @format)" />
</format>
</xsl:template>
</xsl:stylesheet>
您使用的是XSLT1.0还是XSLT2.0?我使用的是XSLT1.0。VS 2008是否提供2.0?Microsoft没有XSLT 2.0实现。可从www.saxonica.com获得Saxon.NET实现。xsl:for each group上的属性称为“groupby”,而不是“groupby”。为什么每个人都要复制组中的每个项目,为什么不简单地代替“每个人”呢?马丁,谢谢你指出组中的拼写错误。我希望我提供的规范链接不会浪费在所有逐字复制我建议的人身上。至于每个
的,目的是建议如何访问组中的各个项目。事实上,如果你想做的只是复制这些物品,那么是的,事实上,你可以只使用一份副本。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="format" match="TestNode/*" use="@format" />
<xsl:template match="TestNode">
<body>
<xsl:apply-templates select="*[generate-id(.)=generate-id(key('format',@format)[1])]"/>
</body>
</xsl:template>
<xsl:template match="*">
<format format="{@format}">
<xsl:copy-of select="key('format', @format)" />
</format>
</xsl:template>
</xsl:stylesheet>