使用 XSLT 1.0 进行分组

发布于 2024-09-13 17:02:20 字数 5933 浏览 3 评论 0原文

我的 XML 看起来像

 <xml version="1.0" standalone="no"> 
 <Alerts AlertsName="">
 <Alert UserId="13" OwnerId="13" OwnerName="jasprice" OwnerEmail="[email protected]" Scope="I">
 <Assets>
 <Asset>
 <AssetTaxonamy>
 <AssetTopics>
  <AssetTopic Type="Global business">Globalisation</AssetTopic> 
  </AssetTopics>
  </AssetTaxonamy>
  <AssetTitle>Doing it the Chinese way: Disney's strategy for a lucrative ride in China</AssetTitle> 
  <AssetDescription>FROM INSEAD KNOWLEDGE As trite as the phrase ?think global, act local? may be, it nevertheless encapsulates The Walt Disney Company?s approach to making a success of its business in China. To that end, producing content that has a cultural and emotional resonance with Chinese consumers is crucial, says Stanley Cheung, Disney?s managing director for Greater China. ?We see it in China today, that ...</AssetDescription> 
  <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&amp;article_id=467282231</AssetLink> 
  <AssetPubDate>7/23/2010</AssetPubDate> 
  <AssetArrivalDate>8/9/2010</AssetArrivalDate> 
  <AssetSource>Executive briefings / whitepapers</AssetSource> 
  </Asset>
 <Asset>
 <AssetTaxonamy>
 <AssetTopics>
  <AssetTopic Type="Sales and marketing">Marketing effectiveness</AssetTopic> 
  </AssetTopics>
  </AssetTaxonamy>
  <AssetTitle>The empowered sales team: Enhancing productivity through thebetter use of information</AssetTitle> 
  <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Sales professionals create value by transforming their company?s raw product or service into a tailored solution for a customer?s needs. In a setting where customers have access to an unprecedented amount of product information, this is an increasingly challenging task. To thrive in this environment, companies...</AssetDescription> 
  <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&amp;article_id=1297294514</AssetLink> 
  <AssetPubDate>7/23/2010</AssetPubDate> 
  <AssetArrivalDate>8/9/2010</AssetArrivalDate> 
  <AssetSource>Executive briefings / whitepapers</AssetSource> 
  </Asset>
 <Asset>
 <AssetTaxonamy>
 <AssetTopics>
  <AssetTopic Type="Sales and marketing">Customer management</AssetTopic> 
  </AssetTopics>
  </AssetTaxonamy>
  <AssetTitle>On the front lines: The role of information in enhancing customer service</AssetTitle> 
  <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Customer service professionals play a critical role in most companies because they are the people customers are most often in contact with, especially when problems arise. In today?s unsettled market environment, the ability to build a deep understanding of evolving customer needs and expectations can make a com...</AssetDescription> 
  <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&amp;article_id=1327294517</AssetLink> 
  <AssetPubDate>7/23/2010</AssetPubDate> 
  <AssetArrivalDate>8/9/2010</AssetArrivalDate> 
  <AssetSource>Executive briefings / whitepapers</AssetSource> 
  </Asset>
 <Asset>
 <AssetTaxonamy>
 <AssetTopics>
  <AssetTopic Type="Leadership">Managing change</AssetTopic> 
  </AssetTopics>
  </AssetTaxonamy>
  <AssetTitle>World of leaders</AssetTitle> 
  <AssetDescription>FROM INDIAN SCHOOL OF BUSINESS At the inaugural ?ISB World of Leaders? speaker series event hosted by the Indian School of Business (ISB), Henry R Kravis, Co-Founder, Co-Chairman and Co-CEO, Kohlberg Kravis Roberts &amp; Company (KKR), New York, interacted with a select group of Indian business leaders about how he started his enterprise, the journey so far and his views on the private equity industr...</AssetDescription> 
  <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&amp;article_id=1757259560</AssetLink> 
  <AssetPubDate>7/23/2010</AssetPubDate> 
  <AssetArrivalDate>8/9/2010</AssetArrivalDate> 
  <AssetSource>Executive briefings / whitepapers</AssetSource> 
  </Asset>
 <Asset>
 <AssetTaxonamy>
 <AssetTopics>
  <AssetTopic Type="Global business">Country strategies</AssetTopic> 
  </AssetTopics>
  </AssetTaxonamy>
  <AssetTitle>State industries in Lithuania: Follow the money</AssetTitle> 
  <AssetDescription>State-owned enterprises in eastern Europe are often a mess. Lithuania is trying to reform them DIG into the political undergrowth anywhere between the Baltic and the Black Seas and you soon find curious connections between state-owned enterprises, officials and politicians. They mostly escape public scrutiny--not least because politicians of all stripes tend to benefit from the state firms? large...</AssetDescription> 
  <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&amp;article_id=67277991</AssetLink> 
  <AssetPubDate>7/23/2010</AssetPubDate> 
  <AssetArrivalDate>8/9/2010</AssetArrivalDate> 
  <AssetSource>Executive briefings / whitepapers</AssetSource> 
  </Asset>
</Assets>
</Alert>
</Alerts>

现在我们需要首先按类型属性(例如全球化)对资产进行分组,然后需要按值(例如国家/地区策略)进行分组。我们只需显示一次全球化和国家战略,并需要显示其下方的所有资产。我可以使用 XSLT 2.0 轻松完成此操作,但 Microsoft .net 不支持它,因此无法使用。

有人可以帮我吗?

提前致谢。

My XML looks like

 <xml version="1.0" standalone="no"> 
 <Alerts AlertsName="">
 <Alert UserId="13" OwnerId="13" OwnerName="jasprice" OwnerEmail="[email protected]" Scope="I">
 <Assets>
 <Asset>
 <AssetTaxonamy>
 <AssetTopics>
  <AssetTopic Type="Global business">Globalisation</AssetTopic> 
  </AssetTopics>
  </AssetTaxonamy>
  <AssetTitle>Doing it the Chinese way: Disney's strategy for a lucrative ride in China</AssetTitle> 
  <AssetDescription>FROM INSEAD KNOWLEDGE As trite as the phrase ?think global, act local? may be, it nevertheless encapsulates The Walt Disney Company?s approach to making a success of its business in China. To that end, producing content that has a cultural and emotional resonance with Chinese consumers is crucial, says Stanley Cheung, Disney?s managing director for Greater China. ?We see it in China today, that ...</AssetDescription> 
  <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=467282231</AssetLink> 
  <AssetPubDate>7/23/2010</AssetPubDate> 
  <AssetArrivalDate>8/9/2010</AssetArrivalDate> 
  <AssetSource>Executive briefings / whitepapers</AssetSource> 
  </Asset>
 <Asset>
 <AssetTaxonamy>
 <AssetTopics>
  <AssetTopic Type="Sales and marketing">Marketing effectiveness</AssetTopic> 
  </AssetTopics>
  </AssetTaxonamy>
  <AssetTitle>The empowered sales team: Enhancing productivity through thebetter use of information</AssetTitle> 
  <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Sales professionals create value by transforming their company?s raw product or service into a tailored solution for a customer?s needs. In a setting where customers have access to an unprecedented amount of product information, this is an increasingly challenging task. To thrive in this environment, companies...</AssetDescription> 
  <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1297294514</AssetLink> 
  <AssetPubDate>7/23/2010</AssetPubDate> 
  <AssetArrivalDate>8/9/2010</AssetArrivalDate> 
  <AssetSource>Executive briefings / whitepapers</AssetSource> 
  </Asset>
 <Asset>
 <AssetTaxonamy>
 <AssetTopics>
  <AssetTopic Type="Sales and marketing">Customer management</AssetTopic> 
  </AssetTopics>
  </AssetTaxonamy>
  <AssetTitle>On the front lines: The role of information in enhancing customer service</AssetTitle> 
  <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Customer service professionals play a critical role in most companies because they are the people customers are most often in contact with, especially when problems arise. In today?s unsettled market environment, the ability to build a deep understanding of evolving customer needs and expectations can make a com...</AssetDescription> 
  <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1327294517</AssetLink> 
  <AssetPubDate>7/23/2010</AssetPubDate> 
  <AssetArrivalDate>8/9/2010</AssetArrivalDate> 
  <AssetSource>Executive briefings / whitepapers</AssetSource> 
  </Asset>
 <Asset>
 <AssetTaxonamy>
 <AssetTopics>
  <AssetTopic Type="Leadership">Managing change</AssetTopic> 
  </AssetTopics>
  </AssetTaxonamy>
  <AssetTitle>World of leaders</AssetTitle> 
  <AssetDescription>FROM INDIAN SCHOOL OF BUSINESS At the inaugural ?ISB World of Leaders? speaker series event hosted by the Indian School of Business (ISB), Henry R Kravis, Co-Founder, Co-Chairman and Co-CEO, Kohlberg Kravis Roberts & Company (KKR), New York, interacted with a select group of Indian business leaders about how he started his enterprise, the journey so far and his views on the private equity industr...</AssetDescription> 
  <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1757259560</AssetLink> 
  <AssetPubDate>7/23/2010</AssetPubDate> 
  <AssetArrivalDate>8/9/2010</AssetArrivalDate> 
  <AssetSource>Executive briefings / whitepapers</AssetSource> 
  </Asset>
 <Asset>
 <AssetTaxonamy>
 <AssetTopics>
  <AssetTopic Type="Global business">Country strategies</AssetTopic> 
  </AssetTopics>
  </AssetTaxonamy>
  <AssetTitle>State industries in Lithuania: Follow the money</AssetTitle> 
  <AssetDescription>State-owned enterprises in eastern Europe are often a mess. Lithuania is trying to reform them DIG into the political undergrowth anywhere between the Baltic and the Black Seas and you soon find curious connections between state-owned enterprises, officials and politicians. They mostly escape public scrutiny--not least because politicians of all stripes tend to benefit from the state firms? large...</AssetDescription> 
  <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=67277991</AssetLink> 
  <AssetPubDate>7/23/2010</AssetPubDate> 
  <AssetArrivalDate>8/9/2010</AssetArrivalDate> 
  <AssetSource>Executive briefings / whitepapers</AssetSource> 
  </Asset>
</Assets>
</Alert>
</Alerts>

Now we need to group assets by first Type attribute (ex globalisation) and then need to group by value (ex Country stratagies). We need to display Globalisation and Country stratagies once only and need to display all assets below that. I can do it with XSLT 2.0 easily with but it is not supported with Microsoft .net so can't use.

Can anyone help me here?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

审判长 2024-09-20 17:02:20

此转换

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:key name="kAssetByTypeName" match="Asset"
  use="AssetTaxonamy/AssetTopics/AssetTopic[1]/@Type"/>

 <xsl:key name="kAssetByTypeNameValue" match="Asset"
  use="concat(AssetTaxonamy/AssetTopics/AssetTopic[1]/@Type,
              AssetTaxonamy/AssetTopics/AssetTopic[1]
              )
  "/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>

 <xsl:template match="Assets">
   <Assets>
     <xsl:for-each select=
     "Asset[generate-id()
           =
            generate-id(key('kAssetByTypeName',
                            AssetTaxonamy/AssetTopics
                                       /AssetTopic[1]/@Type
                            )
                            [1]
                        )
           ]
     ">
      <xsl:variable name="vcurType" select=
       "AssetTaxonamy/AssetTopics/AssetTopic[1]/@Type"/>

       <Topic Type="{$vcurType}">
          <xsl:for-each select=
           "key('kAssetByTypeName',$vcurType)
                [generate-id()
                =
                 generate-id(key('kAssetByTypeNameValue',
                                  concat($vcurType,
                                         AssetTaxonamy/AssetTopics/AssetTopic[1]
                                         )
                                 )[1]
                             )
                ]
           ">
             <xsl:variable name="vSubject" select=
              "AssetTaxonamy/AssetTopics/AssetTopic[1]"/>

             <Subject>
               <xsl:value-of select="$vSubject"/>
             </Subject>

             <xsl:apply-templates select=
              "key('kAssetByTypeNameValue',
                    concat($vcurType, $vSubject)
                   )
              "/>
          </xsl:for-each>
       </Topic>
     </xsl:for-each>
   </Assets>
 </xsl:template>
</xsl:stylesheet>

应用于提供的(已更正为格式良好的)XML 文档时

<Alerts AlertsName="">
    <Alert UserId="13" OwnerId="13" OwnerName="jasprice" OwnerEmail="[email protected]" Scope="I">
        <Assets>
            <Asset>
                <AssetTaxonamy>
                    <AssetTopics>
                        <AssetTopic Type="Global business">Globalisation</AssetTopic>
                    </AssetTopics>
                </AssetTaxonamy>
                <AssetTitle>Doing it the Chinese way: Disney's strategy for a lucrative ride in China</AssetTitle>
                <AssetDescription>FROM INSEAD KNOWLEDGE As trite as the phrase ?think global, act local? may be, it nevertheless encapsulates The Walt Disney Company?s approach to making a success of its business in China. To that end, producing content that has a cultural and emotional resonance with Chinese consumers is crucial, says Stanley Cheung, Disney?s managing director for Greater China. ?We see it in China today, that ...</AssetDescription>
                <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=467282231</AssetLink>
                <AssetPubDate>7/23/2010</AssetPubDate>
                <AssetArrivalDate>8/9/2010</AssetArrivalDate>
                <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Asset>
                <AssetTaxonamy>
                    <AssetTopics>
                        <AssetTopic Type="Sales and marketing">Marketing effectiveness</AssetTopic>
                    </AssetTopics>
                </AssetTaxonamy>
                <AssetTitle>The empowered sales team: Enhancing productivity through thebetter use of information</AssetTitle>
                <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Sales professionals create value by transforming their company?s raw product or service into a tailored solution for a customer?s needs. In a setting where customers have access to an unprecedented amount of product information, this is an increasingly challenging task. To thrive in this environment, companies...</AssetDescription>
                <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1297294514</AssetLink>
                <AssetPubDate>7/23/2010</AssetPubDate>
                <AssetArrivalDate>8/9/2010</AssetArrivalDate>
                <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Asset>
                <AssetTaxonamy>
                    <AssetTopics>
                        <AssetTopic Type="Sales and marketing">Customer management</AssetTopic>
                    </AssetTopics>
                </AssetTaxonamy>
                <AssetTitle>On the front lines: The role of information in enhancing customer service</AssetTitle>
                <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Customer service professionals play a critical role in most companies because they are the people customers are most often in contact with, especially when problems arise. In today?s unsettled market environment, the ability to build a deep understanding of evolving customer needs and expectations can make a com...</AssetDescription>
                <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1327294517</AssetLink>
                <AssetPubDate>7/23/2010</AssetPubDate>
                <AssetArrivalDate>8/9/2010</AssetArrivalDate>
                <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Asset>
                <AssetTaxonamy>
                    <AssetTopics>
                        <AssetTopic Type="Leadership">Managing change</AssetTopic>
                    </AssetTopics>
                </AssetTaxonamy>
                <AssetTitle>World of leaders</AssetTitle>
                <AssetDescription>FROM INDIAN SCHOOL OF BUSINESS At the inaugural ?ISB World of Leaders? speaker series event hosted by the Indian School of Business (ISB), Henry R Kravis, Co-Founder, Co-Chairman and Co-CEO, Kohlberg Kravis Roberts & Company (KKR), New York, interacted with a select group of Indian business leaders about how he started his enterprise, the journey so far and his views on the private equity industr...</AssetDescription>
                <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1757259560</AssetLink>
                <AssetPubDate>7/23/2010</AssetPubDate>
                <AssetArrivalDate>8/9/2010</AssetArrivalDate>
                <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Asset>
                <AssetTaxonamy>
                    <AssetTopics>
                        <AssetTopic Type="Global business">Country strategies</AssetTopic>
                    </AssetTopics>
                </AssetTaxonamy>
                <AssetTitle>State industries in Lithuania: Follow the money</AssetTitle>
                <AssetDescription>State-owned enterprises in eastern Europe are often a mess. Lithuania is trying to reform them DIG into the political undergrowth anywhere between the Baltic and the Black Seas and you soon find curious connections between state-owned enterprises, officials and politicians. They mostly escape public scrutiny--not least because politicians of all stripes tend to benefit from the state firms? large...</AssetDescription>
                <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=67277991</AssetLink>
                <AssetPubDate>7/23/2010</AssetPubDate>
                <AssetArrivalDate>8/9/2010</AssetArrivalDate>
                <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
        </Assets>
    </Alert>
</Alerts>

生成所需的分组

<Alerts AlertsName="">
   <Alert UserId="13" OwnerId="13" OwnerName="jasprice" OwnerEmail="[email protected]" Scope="I">
      <Assets>
         <Topic Type="Global business">
            <Subject>Globalisation</Subject>
            <Asset>
               <AssetTaxonamy>
                  <AssetTopics>
                     <AssetTopic Type="Global business">Globalisation</AssetTopic>
                  </AssetTopics>
               </AssetTaxonamy>
               <AssetTitle>Doing it the Chinese way: Disney's strategy for a lucrative ride in China</AssetTitle>
               <AssetDescription>FROM INSEAD KNOWLEDGE As trite as the phrase ?think global, act local? may be, it nevertheless encapsulates The Walt Disney Company?s approach to making a success of its business in China. To that end, producing content that has a cultural and emotional resonance with Chinese consumers is crucial, says Stanley Cheung, Disney?s managing director for Greater China. ?We see it in China today, that ...</AssetDescription>
               <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=467282231</AssetLink>
               <AssetPubDate>7/23/2010</AssetPubDate>
               <AssetArrivalDate>8/9/2010</AssetArrivalDate>
               <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Subject>Country strategies</Subject>
            <Asset>
               <AssetTaxonamy>
                  <AssetTopics>
                     <AssetTopic Type="Global business">Country strategies</AssetTopic>
                  </AssetTopics>
               </AssetTaxonamy>
               <AssetTitle>State industries in Lithuania: Follow the money</AssetTitle>
               <AssetDescription>State-owned enterprises in eastern Europe are often a mess. Lithuania is trying to reform them DIG into the political undergrowth anywhere between the Baltic and the Black Seas and you soon find curious connections between state-owned enterprises, officials and politicians. They mostly escape public scrutiny--not least because politicians of all stripes tend to benefit from the state firms? large...</AssetDescription>
               <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=67277991</AssetLink>
               <AssetPubDate>7/23/2010</AssetPubDate>
               <AssetArrivalDate>8/9/2010</AssetArrivalDate>
               <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
         </Topic>
         <Topic Type="Sales and marketing">
            <Subject>Marketing effectiveness</Subject>
            <Asset>
               <AssetTaxonamy>
                  <AssetTopics>
                     <AssetTopic Type="Sales and marketing">Marketing effectiveness</AssetTopic>
                  </AssetTopics>
               </AssetTaxonamy>
               <AssetTitle>The empowered sales team: Enhancing productivity through thebetter use of information</AssetTitle>
               <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Sales professionals create value by transforming their company?s raw product or service into a tailored solution for a customer?s needs. In a setting where customers have access to an unprecedented amount of product information, this is an increasingly challenging task. To thrive in this environment, companies...</AssetDescription>
               <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1297294514</AssetLink>
               <AssetPubDate>7/23/2010</AssetPubDate>
               <AssetArrivalDate>8/9/2010</AssetArrivalDate>
               <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Subject>Customer management</Subject>
            <Asset>
               <AssetTaxonamy>
                  <AssetTopics>
                     <AssetTopic Type="Sales and marketing">Customer management</AssetTopic>
                  </AssetTopics>
               </AssetTaxonamy>
               <AssetTitle>On the front lines: The role of information in enhancing customer service</AssetTitle>
               <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Customer service professionals play a critical role in most companies because they are the people customers are most often in contact with, especially when problems arise. In today?s unsettled market environment, the ability to build a deep understanding of evolving customer needs and expectations can make a com...</AssetDescription>
               <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1327294517</AssetLink>
               <AssetPubDate>7/23/2010</AssetPubDate>
               <AssetArrivalDate>8/9/2010</AssetArrivalDate>
               <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
         </Topic>
         <Topic Type="Leadership">
            <Subject>Managing change</Subject>
            <Asset>
               <AssetTaxonamy>
                  <AssetTopics>
                     <AssetTopic Type="Leadership">Managing change</AssetTopic>
                  </AssetTopics>
               </AssetTaxonamy>
               <AssetTitle>World of leaders</AssetTitle>
               <AssetDescription>FROM INDIAN SCHOOL OF BUSINESS At the inaugural ?ISB World of Leaders? speaker series event hosted by the Indian School of Business (ISB), Henry R Kravis, Co-Founder, Co-Chairman and Co-CEO, Kohlberg Kravis Roberts & Company (KKR), New York, interacted with a select group of Indian business leaders about how he started his enterprise, the journey so far and his views on the private equity industr...</AssetDescription>
               <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1757259560</AssetLink>
               <AssetPubDate>7/23/2010</AssetPubDate>
               <AssetArrivalDate>8/9/2010</AssetArrivalDate>
               <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
         </Topic>
      </Assets>
   </Alert>
</Alerts>

请注意:使用 Muenchian 方法进行分组。

This transformation:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:key name="kAssetByTypeName" match="Asset"
  use="AssetTaxonamy/AssetTopics/AssetTopic[1]/@Type"/>

 <xsl:key name="kAssetByTypeNameValue" match="Asset"
  use="concat(AssetTaxonamy/AssetTopics/AssetTopic[1]/@Type,
              AssetTaxonamy/AssetTopics/AssetTopic[1]
              )
  "/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>

 <xsl:template match="Assets">
   <Assets>
     <xsl:for-each select=
     "Asset[generate-id()
           =
            generate-id(key('kAssetByTypeName',
                            AssetTaxonamy/AssetTopics
                                       /AssetTopic[1]/@Type
                            )
                            [1]
                        )
           ]
     ">
      <xsl:variable name="vcurType" select=
       "AssetTaxonamy/AssetTopics/AssetTopic[1]/@Type"/>

       <Topic Type="{$vcurType}">
          <xsl:for-each select=
           "key('kAssetByTypeName',$vcurType)
                [generate-id()
                =
                 generate-id(key('kAssetByTypeNameValue',
                                  concat($vcurType,
                                         AssetTaxonamy/AssetTopics/AssetTopic[1]
                                         )
                                 )[1]
                             )
                ]
           ">
             <xsl:variable name="vSubject" select=
              "AssetTaxonamy/AssetTopics/AssetTopic[1]"/>

             <Subject>
               <xsl:value-of select="$vSubject"/>
             </Subject>

             <xsl:apply-templates select=
              "key('kAssetByTypeNameValue',
                    concat($vcurType, $vSubject)
                   )
              "/>
          </xsl:for-each>
       </Topic>
     </xsl:for-each>
   </Assets>
 </xsl:template>
</xsl:stylesheet>

when applied on the provided (corrected to be well-formed) XML document:

<Alerts AlertsName="">
    <Alert UserId="13" OwnerId="13" OwnerName="jasprice" OwnerEmail="[email protected]" Scope="I">
        <Assets>
            <Asset>
                <AssetTaxonamy>
                    <AssetTopics>
                        <AssetTopic Type="Global business">Globalisation</AssetTopic>
                    </AssetTopics>
                </AssetTaxonamy>
                <AssetTitle>Doing it the Chinese way: Disney's strategy for a lucrative ride in China</AssetTitle>
                <AssetDescription>FROM INSEAD KNOWLEDGE As trite as the phrase ?think global, act local? may be, it nevertheless encapsulates The Walt Disney Company?s approach to making a success of its business in China. To that end, producing content that has a cultural and emotional resonance with Chinese consumers is crucial, says Stanley Cheung, Disney?s managing director for Greater China. ?We see it in China today, that ...</AssetDescription>
                <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=467282231</AssetLink>
                <AssetPubDate>7/23/2010</AssetPubDate>
                <AssetArrivalDate>8/9/2010</AssetArrivalDate>
                <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Asset>
                <AssetTaxonamy>
                    <AssetTopics>
                        <AssetTopic Type="Sales and marketing">Marketing effectiveness</AssetTopic>
                    </AssetTopics>
                </AssetTaxonamy>
                <AssetTitle>The empowered sales team: Enhancing productivity through thebetter use of information</AssetTitle>
                <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Sales professionals create value by transforming their company?s raw product or service into a tailored solution for a customer?s needs. In a setting where customers have access to an unprecedented amount of product information, this is an increasingly challenging task. To thrive in this environment, companies...</AssetDescription>
                <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1297294514</AssetLink>
                <AssetPubDate>7/23/2010</AssetPubDate>
                <AssetArrivalDate>8/9/2010</AssetArrivalDate>
                <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Asset>
                <AssetTaxonamy>
                    <AssetTopics>
                        <AssetTopic Type="Sales and marketing">Customer management</AssetTopic>
                    </AssetTopics>
                </AssetTaxonamy>
                <AssetTitle>On the front lines: The role of information in enhancing customer service</AssetTitle>
                <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Customer service professionals play a critical role in most companies because they are the people customers are most often in contact with, especially when problems arise. In today?s unsettled market environment, the ability to build a deep understanding of evolving customer needs and expectations can make a com...</AssetDescription>
                <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1327294517</AssetLink>
                <AssetPubDate>7/23/2010</AssetPubDate>
                <AssetArrivalDate>8/9/2010</AssetArrivalDate>
                <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Asset>
                <AssetTaxonamy>
                    <AssetTopics>
                        <AssetTopic Type="Leadership">Managing change</AssetTopic>
                    </AssetTopics>
                </AssetTaxonamy>
                <AssetTitle>World of leaders</AssetTitle>
                <AssetDescription>FROM INDIAN SCHOOL OF BUSINESS At the inaugural ?ISB World of Leaders? speaker series event hosted by the Indian School of Business (ISB), Henry R Kravis, Co-Founder, Co-Chairman and Co-CEO, Kohlberg Kravis Roberts & Company (KKR), New York, interacted with a select group of Indian business leaders about how he started his enterprise, the journey so far and his views on the private equity industr...</AssetDescription>
                <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1757259560</AssetLink>
                <AssetPubDate>7/23/2010</AssetPubDate>
                <AssetArrivalDate>8/9/2010</AssetArrivalDate>
                <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Asset>
                <AssetTaxonamy>
                    <AssetTopics>
                        <AssetTopic Type="Global business">Country strategies</AssetTopic>
                    </AssetTopics>
                </AssetTaxonamy>
                <AssetTitle>State industries in Lithuania: Follow the money</AssetTitle>
                <AssetDescription>State-owned enterprises in eastern Europe are often a mess. Lithuania is trying to reform them DIG into the political undergrowth anywhere between the Baltic and the Black Seas and you soon find curious connections between state-owned enterprises, officials and politicians. They mostly escape public scrutiny--not least because politicians of all stripes tend to benefit from the state firms? large...</AssetDescription>
                <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=67277991</AssetLink>
                <AssetPubDate>7/23/2010</AssetPubDate>
                <AssetArrivalDate>8/9/2010</AssetArrivalDate>
                <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
        </Assets>
    </Alert>
</Alerts>

produces the wanted grouping:

<Alerts AlertsName="">
   <Alert UserId="13" OwnerId="13" OwnerName="jasprice" OwnerEmail="[email protected]" Scope="I">
      <Assets>
         <Topic Type="Global business">
            <Subject>Globalisation</Subject>
            <Asset>
               <AssetTaxonamy>
                  <AssetTopics>
                     <AssetTopic Type="Global business">Globalisation</AssetTopic>
                  </AssetTopics>
               </AssetTaxonamy>
               <AssetTitle>Doing it the Chinese way: Disney's strategy for a lucrative ride in China</AssetTitle>
               <AssetDescription>FROM INSEAD KNOWLEDGE As trite as the phrase ?think global, act local? may be, it nevertheless encapsulates The Walt Disney Company?s approach to making a success of its business in China. To that end, producing content that has a cultural and emotional resonance with Chinese consumers is crucial, says Stanley Cheung, Disney?s managing director for Greater China. ?We see it in China today, that ...</AssetDescription>
               <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=467282231</AssetLink>
               <AssetPubDate>7/23/2010</AssetPubDate>
               <AssetArrivalDate>8/9/2010</AssetArrivalDate>
               <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Subject>Country strategies</Subject>
            <Asset>
               <AssetTaxonamy>
                  <AssetTopics>
                     <AssetTopic Type="Global business">Country strategies</AssetTopic>
                  </AssetTopics>
               </AssetTaxonamy>
               <AssetTitle>State industries in Lithuania: Follow the money</AssetTitle>
               <AssetDescription>State-owned enterprises in eastern Europe are often a mess. Lithuania is trying to reform them DIG into the political undergrowth anywhere between the Baltic and the Black Seas and you soon find curious connections between state-owned enterprises, officials and politicians. They mostly escape public scrutiny--not least because politicians of all stripes tend to benefit from the state firms? large...</AssetDescription>
               <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=67277991</AssetLink>
               <AssetPubDate>7/23/2010</AssetPubDate>
               <AssetArrivalDate>8/9/2010</AssetArrivalDate>
               <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
         </Topic>
         <Topic Type="Sales and marketing">
            <Subject>Marketing effectiveness</Subject>
            <Asset>
               <AssetTaxonamy>
                  <AssetTopics>
                     <AssetTopic Type="Sales and marketing">Marketing effectiveness</AssetTopic>
                  </AssetTopics>
               </AssetTaxonamy>
               <AssetTitle>The empowered sales team: Enhancing productivity through thebetter use of information</AssetTitle>
               <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Sales professionals create value by transforming their company?s raw product or service into a tailored solution for a customer?s needs. In a setting where customers have access to an unprecedented amount of product information, this is an increasingly challenging task. To thrive in this environment, companies...</AssetDescription>
               <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1297294514</AssetLink>
               <AssetPubDate>7/23/2010</AssetPubDate>
               <AssetArrivalDate>8/9/2010</AssetArrivalDate>
               <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
            <Subject>Customer management</Subject>
            <Asset>
               <AssetTaxonamy>
                  <AssetTopics>
                     <AssetTopic Type="Sales and marketing">Customer management</AssetTopic>
                  </AssetTopics>
               </AssetTaxonamy>
               <AssetTitle>On the front lines: The role of information in enhancing customer service</AssetTitle>
               <AssetDescription>FROM THE ECONOMIST INTELLIGENCE UNIT Sponsored by Microsoft Introduction Customer service professionals play a critical role in most companies because they are the people customers are most often in contact with, especially when problems arise. In today?s unsettled market environment, the ability to build a deep understanding of evolving customer needs and expectations can make a com...</AssetDescription>
               <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1327294517</AssetLink>
               <AssetPubDate>7/23/2010</AssetPubDate>
               <AssetArrivalDate>8/9/2010</AssetArrivalDate>
               <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
         </Topic>
         <Topic Type="Leadership">
            <Subject>Managing change</Subject>
            <Asset>
               <AssetTaxonamy>
                  <AssetTopics>
                     <AssetTopic Type="Leadership">Managing change</AssetTopic>
                  </AssetTopics>
               </AssetTaxonamy>
               <AssetTitle>World of leaders</AssetTitle>
               <AssetDescription>FROM INDIAN SCHOOL OF BUSINESS At the inaugural ?ISB World of Leaders? speaker series event hosted by the Indian School of Business (ISB), Henry R Kravis, Co-Founder, Co-Chairman and Co-CEO, Kohlberg Kravis Roberts & Company (KKR), New York, interacted with a select group of Indian business leaders about how he started his enterprise, the journey so far and his views on the private equity industr...</AssetDescription>
               <AssetLink>http://viewswire.eiu.com/index.asp?layout=EBArticleVW3&article_id=1757259560</AssetLink>
               <AssetPubDate>7/23/2010</AssetPubDate>
               <AssetArrivalDate>8/9/2010</AssetArrivalDate>
               <AssetSource>Executive briefings / whitepapers</AssetSource>
            </Asset>
         </Topic>
      </Assets>
   </Alert>
</Alerts>

Do note: The use of the Muenchian method for grouping.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文