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

Recipe showing how to Transform a table or set of tables

Sample Tables

Author Title
Rider, Henry Allan and the Holy Flower
Rider, Henry Allan Quatermain
Rider, Henry Allan's Wife
Rider, Henry The Ancient Allan
Campan, Jeanne Louise Henriette Images from Campan's Marie Antoinette
Campan, Jeanne Louise Henriette Marie Antoinette Volume 01
Campan, Jeanne Louise Henriette Marie Antoinette Volume 02
Casanova, Giacomo Memoirs of Casanova Volume 01: Childhood
Casanova, Giacomo Memoirs of Casanova Volume 02: a Cleric in Naples
Casanova, Giacomo Memoirs of Casanova Volume 03: Military Career
Casanova, Giacomo Memoirs of Casanova Volume 04: Return to Venice

Author Title
Poe, Edgar Allan Alone
Poe, Edgar Allan Derniers Contes
Poe, Edgar Allan Edgar Allan Poe's Complete Poetical Works
Poe, Edgar Allan The Fall of the House of Usher

Annotated Query

%XSLTSTART{id="%WEB%" benchmark="off" debug="off" }% 
 <xsl:stylesheet version="1.0" 

<xsl:template match="/">
 <table border="1">
 <xsl:apply-templates select="/twiki/web/topic/data/tables/table/row[position()=1]/field[@type='title' and position()=1 and text()='Author']/../../row">
Select each row from all tables that have the first field in the first row equal to 'Title' and of type 'title'. Then apply the template that matchs "row"
          <xsl:sort select="field[2]"/>
Sort each row according to the contents of the second child tag named field

<xsl:template match="row">
Executed from the apply-templates tag against each node in the select= list

         <xsl:if test="./field[1][@type='data']">
If this is a data field then output it

                 <td><xsl:value-of select="./field[2]"/></td>
                  <td><xsl:value-of select="./field[1]"/></td>


XSLT Demo Transformed Table

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

The above tables has been transformed in 3 ways 1 They have been combined 1 The Author and Title columns have been swapped 1 The entries have been sorted by Title

Topic revision: r10 - 2006-02-28 - 11:19:03 - 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 at TWiki:TWiki.XmlQueryPluginRecipe3