Difference: XmlQueryPluginRecipe7 (1 vs. 4)

Revision 42006-02-28 - Main.PatrickDiamond

Line: 1 to 1
 
META TOPICPARENT name="XmlQueryPlugin"

Recipe showing how to place all table fields in one set. This simplifies some types of query.

Revision 32005-04-04 - Main.PatrickDiamond

Line: 1 to 1
 
META TOPICPARENT name="XmlQueryPlugin"

Recipe showing how to place all table fields in one set. This simplifies some types of query.

Line: 46 to 46
  <xsl:call-template name="find_fields_by_column"/>
Added:
>
>
<-- This template processes each field and tranforms it into a node /fields/field -->
 
Changed:
<
<
<-- process each row after the first header row -->
>
>
<-- process each table -->
  <xsl:for-each select="/twiki/web/topic/data/tables/table">
Added:
>
>
<-- extract the table name and topic name -->

<-- process each row after the first header row -->
  <xsl:for-each select="row[position()>1]">
Deleted:
<
<
  <xsl:for-each select="field">
Line: 127 to 131
  <xsl:call-template name="find_fields_by_column"/>
Added:
>
>
<-- This template processes each field and tranforms it into a node /fields/field -->
 
Added:
>
>
<-- process each table -->
  <xsl:for-each select="/twiki/web/topic/data/tables/table">
Added:
>
>

<-- process each row after the first header row -->
  <xsl:for-each select="row[position()>1]">
Deleted:
<
<
  <xsl:for-each select="field">

Revision 22005-04-04 - Main.PatrickDiamond

Line: 1 to 1
 
META TOPICPARENT name="XmlQueryPlugin"

Recipe showing how to place all table fields in one set. This simplifies some types of query.

Line: 7 to 7
  ---++Sample Tables
Added:
>
>
 
Author Title
Rider, Henry Allan and the Holy Flower
Rider, Henry Allan Quatermain
Line: 20 to 21
 
Casanova, Giacomo Memoirs of Casanova Volume 03: Military Career
Casanova, Giacomo Memoirs of Casanova Volume 04: Return to Venice
Added:
>
>
 
Author Title
Poe, Edgar Allan Alone
Poe, Edgar Allan Derniers Contes
Line: 30 to 32
 
%XSLTSTART{id="%WEB%" benchmark="off" debug="off" }% 
Added:
>
>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:set="http://exslt.org/sets" xmlns:exslt="http://exslt.org/common" extension-element-prefixes="set">
 
Added:
>
>
<-- place each field in a set with attributes for table, title, row & column info -->
<-- The field title is taken as the value in the first row of this column -->

<-- http://www-106.ibm.com/developerworks/xml/library/x-tipxsltmp.html -->
<xsl:call-template name="find_fields_by_column"/>

<-- process each row after the first header row -->
<xsl:for-each select="/twiki/web/topic/data/tables/table"> <xsl:for-each select="row[position()>1]"> <xsl:for-each select="field">
<-- extract the title from the field in the same column 1st row -->
<xsl:value-of select="../../row[1]/field[position() = $col]"/>
<xsl:value-of select="$col"/> <xsl:value-of select="$row"/> <xsl:value-of select="$table"/> <xsl:value-of select="$topic"/> <xsl:value-of select="text()"/>
</xsl:for-each> </xsl:for-each> </xsl:for-each>

<-- use exslt:node-set to allow the parsing of the variable as a set of nodes -->
<xsl:for-each select="exslt:node-set($fields_by_column)//field"> </xsl:for-each>
NameValueTableTitleTopicColumnRow
<xsl:value-of select="name(.)"/> <xsl:value-of select="."/> <xsl:value-of select="@table"/> <xsl:value-of select="@title"/> <xsl:value-of select="@topic"/> <xsl:value-of select="@column"/> <xsl:value-of select="@row"/>

%XSLTEND%

 

XSLT Demo Transformed Table

XmlQuery must be Installed for this demo to work. If %XSLTSTART{}% tag appears XmlQueryPugin is not installed
Deleted:
<
<
The above tables has been transformed in 3 ways
  1. They have been combined
  2. The Author and Title columns have been swapped
  3. The entries have been sorted by Title
  %XSLTSTART{id="TWiki" benchmark="off" debug="off" }% <xsl:stylesheet version="1.0"
Line: 59 to 130
 
Changed:
<
<
<xsl:for-each select="/twiki/web/topic/data/tables/table/row[position()>1]">
>
>
<xsl:for-each select="/twiki/web/topic/data/tables/table"> <xsl:for-each select="row[position()>1]">
 
Line: 86 to 158
  </xsl:for-each> </xsl:for-each>
Added:
>
>
</xsl:for-each>
 
Line: 94 to 167
 
Changed:
<
<
NameValueTableTitleTopicColumn
>
>
NameValueTableTitleTopicColumnRow
 
<-- use exslt:node-set to allow the parsing of the variable as a set of nodes -->
<xsl:for-each select="exslt:node-set($fields_by_column)//field">
Line: 105 to 178
 
<xsl:value-of select="@title"/> <xsl:value-of select="@topic"/> <xsl:value-of select="@column"/>
Added:
>
>
<xsl:value-of select="@row"/>
  </xsl:for-each>

Revision 12005-04-04 - Main.PatrickDiamond

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="XmlQueryPlugin"

Recipe showing how to place all table fields in one set. This simplifies some types of query.

On this page:

---++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" }% 
 

---++ XSLT Demo Transformed Table
*XmlQuery must be Installed for this demo to work. If %<nop>XSLTSTART{}% tag appears <nop>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__


%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"
  xmlns:exslt="http://exslt.org/common"
  extension-element-prefixes="set">

<!-- place each field in a set with attributes fro table, title, row & column info --> 
<!-- The field title is taken as the value in the first row of this column -->

<xsl:variable name="fields_by_column">
    <!-- http://www-106.ibm.com/developerworks/xml/library/x-tipxsltmp.html -->
    <xsl:call-template name="find_fields_by_column"/>
</xsl:variable>

<xsl:template name="find_fields_by_column">
    <xsl:param name="find_table"/>
    <fields>
    <xsl:for-each select="/twiki/web/topic/data/tables/table/row[position()>1]">
        <xsl:variable name="row" select="position()"/>
        <xsl:variable name="table" select="../@name"/>
        <xsl:variable name="topic" select="../../../@topic"/>
        <xsl:for-each select="field">
            <xsl:variable name="col" select="position()"/>
            <field>
                <xsl:attribute name="title">
                  <!-- extract the title from the field in the same column 1st row -->
                  <xsl:value-of select="../../row[1]/field[position() = $col]"/>
                </xsl:attribute>
                <xsl:attribute name="column">
                    <xsl:value-of select="$col"/>
                </xsl:attribute>
                <xsl:attribute name="row">
                    <xsl:value-of select="$row"/>
                </xsl:attribute>
                <xsl:attribute name="table">
                    <xsl:value-of select="$table"/>
                </xsl:attribute>
                <xsl:attribute name="topic">
                    <xsl:value-of select="$topic"/>
                </xsl:attribute>
                <xsl:value-of select="text()"/>
            </field>
        </xsl:for-each>
    </xsl:for-each>
    </fields>
</xsl:template>



<xsl:template match="/">
<table>

<tr><th>Name</th><th>Value</th><th>Table</th><th></th><th>Title</th><th>Topic</th><th>Column</th></tr>

<!-- use exslt:node-set to allow the parsing of the variable as a set of nodes -->
<xsl:for-each select="exslt:node-set($fields_by_column)//field">
     <tr>
          <td> <xsl:value-of select="name(.)"/> </td>
          <td> <xsl:value-of select="."/> </td>
          <td> <xsl:value-of select="@table"/> </td>
          <td> <xsl:value-of select="@title"/> </td>
          <td> <xsl:value-of select="@topic"/> </td>
          <td> <xsl:value-of select="@column"/> </td>
     </tr>
</xsl:for-each>
</table>

</xsl:template>
</xsl:stylesheet>
%XSLTEND%
 
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.XmlQueryPluginRecipe7