本文介绍了在XSLT中按月和年份分组XML节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 更新 我正在Umbraco的自定义博客上工作。 Umbraco吐出XML作为输出,然后使用XSLT读取。 XML的结构如下 博客 博客中心 房间 博客文章 博客文章 博客文章 博客文章 博客中心 房间 这是XML代码,我已经清理了很多,使其至少有些可读。 < Blog id =1078parentID =1049level =2writerID =0creatorID =0nodeType =1073template =1089sortOrder = 7createDate =2010-09-27T14:11:04updateDate =2010-10-12T16:59:12nodeName =BlogwriterName =AdministratorcreatorName =Administratorpath = - 1, 1049,1078isDoc => < newPageTitle> The Lorem Ipsum Blog< / newPageTitle> < BlogCentre id =1079parentID =1078level =3writerID =0creatorID =0nodeType =1075template =1076sortOrder =1createDate = 2010-09-27T14:11:49updateDate =2010-10-07T14:43:13nodeName =Blog Center 1writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078, 1079isDoc => < Room id =1081parentID =1079level =4writerID =0creatorID =0nodeType =1077template =0sortOrder =1createDate = 2010-09-27T14:12:26updateDate =2010-10-07T14:43:06nodeName =Room 10writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1081isDoc => < BlogPost id =1175parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1192sortOrder =1createDate = 2010-10-07T14:51:48updateDate =2010-10-12T21:30:53nodeName =第一次博客文章writerName =AdministratorcreatorName =Administratorpath = - 1,1049, 10,D=> < topicTitle>第一个博客< / topicTitle> < / BlogPost> < BlogPost id =1180parentID =1081level =5writerID =0creatorID =3nodeType =1087template =1089sortOrder =2createDate = 2010-10-08T15:52:20updateDate =2010-10-12T16:57:00nodeName =asdasdwriterName =AdministratorcreatorName =ZXpath = - 1,1049,1078,1079, 1081,1180isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < / BlogPost> < BlogPost id =1181parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =3createDate = 2010-10-08T17:50:19updateDate =2010-10-12T11:40:37nodeName =condimentumwriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079, 1081,1181isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-09-01T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1194parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =4createDate = 2010-10-12T11:41:50updateDate =2010-10-12T11:42:37nodeName =Nam auguewriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1081,1194isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-08-05T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1195parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =5createDate = 2010-10-12T11:42:15updateDate =2010-10-12T11:42:25nodeName =due not nuncwriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1081,1195isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-08-12T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1196parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =6createDate = 2010-10-12T12:05:57updateDate =2010-10-12T12:08:40nodeName =cursus conguewriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1081,1196isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2009-10-22T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1197parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =7createDate = 2010-10-12T12:08:54updateDate =2010-10-12T12:09:24nodeName =inceptoswriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079, 1081,1197isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2009-11-19T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1198parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =8createDate = 2010-10-12T12:09:45updateDate =2010-10-12T12:10:13nodeName =inceptos himenaeoswriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1081,1198isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2009-12-16T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1199parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =9createDate = 2010-10-12T12:10:29updateDate =2010-10-12T12:10:56nodeName =becatwriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079, 1081,1199isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-01-13T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1200parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =10createDate = 2010-10-12T12:11:08updateDate =2010-10-12T12:11:35nodeName =himenaeoswriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079, 1081,1200isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-02-09T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1201parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =11createDate = 2010-10-12T12:11:45updateDate =2010-10-12T12:12:35nodeName =cursus conguewriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1081,1201isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-04-22T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1202parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =12createDate = 2010-10-12T12:12:18updateDate =2010-10-12T12:12:45nodeName =pharetrawriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079, 1081,1202isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-03-09T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1203parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =13createDate = 2010-10-12T12:13:05updateDate =2010-10-12T12:13:27nodeName =inceptos himenaeoswriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1081,1203isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-05-26T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1204parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =14createDate = 2010-10-12T12:13:36updateDate =2010-10-12T12:13:56nodeName =pharetrawriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079, 1081,1204isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-06-11T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1205parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =15createDate = 2010-10-12T12:14:06updateDate =2010-10-12T12:14:41nodeName =Fusce auguewriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1081,1205isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-07-08T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1206parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =16createDate = 2010-10-12T12:14:52updateDate =2010-10-12T12:15:19nodeName =pharetra et fermentumwriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078, 1079,1081,1206isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-08-09T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1207parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =17createDate = 2010-10-12T12:15:31updateDate =2010-10-12T12:15:51nodeName =Fusce augue puruswriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078, isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-09-14T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1208parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =18createDate = 2010-10-12T12:16:25updateDate =2010-10-12T12:16:45nodeName =类aptent tacitiwriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078, 1079,1081,1208isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-06-04T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1209parentID =1081level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =19createDate = 2010-10-12T12:17:01updateDate =2010-10-12T12:17:29nodeName =类aptentwriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1081,1209isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-06-21T00:00:00< / archiveUnder> < / BlogPost> < / Room> < Room id =1082parentID =1079level =4writerID =0creatorID =0nodeType =1077template =0sortOrder =2createDate = 2010-09-27T14:12:33updateDate =2010-10-07T14:43:09nodeName =Test BlogwriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1082isDoc => < BlogPost id =1182parentID =1082level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =1createDate = 2010-10-08T17:51:19updateDate =2010-10-08T17:51:58nodeName =Test BlogwriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1082,1182isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < / BlogPost> < / Room> < Room id =1083parentID =1079level =4writerID =0creatorID =0nodeType =1077template =1089sortOrder =3createDate = 2010-09-27T14:12:40updateDate =2010-10-07T14:49:48nodeName =Test BlogwriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1083isDoc => < BlogPost id =1183parentID =1083level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =1createDate = 2010-10-08T17:52:22updateDate =2010-10-08T17:52:39nodeName =Test BlogwriterName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1083,1183isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < / BlogPost> < / Room> < / BlogCentre> < BlogCentre id =1080parentID =1078level =3writerID =0creatorID =0nodeType =1075template =1076sortOrder =2createDate = 2010-09-27T14:11:55updateDate =2010-10-07T14:43:23nodeName =Blog Center 2writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078, 1080isDoc =>> < Room id =1084parentID =1080level =4writerID =0creatorID =0nodeType =1077template =0sortOrder =1createDate = 2010-09-27T14:12:45updateDate =2010-10-07T14:43:17nodeName =Room 1writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1080 ,1084isDoc => < BlogPost id =1184parentID =1084level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =1createDate = 2010-10-08T17:53:05updateDate =2010-10-08T17:53:29nodeName =Blog Post 3writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078, 1080,1084,1184isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < / BlogPost> < / Room> < Room id =1085parentID =1080level =4writerID =0creatorID =0nodeType =1077template =0sortOrder =2createDate = 2010-09-27T14:12:50updateDate =2010-10-07T14:43:19nodeName =Room 2writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1080 ,1085isDoc => < BlogPost id =1185parentID =1085level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =1createDate = 2010-10-08T17:53:51updateDate =2010-10-08T17:54:15nodeName =Blog Post 109writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078, 1080,1085,1185isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < / BlogPost> < / Room> < Room id =1086parentID =1080level =4writerID =0creatorID =0nodeType =1077template =1089sortOrder =3createDate = 2010-09-27T14:12:55updateDate =2010-10-07T14:50:39nodeName =Room 3writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1080 ,1086isDoc => < BlogPost id =1186parentID =1086level =5writerID =0creatorID =0nodeType =1087template =1089sortOrder =1createDate = 2010-10-08T17:54:28updateDate =2010-10-08T17:54:51nodeName =Blog Post 123writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078, 1080,1086,1186isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < / BlogPost> < / Room> < / BlogCentre> < / Blog> 在Umbraco XSLT样式表中,有一个参数传递给当前页面。 < xsl:param name =currentPage/> 这将永远是父节点< Blog /> ; ,所以我们必须从这里开始。 你会注意到< Blog /> 和< BlogPost /> ,但是我们要计算每个< BlogCentre /> 和< Room /> 。 为此,我一直在使用 code>< xsl:for-each select =$ currentPage / descendant :: BlogPost/> 无论中心/房间如何,都选择所有博客帖子 / p> 现在我的要求是通过月份和年份(包括每个月的帖子计数)对这些博客帖子进行分组。我想要分组的日期是属性 createDate UNLESS 有一个称为< archiveUnder> some-date-here< / archiveUnder> 。进一步解释 更新 我可以通过检查属性是否为空,轻松完成此部分,因此如果需要,解决方案可以省略此部分。 < BlogPost createDate =2010-10-08T17:52:22 > <! - no archiveUnder - > < / BlogPost> ^ 使用创建日期 < BlogPost createDate =2010-10-08T17:52:22> < archiveUnder> 2010-10-08T17:51:19< / archiveUnder> < / BlogPost> ^ 使用archiveUnder < ul> < li> < h3> 2010< / h3> < ul> < li> 9月(4)< / li> < li> August(2)< / li> < li> June(5)< / li> <! - 没有7月,因为没有帖子 - > < / ul> < / li> < li> < h3> 2009< / h3> < ul> < li> April(4)< / li> < li> March(2)< / li> < li> January(5)< / li> <! - 没有2月,因为没有帖子 - > < / ul> < / li> < / ul> 解决方案 此转换行,但格式化为可读性): < xsl:stylesheet version =1.0 xmlns:xsl = $$$$xmlns:m =my:monthsexclude-result-prefixes =m> < xsl:output omit-xml-declaration =yesindent =yes/> < xsl:param name =currentPageselect =/ */> < m:months> < m> January< / m> < m> February< / m> < m> March< / m> < m> April< / m> < m> May< / m> < m> June< / m> < m> July< / m> < m> August< / m> < m> September< / m> < m> October< / m> < m> November< / m> < m> December< / m> < / m:months> < xsl:variable name =vMonthNamesselect = document('')/ * / m:months / */> < xsl:key name =kPostsByYearmatch =BlogPost use =substring-before( concat(archiveUnder, @createDate [not (archiveUnder)] ),' - ')/> < xsl:key name =kPostsByYearMonthmatch =BlogPost use =substring( concat(archiveUnder, @createDate [not(archiveUnder )] ), 1,7 )/> < xsl:template match =/> < ul> < xsl:apply-templates mode =yearselect = $ currentPage / * / * / BlogPost [generate-id() = generate-id(key('kPostsByYear', substring-before( concat(archiveUnder, @createDate [not(archiveUnder)] ),' '))[1] )] > < xsl:sort order =descendingselect = substring-before( concat(archiveUnder, @createDate [not(archiveUnder)] ) , ' - ')/> < / xsl:apply-templates> < / ul> < / xsl:template> < xsl:template match =BlogPostmode =year> < xsl:variable name =vYearselect = substring-before( concat(archiveUnder, @createDate [not(archiveUnder)] ) , ' - ')/> < xsl:variable name =vyearBlogs select =key('kPostsByYear',$ vYear)/> < li> < h3>< xsl:value-of select =$ vYear/>< / h3> < ul> < xsl:apply-templates mode =monthselect = $ vyearBlogs [generate-id() = generate-id(key 'kPostsByYearMonth', substring( concat(archiveUnder, @createDate [not(archiveUnder)] ), 1,7 ))[1] )] > < xsl:sort order =descendingselect = substring( concat(archiveUnder, @createDate [not(archiveUnder)] ), 6,2) /> < / xsl:apply-templates> < / ul> < / li> < / xsl:template> < xsl:template match =BlogPostmode =month> < xsl:variable name =vMonthselect = substring( concat(archiveUnder, @createDate [not(archiveUnder)] ), 6,2)/> < xsl:variable name =vmonthsBlogsselect = key('kPostsByYearMonth', substring( concat(archiveUnder, @ createDate [not(archiveUnder)] ), 1,7))/> < li>< xsl:value-of select = concat($ vMonthNames [position()= $ vMonth],'(', count vmonthsBlogs),')')/> < / li> < / xsl:template> < / xsl:stylesheet> 应用于提供的示例XML文档(我们正在访问每个节点关闭 $ currentPage < xsl:param> ,因为这将在真正的Umbraco案例中),格式化为可读性并且元素名称后面的第一行上移动的每个 BlogPost 的 createDate 属性 < Blog id =1078parentID =1049level =2writerID =0creatorID =0nodeType =1073 template =1089sortOrder =7createDate =2010-09-27T14:11:04updateDate =2010-10-12T16:59:12nodeName =BlogwriterName =AdministratorcreatorName =Administrator path = - 1,1049,1078isDoc => < newPageTitle> The Lorem Ipsum Blog< / newPageTitle> < BlogCentre id =1079parentID =1078level =3writerID =0creatorID =0nodeType =1075template =1076sortOrder =1createDate = 2010-09-27T14:11:49updateDate =2010-10-07T14:43:13nodeName =Blog Center 1writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078, 1079isDoc => < Room id =1081parentID =1079level =4writerID =0creatorID =0nodeType =1077template =0sortOrder =1createDate = 2010-09-27T14:12:26updateDate =2010-10-07T14:43:06nodeName =Room 10writerName =AdministratorcreatorName =Administratorpath = - 1,1049,1078,1079 ,1081isDoc => < BlogPost id =1175parentID =1081level =5 createDate =2010-10-07T14:51:48 writerID =0creatorID = 0nodeType =1087 template =1192sortOrder =1 updateDate =2010-10-12T21:30:53 nodeName =第一个Blog writerName =Administrator creatorName =Administrator path = - 1,1049,1078,1079,1081,1175isDoc => < topicTitle>第一个博客< / topicTitle> < archiveUnder /> < / BlogPost> < BlogPost id =1180parentID =1081 createDate =2010-10-08T15:52:20 level =5writerID =0creatorID = 3 nodeType =1087template =1089 sortOrder =2 updateDate =2010-10-12T16:57:00nodeName =asdasd writerName =AdministratorcreatorName =ZX path = - 1,1049,1078,1079,1081,1180isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < / BlogPost> < BlogPost id =1181parentID =1081level =5 createDate =2010-10-08T17:50:19 writerID =0creatorID = 0nodeType =1087 template =1089sortOrder =3 updateDate =2010-10-12T11:40:37 nodeName =condimentum writerName =Administrator creatorName =Administrator path = - 1,1049,1078,1079,1081,1181isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-09-01T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1194parentID =1081level =5 createDate =2010-10-12T11:41:50 writerID =0creatorID = 0nodeType =1087 template =1089sortOrder =4 updateDate =2010-10-12T11:42:37 nodeName =Nam auguewriterName =Administrator creatorName =Administrator path = - 1,1049,1078,1079,1081,1194isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-08-05T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1195parentID =1081level =5 createDate =2010-10-12T11:42:15 writerID =0creatorID = 0nodeType =1087 template =1089sortOrder =5 updateDate =2010-10-12T11:42:25 nodeName =becat nunc writerName =Administrator creatorName =Administrator path = - 1,1049,1078,1079,1081,1195isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-08-12T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1196parentID =1081level =5 createDate =2010-10-12T12:05:57 writerID =0creatorID = 0nodeType =1087 template =1089sortOrder =6 updateDate =2010-10-12T12:08:40 nodeName =cursus congue writerName =Administrator creatorName =Administrator path = - 1,1049,1078,1079,1081,1196isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2009-10-22T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1197parentID =1081level =5 createDate =2010-10-12T12:08:54 writerID =0creatorID = 0nodeType =1087 template =1089sortOrder =7 updateDate =2010-10-12T12:09:24 nodeName =inceptoswriterName = Administrator creatorName =Administrator path = - 1,1049,1078,1079,1081,1197isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2009-11-19T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1198parentID =1081level =5 createDate =2010-10-12T12:09:45 writerID =0creatorID = 0nodeType =1087 template =1089sortOrder =8 updateDate =2010-10-12T12:10:13 nodeName =inceptos himenaeos writerName =Administrator creatorName =Administrator path = - 1,1049,1078,1079,1081,1198isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2009-12-16T00:00:00< / archiveUnder> < / BlogPost> < BlogPost id =1199parentID =1081level =5 createDate =2010-10-12T12:10:29 writerID =0creatorID = 0nodeType =1087 template =1089sortOrder =9 updateDate =2010-10-12T12:10:56 nodeName =becatwriterName = Administrator creatorName =Administrator path = - 1,1049,1078,1079,1081,1199isDoc => < topicTitle> Lorem Ipsum< / topicTitle> < archiveUnder> 2010-01-13T00:00:00< / archiveUnder> < / BlogPost> <BlogPost id=\"1200\" parentID=\"1081\" level=\"5\" createDate=\"2010-10-12T12:11:08\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"10\" updateDate=\"2010-10-12T12:11:35\" nodeName=\"himenaeos\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1081,1200\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-02-09T00:00:00</archiveUnder> </BlogPost> <BlogPost id=\"1201\" parentID=\"1081\" level=\"5\" createDate=\"2010-10-12T12:11:45\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"11\" updateDate=\"2010-10-12T12:12:35\" nodeName=\"cursus congue\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1081,1201\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-04-22T00:00:00</archiveUnder> </BlogPost> <BlogPost id=\"1202\" parentID=\"1081\" level=\"5\" createDate=\"2010-10-12T12:12:18\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"12\" updateDate=\"2010-10-12T12:12:45\" nodeName=\"pharetra\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1081,1202\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-03-09T00:00:00</archiveUnder> </BlogPost> <BlogPost id=\"1203\" parentID=\"1081\" level=\"5\" createDate=\"2010-10-12T12:13:05\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"13\" updateDate=\"2010-10-12T12:13:27\" nodeName=\"inceptos himenaeos\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1081,1203\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-05-26T00:00:00</archiveUnder> </BlogPost> <BlogPost id=\"1204\" parentID=\"1081\" level=\"5\" createDate=\"2010-10-12T12:13:36\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"14\" updateDate=\"2010-10-12T12:13:56\" nodeName=\"pharetra\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1081,1204\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-06-11T00:00:00</archiveUnder> </BlogPost> <BlogPost id=\"1205\" parentID=\"1081\" level=\"5\" createDate=\"2010-10-12T12:14:06\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"15\" updateDate=\"2010-10-12T12:14:41\" nodeName=\"Fusce augue\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1081,1205\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-07-08T00:00:00</archiveUnder> </BlogPost> <BlogPost id=\"1206\" parentID=\"1081\" level=\"5\" createDate=\"2010-10-12T12:14:52\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"16\" updateDate=\"2010-10-12T12:15:19\" nodeName=\"pharetra et fermentum\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1081,1206\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-08-09T00:00:00</archiveUnder> </BlogPost> <BlogPost id=\"1207\" parentID=\"1081\" createDate=\"2010-10-12T12:15:31\" level=\"5\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"17\" updateDate=\"2010-10-12T12:15:51\" nodeName=\"Fusce augue purus\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1081,1207\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-09-14T00:00:00</archiveUnder> </BlogPost> <BlogPost id=\"1208\" parentID=\"1081\" level=\"5\" createDate=\"2010-10-12T12:16:25\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"18\" updateDate=\"2010-10-12T12:16:45\" nodeName=\"Class aptent taciti\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1081,1208\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-06-04T00:00:00</archiveUnder> </BlogPost> <BlogPost id=\"1209\" parentID=\"1081\" level=\"5\" createDate=\"2010-10-12T12:17:01\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"19\" updateDate=\"2010-10-12T12:17:29\" nodeName=\"Class aptent\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1081,1209\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-06-21T00:00:00</archiveUnder> </BlogPost> </Room> <Room id=\"1082\" parentID=\"1079\" level=\"4\" createDate=\"2010-09-27T14:12:33\" writerID=\"0\" creatorID=\"0\" nodeType=\"1077\" template=\"0\" sortOrder=\"2\" updateDate=\"2010-10-07T14:43:09\" nodeName=\"Test Blog\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1082\" isDoc=\"\"> <BlogPost id=\"1182\" parentID=\"1082\" level=\"5\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"1\" createDate=\"2010-10-08T17:51:19\" updateDate=\"2010-10-08T17:51:58\" nodeName=\"Test Blog\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1082,1182\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> <Room id=\"1083\" parentID=\"1079\" level=\"4\" writerID=\"0\" createDate=\"2010-09-27T14:12:40\" creatorID=\"0\" nodeType=\"1077\" template=\"1089\" sortOrder=\"3\" updateDate=\"2010-10-07T14:49:48\" nodeName=\"Test Blog\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1083\" isDoc=\"\"> <BlogPost id=\"1183\" parentID=\"1083\" level=\"5\" writerID=\"0\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"1\" createDate=\"2010-10-08T17:52:22\" updateDate=\"2010-10-08T17:52:39\" nodeName=\"Test Blog\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1079,1083,1183\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> </BlogCentre> <BlogCentre id=\"1080\" parentID=\"1078\" level=\"3\" writerID=\"0\" createDate=\"2010-09-27T14:11:55\" creatorID=\"0\" nodeType=\"1075\" template=\"1076\" sortOrder=\"2\" updateDate=\"2010-10-07T14:43:23\" nodeName=\"Blog Centre 2\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1080\" isDoc=\"\"> <Room id=\"1084\" parentID=\"1080\" level=\"4\" writerID=\"0\" creatorID=\"0\" nodeType=\"1077\" template=\"0\" sortOrder=\"1\" createDate=\"2010-09-27T14:12:45\" updateDate=\"2010-10-07T14:43:17\" nodeName=\"Room 1\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1080,1084\" isDoc=\"\"> <BlogPost id=\"1184\" parentID=\"1084\" level=\"5\" writerID=\"0\" createDate=\"2010-10-08T17:53:05\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"1\" updateDate=\"2010-10-08T17:53:29\" nodeName=\"Blog Post 3\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1080,1084,1184\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> <Room id=\"1085\" parentID=\"1080\" level=\"4\" writerID=\"0\" createDate=\"2010-09-27T14:12:50\" creatorID=\"0\" nodeType=\"1077\" template=\"0\" sortOrder=\"2\" updateDate=\"2010-10-07T14:43:19\" nodeName=\"Room 2\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1080,1085\" isDoc=\"\"> <BlogPost id=\"1185\" parentID=\"1085\" level=\"5\" writerID=\"0\" createDate=\"2010-10-08T17:53:51\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"1\" updateDate=\"2010-10-08T17:54:15\" nodeName=\"Blog Post 109\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1080,1085,1185\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> <Room id=\"1086\" parentID=\"1080\" level=\"4\" writerID=\"0\" creatorID=\"0\" nodeType=\"1077\" template=\"1089\" sortOrder=\"3\" createDate=\"2010-09-27T14:12:55\" updateDate=\"2010-10-07T14:50:39\" nodeName=\"Room 3\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1080,1086\" isDoc=\"\"> <BlogPost id=\"1186\" parentID=\"1086\" level=\"5\" writerID=\"0\" createDate=\"2010-10-08T17:54:28\" creatorID=\"0\" nodeType=\"1087\" template=\"1089\" sortOrder=\"1\" updateDate=\"2010-10-08T17:54:51\" nodeName=\"Blog Post 123\" writerName=\"Administrator\" creatorName=\"Administrator\" path=\"-1,1049,1078,1080,1086,1186\" isDoc=\"\"> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> </BlogCentre> </Blog> produces the wanted, correct result:<ul> <li> <h3>2010</h3> <ul> <li>October (7)</li> <li>September (2)</li> <li>August (3)</li> <li>July (1)</li> <li>June (3)</li> <li>May (1)</li> <li>April (1)</li> <li>March (1)</li> <li>February (1)</li> <li>January (1)</li> </ul> </li> <li> <h3>2009</h3> <ul> <li>December (1)</li> <li>November (1)</li> <li>October (1)</li> </ul> </li> </ul> Do note: Muenchian Grouping is used -- both for determining the different years and for determining the different months for each year. The date is chosen between the createDate attribute and the archiveUnder child using the expression: concat(archiveUnder, @createDate[not(archiveUnder)]) This concatenation only picks @createDate if archiveUnder is missing or empty. .3. The transformation will produce the correct result even if the dates of the elements are unsorted. UpdateI'm working on a custom Blog in Umbraco. Umbraco spits out XML as the output which is then read using XSLT.The structure of the XML is as followsBlogBlog CentreRoomBlog PostBlog PostBlog PostRoomBlog PostBlog CentreRoomBlog PostHere's the XML code, I've cleaned up a lot of it to make it at least somewhat readable.<Blog id="1078" parentID="1049" level="2" writerID="0" creatorID="0" nodeType="1073" template="1089" sortOrder="7" createDate="2010-09-27T14:11:04" updateDate="2010-10-12T16:59:12" nodeName="Blog" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078" isDoc=""> <newPageTitle>The Lorem Ipsum Blog</newPageTitle> <BlogCentre id="1079" parentID="1078" level="3" writerID="0" creatorID="0" nodeType="1075" template="1076" sortOrder="1" createDate="2010-09-27T14:11:49" updateDate="2010-10-07T14:43:13" nodeName="Blog Centre 1" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079" isDoc=""> <Room id="1081" parentID="1079" level="4" writerID="0" creatorID="0" nodeType="1077" template="0" sortOrder="1" createDate="2010-09-27T14:12:26" updateDate="2010-10-07T14:43:06" nodeName="Room 10" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081" isDoc=""> <BlogPost id="1175" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1192" sortOrder="1" createDate="2010-10-07T14:51:48" updateDate="2010-10-12T21:30:53" nodeName="The first ever Blog post" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1175" isDoc=""> <topicTitle>The first ever blog</topicTitle> </BlogPost> <BlogPost id="1180" parentID="1081" level="5" writerID="0" creatorID="3" nodeType="1087" template="1089" sortOrder="2" createDate="2010-10-08T15:52:20" updateDate="2010-10-12T16:57:00" nodeName="asdasd" writerName="Administrator" creatorName="ZX" path="-1,1049,1078,1079,1081,1180" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> <BlogPost id="1181" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="3" createDate="2010-10-08T17:50:19" updateDate="2010-10-12T11:40:37" nodeName="condimentum" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1181" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-09-01T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1194" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="4" createDate="2010-10-12T11:41:50" updateDate="2010-10-12T11:42:37" nodeName="Nam augue" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1194" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-08-05T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1195" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="5" createDate="2010-10-12T11:42:15" updateDate="2010-10-12T11:42:25" nodeName="consequat nunc" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1195" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-08-12T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1196" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="6" createDate="2010-10-12T12:05:57" updateDate="2010-10-12T12:08:40" nodeName="cursus congue" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1196" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2009-10-22T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1197" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="7" createDate="2010-10-12T12:08:54" updateDate="2010-10-12T12:09:24" nodeName="inceptos" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1197" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2009-11-19T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1198" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="8" createDate="2010-10-12T12:09:45" updateDate="2010-10-12T12:10:13" nodeName="inceptos himenaeos" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1198" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2009-12-16T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1199" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="9" createDate="2010-10-12T12:10:29" updateDate="2010-10-12T12:10:56" nodeName="consequat" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1199" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-01-13T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1200" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="10" createDate="2010-10-12T12:11:08" updateDate="2010-10-12T12:11:35" nodeName="himenaeos" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1200" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-02-09T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1201" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="11" createDate="2010-10-12T12:11:45" updateDate="2010-10-12T12:12:35" nodeName="cursus congue" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1201" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-04-22T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1202" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="12" createDate="2010-10-12T12:12:18" updateDate="2010-10-12T12:12:45" nodeName="pharetra" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1202" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-03-09T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1203" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="13" createDate="2010-10-12T12:13:05" updateDate="2010-10-12T12:13:27" nodeName="inceptos himenaeos" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1203" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-05-26T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1204" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="14" createDate="2010-10-12T12:13:36" updateDate="2010-10-12T12:13:56" nodeName="pharetra" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1204" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-06-11T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1205" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="15" createDate="2010-10-12T12:14:06" updateDate="2010-10-12T12:14:41" nodeName="Fusce augue" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1205" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-07-08T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1206" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="16" createDate="2010-10-12T12:14:52" updateDate="2010-10-12T12:15:19" nodeName="pharetra et fermentum" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1206" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-08-09T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1207" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="17" createDate="2010-10-12T12:15:31" updateDate="2010-10-12T12:15:51" nodeName="Fusce augue purus" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1207" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-09-14T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1208" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="18" createDate="2010-10-12T12:16:25" updateDate="2010-10-12T12:16:45" nodeName="Class aptent taciti" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1208" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-06-04T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1209" parentID="1081" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="19" createDate="2010-10-12T12:17:01" updateDate="2010-10-12T12:17:29" nodeName="Class aptent" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1209" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-06-21T00:00:00</archiveUnder> </BlogPost> </Room> <Room id="1082" parentID="1079" level="4" writerID="0" creatorID="0" nodeType="1077" template="0" sortOrder="2" createDate="2010-09-27T14:12:33" updateDate="2010-10-07T14:43:09" nodeName="Test Blog" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1082" isDoc=""> <BlogPost id="1182" parentID="1082" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="1" createDate="2010-10-08T17:51:19" updateDate="2010-10-08T17:51:58" nodeName="Test Blog" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1082,1182" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> <Room id="1083" parentID="1079" level="4" writerID="0" creatorID="0" nodeType="1077" template="1089" sortOrder="3" createDate="2010-09-27T14:12:40" updateDate="2010-10-07T14:49:48" nodeName="Test Blog" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1083" isDoc=""> <BlogPost id="1183" parentID="1083" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="1" createDate="2010-10-08T17:52:22" updateDate="2010-10-08T17:52:39" nodeName="Test Blog" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1083,1183" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> </BlogCentre> <BlogCentre id="1080" parentID="1078" level="3" writerID="0" creatorID="0" nodeType="1075" template="1076" sortOrder="2" createDate="2010-09-27T14:11:55" updateDate="2010-10-07T14:43:23" nodeName="Blog Centre 2" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080" isDoc=""> <Room id="1084" parentID="1080" level="4" writerID="0" creatorID="0" nodeType="1077" template="0" sortOrder="1" createDate="2010-09-27T14:12:45" updateDate="2010-10-07T14:43:17" nodeName="Room 1" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1084" isDoc=""> <BlogPost id="1184" parentID="1084" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="1" createDate="2010-10-08T17:53:05" updateDate="2010-10-08T17:53:29" nodeName="Blog Post 3" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1084,1184" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> <Room id="1085" parentID="1080" level="4" writerID="0" creatorID="0" nodeType="1077" template="0" sortOrder="2" createDate="2010-09-27T14:12:50" updateDate="2010-10-07T14:43:19" nodeName="Room 2" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1085" isDoc=""> <BlogPost id="1185" parentID="1085" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="1" createDate="2010-10-08T17:53:51" updateDate="2010-10-08T17:54:15" nodeName="Blog Post 109" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1085,1185" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> <Room id="1086" parentID="1080" level="4" writerID="0" creatorID="0" nodeType="1077" template="1089" sortOrder="3" createDate="2010-09-27T14:12:55" updateDate="2010-10-07T14:50:39" nodeName="Room 3" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1086" isDoc=""> <BlogPost id="1186" parentID="1086" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="1" createDate="2010-10-08T17:54:28" updateDate="2010-10-08T17:54:51" nodeName="Blog Post 123" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1086,1186" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> </BlogCentre></Blog>In the Umbraco XSLT stylesheets, there is a parameter that gets passed for the current page.<xsl:param name="currentPage" />This will always be the parent node <Blog />, so we have to start form here.You'll notice that there are intermediate nodes between <Blog /> and <BlogPost /> but we want to count the TOTAL number of BlogPosts in every <BlogCentre /> and <Room />.To do this, I've been using<xsl:for-each select="$currentPage/descendant::BlogPost" />Which selects all the Blog Posts, regardless of Centre/Room.Now the requirement I have is, to group each of these Blog Posts by Month and Year (including a Post count for each month). The date I'd like to group them by is the attribute createDate UNLESS there is a child node called <archiveUnder>some-date-here</archiveUnder>. To explain furtherUpdateI can easily do this part by checking if an attribute is blank, so the solution can omit this part if need-be.<BlogPost createDate="2010-10-08T17:52:22"> <!-- no archiveUnder --></BlogPost>^ Use create Date<BlogPost createDate="2010-10-08T17:52:22"> <archiveUnder>2010-10-08T17:51:19</archiveUnder></BlogPost>^ Use archiveUnder<ul> <li> <h3>2010</h3> <ul> <li>September (4)</li> <li>August (2)</li> <li>June (5)</li> <!-- No July because there are no posts --> </ul> </li> <li> <h3>2009</h3> <ul> <li>April (4)</li> <li>March (2)</li> <li>January (5)</li> <!-- No February because there are no posts --> </ul> </li></ul> 解决方案 This transformation (141 lines but formatted for readability):<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="my:months" exclude-result-prefixes="m" > <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:param name="currentPage" select="/*"/> <m:months> <m>January</m> <m>February</m> <m>March</m> <m>April</m> <m>May</m> <m>June</m> <m>July</m> <m>August</m> <m>September</m> <m>October</m> <m>November</m> <m>December</m> </m:months> <xsl:variable name="vMonthNames" select= "document('')/*/m:months/*"/> <xsl:key name="kPostsByYear" match="BlogPost" use="substring-before( concat(archiveUnder, @createDate[not(archiveUnder)] ), '-' )"/> <xsl:key name="kPostsByYearMonth" match="BlogPost" use="substring( concat(archiveUnder, @createDate[not(archiveUnder)] ), 1,7 )"/> <xsl:template match="/"> <ul> <xsl:apply-templates mode="year" select= "$currentPage/*/*/BlogPost [generate-id() = generate-id(key('kPostsByYear', substring-before( concat(archiveUnder, @createDate[not(archiveUnder)] ), '-' ) )[1] ) ] "> <xsl:sort order="descending" select= "substring-before( concat(archiveUnder, @createDate[not(archiveUnder)] ), '-' ) "/> </xsl:apply-templates> </ul> </xsl:template> <xsl:template match="BlogPost" mode="year"> <xsl:variable name="vYear" select= "substring-before( concat(archiveUnder, @createDate[not(archiveUnder)] ), '-') "/> <xsl:variable name="vyearBlogs" select="key('kPostsByYear',$vYear)"/> <li> <h3><xsl:value-of select="$vYear"/></h3> <ul> <xsl:apply-templates mode="month" select= "$vyearBlogs [generate-id() = generate-id(key('kPostsByYearMonth', substring( concat(archiveUnder, @createDate[not(archiveUnder)] ), 1,7 ) )[1] ) ] "> <xsl:sort order="descending" select= "substring( concat(archiveUnder, @createDate[not(archiveUnder)] ), 6,2)" /> </xsl:apply-templates> </ul> </li> </xsl:template> <xsl:template match="BlogPost" mode="month"> <xsl:variable name="vMonth" select= "substring( concat(archiveUnder, @createDate[not(archiveUnder)] ), 6,2)"/> <xsl:variable name="vmonthsBlogs" select= "key('kPostsByYearMonth', substring( concat(archiveUnder, @createDate[not(archiveUnder)] ), 1,7) )"/> <li><xsl:value-of select= "concat($vMonthNames[position()=$vMonth], ' (', count($vmonthsBlogs), ')' )"/> </li> </xsl:template></xsl:stylesheet>when applied on the provided sample XML document (we are accessing every node off the $currentPage <xsl:param> as this will be in the real Umbraco case), formatted for readability and the createDate attribute of every BlogPost moved on the firs line after the element name:<Blog id="1078" parentID="1049" level="2" writerID="0" creatorID="0" nodeType="1073" template="1089" sortOrder="7" createDate="2010-09-27T14:11:04" updateDate="2010-10-12T16:59:12" nodeName="Blog" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078" isDoc=""> <newPageTitle>The Lorem Ipsum Blog</newPageTitle> <BlogCentre id="1079" parentID="1078" level="3" writerID="0" creatorID="0" nodeType="1075" template="1076" sortOrder="1" createDate="2010-09-27T14:11:49" updateDate="2010-10-07T14:43:13" nodeName="Blog Centre 1" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079" isDoc=""> <Room id="1081" parentID="1079" level="4" writerID="0" creatorID="0" nodeType="1077" template="0" sortOrder="1" createDate="2010-09-27T14:12:26" updateDate="2010-10-07T14:43:06" nodeName="Room 10" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081" isDoc=""> <BlogPost id="1175" parentID="1081" level="5" createDate="2010-10-07T14:51:48" writerID="0" creatorID="0" nodeType="1087" template="1192" sortOrder="1" updateDate="2010-10-12T21:30:53" nodeName="The first ever Blog post" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1175" isDoc=""> <topicTitle>The first ever blog</topicTitle> <archiveUnder/> </BlogPost> <BlogPost id="1180" parentID="1081" createDate="2010-10-08T15:52:20" level="5" writerID="0" creatorID="3" nodeType="1087" template="1089" sortOrder="2" updateDate="2010-10-12T16:57:00" nodeName="asdasd" writerName="Administrator" creatorName="ZX" path="-1,1049,1078,1079,1081,1180" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> <BlogPost id="1181" parentID="1081" level="5" createDate="2010-10-08T17:50:19" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="3" updateDate="2010-10-12T11:40:37" nodeName="condimentum" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1181" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-09-01T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1194" parentID="1081" level="5" createDate="2010-10-12T11:41:50" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="4" updateDate="2010-10-12T11:42:37" nodeName="Nam augue" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1194" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-08-05T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1195" parentID="1081" level="5" createDate="2010-10-12T11:42:15" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="5" updateDate="2010-10-12T11:42:25" nodeName="consequat nunc" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1195" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-08-12T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1196" parentID="1081" level="5" createDate="2010-10-12T12:05:57" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="6" updateDate="2010-10-12T12:08:40" nodeName="cursus congue" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1196" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2009-10-22T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1197" parentID="1081" level="5" createDate="2010-10-12T12:08:54" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="7" updateDate="2010-10-12T12:09:24" nodeName="inceptos" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1197" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2009-11-19T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1198" parentID="1081" level="5" createDate="2010-10-12T12:09:45" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="8" updateDate="2010-10-12T12:10:13" nodeName="inceptos himenaeos" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1198" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2009-12-16T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1199" parentID="1081" level="5" createDate="2010-10-12T12:10:29" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="9" updateDate="2010-10-12T12:10:56" nodeName="consequat" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1199" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-01-13T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1200" parentID="1081" level="5" createDate="2010-10-12T12:11:08" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="10" updateDate="2010-10-12T12:11:35" nodeName="himenaeos" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1200" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-02-09T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1201" parentID="1081" level="5" createDate="2010-10-12T12:11:45" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="11" updateDate="2010-10-12T12:12:35" nodeName="cursus congue" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1201" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-04-22T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1202" parentID="1081" level="5" createDate="2010-10-12T12:12:18" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="12" updateDate="2010-10-12T12:12:45" nodeName="pharetra" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1202" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-03-09T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1203" parentID="1081" level="5" createDate="2010-10-12T12:13:05" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="13" updateDate="2010-10-12T12:13:27" nodeName="inceptos himenaeos" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1203" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-05-26T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1204" parentID="1081" level="5" createDate="2010-10-12T12:13:36" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="14" updateDate="2010-10-12T12:13:56" nodeName="pharetra" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1204" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-06-11T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1205" parentID="1081" level="5" createDate="2010-10-12T12:14:06" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="15" updateDate="2010-10-12T12:14:41" nodeName="Fusce augue" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1205" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-07-08T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1206" parentID="1081" level="5" createDate="2010-10-12T12:14:52" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="16" updateDate="2010-10-12T12:15:19" nodeName="pharetra et fermentum" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1206" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-08-09T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1207" parentID="1081" createDate="2010-10-12T12:15:31" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="17" updateDate="2010-10-12T12:15:51" nodeName="Fusce augue purus" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1207" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-09-14T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1208" parentID="1081" level="5" createDate="2010-10-12T12:16:25" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="18" updateDate="2010-10-12T12:16:45" nodeName="Class aptent taciti" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1208" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-06-04T00:00:00</archiveUnder> </BlogPost> <BlogPost id="1209" parentID="1081" level="5" createDate="2010-10-12T12:17:01" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="19" updateDate="2010-10-12T12:17:29" nodeName="Class aptent" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1081,1209" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> <archiveUnder>2010-06-21T00:00:00</archiveUnder> </BlogPost> </Room> <Room id="1082" parentID="1079" level="4" createDate="2010-09-27T14:12:33" writerID="0" creatorID="0" nodeType="1077" template="0" sortOrder="2" updateDate="2010-10-07T14:43:09" nodeName="Test Blog" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1082" isDoc=""> <BlogPost id="1182" parentID="1082" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="1" createDate="2010-10-08T17:51:19" updateDate="2010-10-08T17:51:58" nodeName="Test Blog" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1082,1182" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> <Room id="1083" parentID="1079" level="4" writerID="0" createDate="2010-09-27T14:12:40" creatorID="0" nodeType="1077" template="1089" sortOrder="3" updateDate="2010-10-07T14:49:48" nodeName="Test Blog" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1083" isDoc=""> <BlogPost id="1183" parentID="1083" level="5" writerID="0" creatorID="0" nodeType="1087" template="1089" sortOrder="1" createDate="2010-10-08T17:52:22" updateDate="2010-10-08T17:52:39" nodeName="Test Blog" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1079,1083,1183" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> </BlogCentre> <BlogCentre id="1080" parentID="1078" level="3" writerID="0" createDate="2010-09-27T14:11:55" creatorID="0" nodeType="1075" template="1076" sortOrder="2" updateDate="2010-10-07T14:43:23" nodeName="Blog Centre 2" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080" isDoc=""> <Room id="1084" parentID="1080" level="4" writerID="0" creatorID="0" nodeType="1077" template="0" sortOrder="1" createDate="2010-09-27T14:12:45" updateDate="2010-10-07T14:43:17" nodeName="Room 1" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1084" isDoc=""> <BlogPost id="1184" parentID="1084" level="5" writerID="0" createDate="2010-10-08T17:53:05" creatorID="0" nodeType="1087" template="1089" sortOrder="1" updateDate="2010-10-08T17:53:29" nodeName="Blog Post 3" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1084,1184" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> <Room id="1085" parentID="1080" level="4" writerID="0" createDate="2010-09-27T14:12:50" creatorID="0" nodeType="1077" template="0" sortOrder="2" updateDate="2010-10-07T14:43:19" nodeName="Room 2" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1085" isDoc=""> <BlogPost id="1185" parentID="1085" level="5" writerID="0" createDate="2010-10-08T17:53:51" creatorID="0" nodeType="1087" template="1089" sortOrder="1" updateDate="2010-10-08T17:54:15" nodeName="Blog Post 109" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1085,1185" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> <Room id="1086" parentID="1080" level="4" writerID="0" creatorID="0" nodeType="1077" template="1089" sortOrder="3" createDate="2010-09-27T14:12:55" updateDate="2010-10-07T14:50:39" nodeName="Room 3" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1086" isDoc=""> <BlogPost id="1186" parentID="1086" level="5" writerID="0" createDate="2010-10-08T17:54:28" creatorID="0" nodeType="1087" template="1089" sortOrder="1" updateDate="2010-10-08T17:54:51" nodeName="Blog Post 123" writerName="Administrator" creatorName="Administrator" path="-1,1049,1078,1080,1086,1186" isDoc=""> <topicTitle>Lorem Ipsum</topicTitle> </BlogPost> </Room> </BlogCentre></Blog>produces the wanted, correct result:<ul> <li> <h3>2010</h3> <ul> <li>October (7)</li> <li>September (2)</li> <li>August (3)</li> <li>July (1)</li> <li>June (3)</li> <li>May (1)</li> <li>April (1)</li> <li>March (1)</li> <li>February (1)</li> <li>January (1)</li> </ul> </li> <li> <h3>2009</h3> <ul> <li>December (1)</li> <li>November (1)</li> <li>October (1)</li> </ul> </li></ul>Do note:Muenchian Grouping is used -- both for determining the different years and for determining the different months for each year.The date is chosen between the createDate attribute and the archiveUnder child using the expression:concat(archiveUnder, @createDate[not(archiveUnder)])This concatenation only picks @createDate if archiveUnder is missing or empty..3. The transformation will produce the correct result even if the dates of the elements are unsorted. 这篇关于在XSLT中按月和年份分组XML节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 01:04