• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

Getting unique list from xml and do sorting

Hi,

I am working on ASP.net 2.0 using C#.
From my xml, I need unique CategoryName list and in sorted manner

I mean, From my below xml
<?xml version="1.0"?>
<ImagesLibrary>
  <Image CategoryName="IGQ" tcmID="tcm:229-655184">
    <TopCaption>Lorem ipsum dolor sit amet 1</TopCaption>
  </Image>
  <Image CategoryName="DEF" tcmID="tcm:229-655184">
    <TopCaption>Lorem ipsum dolor sit amet 2</TopCaption>
  </Image>
  <Image CategoryName="ABC" tcmID="tcm:229-655184">
    <TopCaption>Lorem ipsum dolor sit amet 2</TopCaption>
  </Image>
  <Image CategoryName="DEF" tcmID="tcm:229-655184">
    <TopCaption>Lorem ipsum dolor sit amet 2</TopCaption>
  </Image>
  <Image CategoryName="DEF" tcmID="tcm:229-655184">
    <TopCaption>Lorem ipsum dolor sit amet 2</TopCaption>
  </Image>
  <Image CategoryName="ABC" tcmID="tcm:229-655184">
    <TopCaption>Lorem ipsum dolor sit amet 2</TopCaption>
  </Image>
</ImagesLibrary>

Open in new window


I need the output
ABC
DEF
IGQ

Please help me with xslt

Many Thanks
0
tia_kamakshi
Asked:
tia_kamakshi
  • 2
  • 2
1 Solution
 
Geert BormansCommented:
Use Muenchian grouping (google for that to have it explained)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
    
    <xsl:key name="im" match="Image" use="@CategoryName"/>
    
    <xsl:template match="ImagesLibrary">
        <ul>
            <xsl:for-each select="Image[generate-id() = generate-id(key('im', @CategoryName )[1])]">
                <xsl:sort select="@CategoryName"/>
                <li><xsl:value-of select="@CategoryName"/></li>
            </xsl:for-each>
        </ul>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
 
tia_kamakshiAuthor Commented:
Many Thanks Gertone.

I will go through to understand 'Muenchian grouping '

Thanks again
0
 
Geert BormansCommented:
welcome

check out: http://www.jenitennison.com/xslt/grouping/muenchian.html
it is a good article that explains muenchian
0
 
tia_kamakshiAuthor Commented:
Thanks Gertone
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now