You are here: Foswiki>System Web>XMLQueryPlugin>XmlQueryPluginRecipe5 (28 Feb 2006, PatrickDiamond)Edit Attach

Recipe showing how to extract the values from a Table Column, sort them and produce a unique list

Sample Table

Title AuthorSorted ascending
The Parenticide Club Bierce, Ambrose
Paris as It Was and as It Is Blagdon, Francis W.
Early Kings of Norway Carlyle, Thomas
The Early Poems of Alfred Lord Tennyson Collins, John Churton
Early Letters of George Wm. Curtis Cooke, George Willis
The Parish Register Crabbe, George
Early Letters of George Wm. Curtis Curtis, George William
The Parish Clerk (1907) Ditchfield, P. H. (Peter Hampson)
The Parent's Assistant Edgeworth, Maria
Early Plays Catiline, the Warrior's Barrow, Olaf Liljekrans Ibsen, Henrik
Parish Papers Macleod, Norman
Early Plays Catiline, the Warrior's Barrow, Olaf Liljekrans Orbeck, Anders
The Early Life of Mark Rutherford (W. Hale White) Rutherford, Mark
Early Israel and the Surrounding Nations Sayce, Archibald Henry
The Early Poems of Alfred Lord Tennyson Tennyson, Alfred Lord
Early Short Fiction of Edith Wharton Audio Book Wharton, Edith

Annotated XSLT

%XSLTSTART{id="%WEB%" benchmark="off" debug="off" }% 
 <xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:set="http://exslt.org/sets"
  extension-element-prefixes="set">

The last two parameters in the xsl:stylesheet tag include set processing functions

 <xsl:template match="/twiki">

 <ol>
 <xsl:for-each select="set:distinct(/twiki/web/topic/data/tables/table/row[position()>1]/field[1])">

Extract the first column from all rows but the first and procduce a distinct list of the items

          <xsl:sort select="."/>

sort this list of items

          <li><xsl:value-of select="."/></li>
 </xsl:for-each>
 </ol>

  </xsl:template>
  </xsl:stylesheet>
%XSLTEND%

XSLT Demo: Ordered List

XmlQuery must be Installed for this demo to work. If %XSLTSTART{}% tag appears XmlQueryPugin is not installed

%XSLTSTART{id="System" benchmark="off" debug="off" }% <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:set="http://exslt.org/sets" extension-element-prefixes="set">

%XSLTEND%
Topic revision: r3 - 28 Feb 2006, PatrickDiamond
This site is powered by FoswikiCopyright &© by the contributing authors. All material on this site is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback