TWiki> TWiki Web>XMLQueryPlugin? >XmlQueryPluginRecipe5 (2006-02-28, PatrickDiamond? )EditAttach

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

Sample Table

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

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
Topic revision: r3 - 2006-02-28 - 11:19:39 - PatrickDiamond?
 

This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.XmlQueryPluginRecipe5