I have the following XML file:
<Promotions>
<Promotion>
<Category>Arts & Entertainment</Category>
<Client>Client Five</Client>
<Title>Get your Free 2</Title>
</Promotion>
<Promotion>
<Category>Arts & Entertainment</Category>
<Client>Client 5</Client>
<Title>Get your Free 4</Title>
</Promotion>
<Promotion>
<Category>Arts & Entertainment</Category>
<Client>Client five</Client>
<Title>Get your Free 5</Title>
</Promotion>
<Promotion>
<Category>Community & Neighborhood</Category>
<Client>Client 1</Client>
<Title>Get your Free 1</Title>
</Promotion>
<Promotion>
<Category>Education</Category>
<Client>Client 3</Client>
<Title>Get Your Free 3</Title>
</Promotion>
I would like to group by category. I tried the following and keep getting errors:
string xslmarkup = @"
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='html' />
<xsl:key name='Categories' match='Promotions/Promotion' use='Category'/>
<xsl:template match='/'>
<xsl:apply-templates select='
/Promotions/Promotion[
generate-id()
=
generate-id(key ('Categories',Category)[1])
]
'/>
</xsl:template>
<xsl:template match='Promotion'>
<xsl:value-of select='Title'/>
</xsl:template>
</xsl:stylesheet>
"
I would like something like this as the output:
<h1>Arts & Entertainment</h1>
<ul>Client Five</ul>
<ul>Get your Free 2</ul>
<ul>Client 5</ul>
<ul>Get your Free 4</ul>
<ul>Client five</ul>
<ul>Get your Free 5</ul>
<h1>Community & Neighborhood</h1>
<ul>Client 1</ul>
<ul>Get your Free 1</ul>
<h1>Education</h1>
<ul>Client 3</ul>
<ul>Get Your Free 3</ul>