Xml 具有嵌套结构的xslt 1.0 groupby
给定一个如下所示的结构:Xml 具有嵌套结构的xslt 1.0 groupby,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,给定一个如下所示的结构: <feed> <entry> <summary>lorem ipsum 1</summary> <updated>2013-11-20T18:40:00Z</updated> <author>Jon</author> </entry> <entry> <sum
<feed>
<entry>
<summary>lorem ipsum 1</summary>
<updated>2013-11-20T18:40:00Z</updated>
<author>Jon</author>
</entry>
<entry>
<summary>lorem ipsum 2</summary>
<updated>2013-11-19T19:40:00Z</updated>
<author>Jon</author>
</entry>
<entry>
<summary>lorem ipsum 3</summary>
<updated>2013-11-19T23:40:00Z</updated>
<author>Rebecca</author>
</entry>
<entry>
<summary>lorem ipsum 4</summary>
<updated>2013-11-18T05:40:00Z</updated>
<author>Paul</author>
</entry>
</feed>
同侧眼底1
2013-11-20T18:40:00Z
,但我还没弄明白
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:key name="groupbydate" match="entry" use="updated"/>
<xsl:template match="feed">
<blah>
<xsl:apply-templates
select="entry[
generate-id()
= generate-id(key('groupbydate', updated)[1])]" />
</blah>
</xsl:template>
<xsl:template match="entry">
<!-- GET the date -->
<xsl:variable name="date" select="substring(updated,1,10)"/>
<today>
<date><xsl:value-of select="$date"/></date>
</today>
<xsl:for-each select="entry">
<xsl:if test="preceding-sibling::entry[substring(updated,1,10) = $date]">
<post>
<xsl:copy-of select="entry"/>
</post>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
将密钥定义为
<xsl:key name="groupbydate" match="entry" use="substring-before(updated, 'T')"/>
那么你需要使用它
<xsl:template match="feed">
<blah>
<xsl:apply-templates
select="entry[
generate-id()
= generate-id(key('groupbydate', substring-before(updated, 'T'))[1])]" />
</blah>
</xsl:template>
然后,您使用
<xsl:template match="entry">
<today>
<date><xsl:value-of select="substring-before(updated, 'T')"/></date>
<xsl:apply-templates select="key('groupbydate', substring-before(updated, 'T'))" mode="entry"/>
</today>
</xsl:template>
<xsl:template match="entry" mode="entry">
<post>
<xsl:copy-of select="node()"/>
</post>
</xsl:template>
每组的项目都有
<xsl:template match="entry">
<today>
<date><xsl:value-of select="substring-before(updated, 'T')"/></date>
<xsl:apply-templates select="key('groupbydate', substring-before(updated, 'T'))" mode="entry"/>
</today>
</xsl:template>
<xsl:template match="entry" mode="entry">
<post>
<xsl:copy-of select="node()"/>
</post>
</xsl:template>
将密钥定义为
<xsl:key name="groupbydate" match="entry" use="substring-before(updated, 'T')"/>
那么你需要使用它
<xsl:template match="feed">
<blah>
<xsl:apply-templates
select="entry[
generate-id()
= generate-id(key('groupbydate', substring-before(updated, 'T'))[1])]" />
</blah>
</xsl:template>
然后,您使用
<xsl:template match="entry">
<today>
<date><xsl:value-of select="substring-before(updated, 'T')"/></date>
<xsl:apply-templates select="key('groupbydate', substring-before(updated, 'T'))" mode="entry"/>
</today>
</xsl:template>
<xsl:template match="entry" mode="entry">
<post>
<xsl:copy-of select="node()"/>
</post>
</xsl:template>
每组的项目都有
<xsl:template match="entry">
<today>
<date><xsl:value-of select="substring-before(updated, 'T')"/></date>
<xsl:apply-templates select="key('groupbydate', substring-before(updated, 'T'))" mode="entry"/>
</today>
</xsl:template>
<xsl:template match="entry" mode="entry">
<post>
<xsl:copy-of select="node()"/>
</post>
</xsl:template>
两者都有。非常感谢,因为它帮助我理解并解决了我的问题。非常感谢。非常感谢,因为它帮助我理解并解决了我的问题。非常感谢。