[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] grouping, sorting and selection by language(s)


Subject: [xsl] grouping, sorting and selection by language(s)
From: chunga srevenge <chunga_srevenge@xxxxxxxx>
Date: Tue, 25 Jan 2005 15:45:00 -0500 (EST)

I use ASP to transform the following XML (an article
index) and XSL to HTML. The XSL groups the articles by
category, sorts them by date within each category and
only shows two articles per category. That works OK, 
but I want to show on one page only the articles in
English, on another page the ones in French, Dutch and
German, and on a third page only the ones in French
and German. How do I do that ?

<?xml version="1.0" encoding="ISO-8859-1"?>
<articles>
<article lang="fr">
<category>Catigorie 2</category>
<source>Publication in French</source>
<date pubdate="20050124">24/01/2004</date>
<art_title>Title of the first article in
French</art_title>
<firstpara>Text of the first article in
French.</firstpara>
<link>http://www.anyurl.com/articles/20050124-fr.asp</link>
</article>
<article lang="en">
<category>Category 3</category>
<source>English-language publication</source>
<date pubdate="20041221">21/12/2004</date>
<art_title>Title of the first article in
English</art_title>
<firstpara>Text of the first article in
English.</firstpara>
<link>http://www.anyurl.com/articles/20041221-en.asp</link>
</article>
<article lang="de">
<category>Kategorie 1</category>
<source>German-language publication</source>
<date pubdate="20040724">24/07/2004</date>
<art_title>Title of the first article in
German</art_title>
<firstpara>Text of the first article in
German.</firstpara>
<link>http://www.anyurl.com/articles/20040724-de.asp</link>
</article>
<article lang="fr">
<category>Catigorie 2</category>
<source>Publication in French</source>
<date pubdate="20040302">02/03/2004</date>
<art_title>Title of the second article in
French</art_title>
<firstpara>Text of the second article in
French.</firstpara>
<link>http://www.anyurl.com/articles/20040302-fr.asp</link>
</article>
<article lang="nl">
<category>Categorie 1</category>
<source>Dutch-language publication</source>
<date pubdate="20041119">19/11/2004</date>
<art_title>Title of the first article in
Dutch</art_title>
<firstpara>Text of the first article in
Dutch.</firstpara>
<link>http://www.anyurl.com/articles/20041119-nl.asp</link>
</article>
<article lang="de">
<category>Kategorie 3</category>
<source>German-language publication</source>
<date pubdate="20031224">24/12/2003</date>
<art_title>Title of the second article in
German</art_title>
<firstpara>Text of the second article in
German.</firstpara>
<link>http://www.anyurl.com/articles/20031224-de.asp</link>
</article>
<article lang="nl">
<category>Categorie 2</category>
<source>Dutch-language publication</source>
<date pubdate="20040919">19/09/2004</date>
<art_title>Title of the second article in
Dutch</art_title>
<firstpara>Text of the second article in
Dutch.</firstpara>
<link>http://www.anyurl.com/articles/20040919-nl.asp</link>
</article>
<article lang="en">
<category>Category 1</category>
<source>English-language publication</source>
<date pubdate="20040621">21/06/2004</date>
<art_title>Title of the second article in
English</art_title>
<firstpara>Text of the second article in
English.</firstpara>
<link>http://www.anyurl.com/articles/20040621-en.asp</link>
</article>
<article lang="de">
<category>Kategorie 3</category>
<source>German-language publication</source>
<date pubdate="20041029">29/10/2004</date>
<art_title>Title of the third article in
German</art_title>
<firstpara>Text of the third article in
German.</firstpara>
<link>http://www.anyurl.com/articles/20041029-de.asp</link>
</article>
<article lang="fr">
<category>Catigorie 3</category>
<source>Publication in French</source>
<date pubdate="20030320">20/03/2003</date>
<art_title>Title of the third article in
French</art_title>
<firstpara>Text of the third article in
French.</firstpara>
<link>http://www.anyurl.com/articles/20030320-fr.asp</link>
</article>
<article lang="en">
<category>Category 2</category>
<source>English-language publication</source>
<date pubdate="20030512">12/05/2003</date>
<art_title>Title of the third article in
English</art_title>
<firstpara>Text of the third article in
English.</firstpara>
<link>http://www.anyurl.com/articles/20030512-en.asp</link>
</article>
<article lang="nl">
<category>Categorie 3</category>
<source>Dutch-language publication</source>
<date pubdate="20031017">17/10/2003</date>
<art_title>Title of the third article in
Dutch</art_title>
<firstpara>Text of the third article in
Dutch.</firstpara>
<link>http://www.anyurl.com/articles/20031017-nl.asp</link>
</article>
</articles>

The XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method ="html" encoding="ISO-8859-1" />
<xsl:key name ="articles-by-category" match ="article"
use ="category" />
<xsl:template match="articles">
<xsl:for-each select
="article[count(.|key('articles-by-category', 
category)[1])=1]">
<xsl:sort select="category" />
<h2><xsl:value-of select="category" /></h2><br/>
<xsl:for-each select="key('articles-by-category',
category)">
<xsl:sort select="date/@pubdate" order="descending"/>
<xsl:if test="position() &lt;3">
<i><xsl:value-of select="source"/> - <xsl:value-of
select="date" /></i><br/>
<h4><xsl:value-of select="art_title"/></h4>
<xsl:value-of select="firstpara"/> ..
<a><xsl:attribute name="href">
<xsl:value-of select="link"/>
</xsl:attribute>read full article</a><br/><br/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca


Current Thread
Keywords